ExprCXX.h revision 00cf3cc2718671aa48e8da264a523b0058a8591e
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 /// The scope specifier, if any. 1594 NestedNameSpecifier *Qualifier; 1595 1596 /// The source range of the scope specifier. 1597 SourceRange QualifierRange; 1598 1599protected: 1600 /// True if the name was a template-id. 1601 bool HasExplicitTemplateArgs; 1602 1603 OverloadExpr(StmtClass K, ASTContext &C, 1604 NestedNameSpecifier *Qualifier, SourceRange QRange, 1605 const DeclarationNameInfo &NameInfo, 1606 const TemplateArgumentListInfo *TemplateArgs, 1607 UnresolvedSetIterator Begin, UnresolvedSetIterator End, 1608 bool KnownDependent = false, 1609 bool KnownContainsUnexpandedParameterPack = false); 1610 1611 OverloadExpr(StmtClass K, EmptyShell Empty) 1612 : Expr(K, Empty), Results(0), NumResults(0), 1613 Qualifier(0), HasExplicitTemplateArgs(false) { } 1614 1615 void initializeResults(ASTContext &C, 1616 UnresolvedSetIterator Begin, 1617 UnresolvedSetIterator End); 1618 1619public: 1620 struct FindResult { 1621 OverloadExpr *Expression; 1622 bool IsAddressOfOperand; 1623 bool HasFormOfMemberPointer; 1624 }; 1625 1626 /// Finds the overloaded expression in the given expression of 1627 /// OverloadTy. 1628 /// 1629 /// \return the expression (which must be there) and true if it has 1630 /// the particular form of a member pointer expression 1631 static FindResult find(Expr *E) { 1632 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 1633 1634 FindResult Result; 1635 1636 E = E->IgnoreParens(); 1637 if (isa<UnaryOperator>(E)) { 1638 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 1639 E = cast<UnaryOperator>(E)->getSubExpr(); 1640 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 1641 1642 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 1643 Result.IsAddressOfOperand = true; 1644 Result.Expression = Ovl; 1645 } else { 1646 Result.HasFormOfMemberPointer = false; 1647 Result.IsAddressOfOperand = false; 1648 Result.Expression = cast<OverloadExpr>(E); 1649 } 1650 1651 return Result; 1652 } 1653 1654 /// Gets the naming class of this lookup, if any. 1655 CXXRecordDecl *getNamingClass() const; 1656 1657 typedef UnresolvedSetImpl::iterator decls_iterator; 1658 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 1659 decls_iterator decls_end() const { 1660 return UnresolvedSetIterator(Results + NumResults); 1661 } 1662 1663 /// Gets the number of declarations in the unresolved set. 1664 unsigned getNumDecls() const { return NumResults; } 1665 1666 /// Gets the full name info. 1667 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 1668 void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; } 1669 1670 /// Gets the name looked up. 1671 DeclarationName getName() const { return NameInfo.getName(); } 1672 void setName(DeclarationName N) { NameInfo.setName(N); } 1673 1674 /// Gets the location of the name. 1675 SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 1676 void setNameLoc(SourceLocation Loc) { NameInfo.setLoc(Loc); } 1677 1678 /// Fetches the nested-name qualifier, if one was given. 1679 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1680 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1681 1682 /// Fetches the range of the nested-name qualifier. 1683 SourceRange getQualifierRange() const { return QualifierRange; } 1684 void setQualifierRange(SourceRange R) { QualifierRange = R; } 1685 1686 /// \brief Determines whether this expression had an explicit 1687 /// template argument list, e.g. f<int>. 1688 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1689 1690 ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below 1691 1692 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1693 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 1694 } 1695 1696 /// \brief Retrieves the optional explicit template arguments. 1697 /// This points to the same data as getExplicitTemplateArgs(), but 1698 /// returns null if there are no explicit template arguments. 1699 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1700 if (!hasExplicitTemplateArgs()) return 0; 1701 return &getExplicitTemplateArgs(); 1702 } 1703 1704 static bool classof(const Stmt *T) { 1705 return T->getStmtClass() == UnresolvedLookupExprClass || 1706 T->getStmtClass() == UnresolvedMemberExprClass; 1707 } 1708 static bool classof(const OverloadExpr *) { return true; } 1709 1710 friend class ASTStmtReader; 1711 friend class ASTStmtWriter; 1712}; 1713 1714/// \brief A reference to a name which we were able to look up during 1715/// parsing but could not resolve to a specific declaration. This 1716/// arises in several ways: 1717/// * we might be waiting for argument-dependent lookup 1718/// * the name might resolve to an overloaded function 1719/// and eventually: 1720/// * the lookup might have included a function template 1721/// These never include UnresolvedUsingValueDecls, which are always 1722/// class members and therefore appear only in 1723/// UnresolvedMemberLookupExprs. 1724class UnresolvedLookupExpr : public OverloadExpr { 1725 /// True if these lookup results should be extended by 1726 /// argument-dependent lookup if this is the operand of a function 1727 /// call. 1728 bool RequiresADL; 1729 1730 /// True if these lookup results are overloaded. This is pretty 1731 /// trivially rederivable if we urgently need to kill this field. 1732 bool Overloaded; 1733 1734 /// The naming class (C++ [class.access.base]p5) of the lookup, if 1735 /// any. This can generally be recalculated from the context chain, 1736 /// but that can be fairly expensive for unqualified lookups. If we 1737 /// want to improve memory use here, this could go in a union 1738 /// against the qualified-lookup bits. 1739 CXXRecordDecl *NamingClass; 1740 1741 UnresolvedLookupExpr(ASTContext &C, 1742 CXXRecordDecl *NamingClass, 1743 NestedNameSpecifier *Qualifier, SourceRange QRange, 1744 const DeclarationNameInfo &NameInfo, 1745 bool RequiresADL, bool Overloaded, 1746 const TemplateArgumentListInfo *TemplateArgs, 1747 UnresolvedSetIterator Begin, UnresolvedSetIterator End) 1748 : OverloadExpr(UnresolvedLookupExprClass, C, Qualifier, QRange, NameInfo, 1749 TemplateArgs, Begin, End), 1750 RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass) 1751 {} 1752 1753 UnresolvedLookupExpr(EmptyShell Empty) 1754 : OverloadExpr(UnresolvedLookupExprClass, Empty), 1755 RequiresADL(false), Overloaded(false), NamingClass(0) 1756 {} 1757 1758public: 1759 static UnresolvedLookupExpr *Create(ASTContext &C, 1760 CXXRecordDecl *NamingClass, 1761 NestedNameSpecifier *Qualifier, 1762 SourceRange QualifierRange, 1763 const DeclarationNameInfo &NameInfo, 1764 bool ADL, bool Overloaded, 1765 UnresolvedSetIterator Begin, 1766 UnresolvedSetIterator End) { 1767 return new(C) UnresolvedLookupExpr(C, NamingClass, Qualifier, 1768 QualifierRange, NameInfo, ADL, 1769 Overloaded, 0, Begin, End); 1770 } 1771 1772 static UnresolvedLookupExpr *Create(ASTContext &C, 1773 CXXRecordDecl *NamingClass, 1774 NestedNameSpecifier *Qualifier, 1775 SourceRange QualifierRange, 1776 const DeclarationNameInfo &NameInfo, 1777 bool ADL, 1778 const TemplateArgumentListInfo &Args, 1779 UnresolvedSetIterator Begin, 1780 UnresolvedSetIterator End); 1781 1782 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 1783 bool HasExplicitTemplateArgs, 1784 unsigned NumTemplateArgs); 1785 1786 /// True if this declaration should be extended by 1787 /// argument-dependent lookup. 1788 bool requiresADL() const { return RequiresADL; } 1789 void setRequiresADL(bool V) { RequiresADL = V; } 1790 1791 /// True if this lookup is overloaded. 1792 bool isOverloaded() const { return Overloaded; } 1793 void setOverloaded(bool V) { Overloaded = V; } 1794 1795 /// Gets the 'naming class' (in the sense of C++0x 1796 /// [class.access.base]p5) of the lookup. This is the scope 1797 /// that was looked in to find these results. 1798 CXXRecordDecl *getNamingClass() const { return NamingClass; } 1799 void setNamingClass(CXXRecordDecl *D) { NamingClass = D; } 1800 1801 // Note that, inconsistently with the explicit-template-argument AST 1802 // nodes, users are *forbidden* from calling these methods on objects 1803 // without explicit template arguments. 1804 1805 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1806 assert(hasExplicitTemplateArgs()); 1807 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1); 1808 } 1809 1810 /// Gets a reference to the explicit template argument list. 1811 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1812 assert(hasExplicitTemplateArgs()); 1813 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1814 } 1815 1816 /// \brief Retrieves the optional explicit template arguments. 1817 /// This points to the same data as getExplicitTemplateArgs(), but 1818 /// returns null if there are no explicit template arguments. 1819 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1820 if (!hasExplicitTemplateArgs()) return 0; 1821 return &getExplicitTemplateArgs(); 1822 } 1823 1824 /// \brief Copies the template arguments (if present) into the given 1825 /// structure. 1826 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1827 getExplicitTemplateArgs().copyInto(List); 1828 } 1829 1830 SourceLocation getLAngleLoc() const { 1831 return getExplicitTemplateArgs().LAngleLoc; 1832 } 1833 1834 SourceLocation getRAngleLoc() const { 1835 return getExplicitTemplateArgs().RAngleLoc; 1836 } 1837 1838 TemplateArgumentLoc const *getTemplateArgs() const { 1839 return getExplicitTemplateArgs().getTemplateArgs(); 1840 } 1841 1842 unsigned getNumTemplateArgs() const { 1843 return getExplicitTemplateArgs().NumTemplateArgs; 1844 } 1845 1846 SourceRange getSourceRange() const { 1847 SourceRange Range(getNameInfo().getSourceRange()); 1848 if (getQualifier()) Range.setBegin(getQualifierRange().getBegin()); 1849 if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc()); 1850 return Range; 1851 } 1852 1853 child_range children() { return child_range(); } 1854 1855 static bool classof(const Stmt *T) { 1856 return T->getStmtClass() == UnresolvedLookupExprClass; 1857 } 1858 static bool classof(const UnresolvedLookupExpr *) { return true; } 1859}; 1860 1861/// \brief A qualified reference to a name whose declaration cannot 1862/// yet be resolved. 1863/// 1864/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 1865/// it expresses a reference to a declaration such as 1866/// X<T>::value. The difference, however, is that an 1867/// DependentScopeDeclRefExpr node is used only within C++ templates when 1868/// the qualification (e.g., X<T>::) refers to a dependent type. In 1869/// this case, X<T>::value cannot resolve to a declaration because the 1870/// declaration will differ from on instantiation of X<T> to the 1871/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 1872/// qualifier (X<T>::) and the name of the entity being referenced 1873/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 1874/// declaration can be found. 1875class DependentScopeDeclRefExpr : public Expr { 1876 /// \brief The nested-name-specifier that qualifies this unresolved 1877 /// declaration name. 1878 NestedNameSpecifierLoc QualifierLoc; 1879 1880 /// The name of the entity we will be referencing. 1881 DeclarationNameInfo NameInfo; 1882 1883 /// \brief Whether the name includes explicit template arguments. 1884 bool HasExplicitTemplateArgs; 1885 1886 DependentScopeDeclRefExpr(QualType T, 1887 NestedNameSpecifierLoc QualifierLoc, 1888 const DeclarationNameInfo &NameInfo, 1889 const TemplateArgumentListInfo *Args); 1890 1891 friend class ASTStmtReader; 1892 1893public: 1894 static DependentScopeDeclRefExpr *Create(ASTContext &C, 1895 NestedNameSpecifierLoc QualifierLoc, 1896 const DeclarationNameInfo &NameInfo, 1897 const TemplateArgumentListInfo *TemplateArgs = 0); 1898 1899 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 1900 bool HasExplicitTemplateArgs, 1901 unsigned NumTemplateArgs); 1902 1903 /// \brief Retrieve the name that this expression refers to. 1904 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 1905 1906 /// \brief Retrieve the name that this expression refers to. 1907 DeclarationName getDeclName() const { return NameInfo.getName(); } 1908 1909 /// \brief Retrieve the location of the name within the expression. 1910 SourceLocation getLocation() const { return NameInfo.getLoc(); } 1911 1912 /// \brief Retrieve the nested-name-specifier that qualifies the 1913 /// name, with source location information. 1914 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 1915 1916 1917 /// \brief Retrieve the nested-name-specifier that qualifies this 1918 /// declaration. 1919 NestedNameSpecifier *getQualifier() const { 1920 return QualifierLoc.getNestedNameSpecifier(); 1921 } 1922 1923 /// Determines whether this lookup had explicit template arguments. 1924 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1925 1926 // Note that, inconsistently with the explicit-template-argument AST 1927 // nodes, users are *forbidden* from calling these methods on objects 1928 // without explicit template arguments. 1929 1930 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1931 assert(hasExplicitTemplateArgs()); 1932 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1); 1933 } 1934 1935 /// Gets a reference to the explicit template argument list. 1936 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1937 assert(hasExplicitTemplateArgs()); 1938 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1939 } 1940 1941 /// \brief Retrieves the optional explicit template arguments. 1942 /// This points to the same data as getExplicitTemplateArgs(), but 1943 /// returns null if there are no explicit template arguments. 1944 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1945 if (!hasExplicitTemplateArgs()) return 0; 1946 return &getExplicitTemplateArgs(); 1947 } 1948 1949 /// \brief Copies the template arguments (if present) into the given 1950 /// structure. 1951 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1952 getExplicitTemplateArgs().copyInto(List); 1953 } 1954 1955 SourceLocation getLAngleLoc() const { 1956 return getExplicitTemplateArgs().LAngleLoc; 1957 } 1958 1959 SourceLocation getRAngleLoc() const { 1960 return getExplicitTemplateArgs().RAngleLoc; 1961 } 1962 1963 TemplateArgumentLoc const *getTemplateArgs() const { 1964 return getExplicitTemplateArgs().getTemplateArgs(); 1965 } 1966 1967 unsigned getNumTemplateArgs() const { 1968 return getExplicitTemplateArgs().NumTemplateArgs; 1969 } 1970 1971 SourceRange getSourceRange() const { 1972 SourceRange Range(QualifierLoc.getBeginLoc(), getLocation()); 1973 if (hasExplicitTemplateArgs()) 1974 Range.setEnd(getRAngleLoc()); 1975 return Range; 1976 } 1977 1978 static bool classof(const Stmt *T) { 1979 return T->getStmtClass() == DependentScopeDeclRefExprClass; 1980 } 1981 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 1982 1983 child_range children() { return child_range(); } 1984 1985 friend class ASTStmtReader; 1986 friend class ASTStmtWriter; 1987}; 1988 1989/// Represents an expression --- generally a full-expression --- which 1990/// introduces cleanups to be run at the end of the sub-expression's 1991/// evaluation. The most common source of expression-introduced 1992/// cleanups is temporary objects in C++, but several other C++ 1993/// expressions can create cleanups. 1994class ExprWithCleanups : public Expr { 1995 Stmt *SubExpr; 1996 1997 CXXTemporary **Temps; 1998 unsigned NumTemps; 1999 2000 ExprWithCleanups(ASTContext &C, Expr *SubExpr, 2001 CXXTemporary **Temps, unsigned NumTemps); 2002 2003public: 2004 ExprWithCleanups(EmptyShell Empty) 2005 : Expr(ExprWithCleanupsClass, Empty), 2006 SubExpr(0), Temps(0), NumTemps(0) {} 2007 2008 static ExprWithCleanups *Create(ASTContext &C, Expr *SubExpr, 2009 CXXTemporary **Temps, 2010 unsigned NumTemps); 2011 2012 unsigned getNumTemporaries() const { return NumTemps; } 2013 void setNumTemporaries(ASTContext &C, unsigned N); 2014 2015 CXXTemporary *getTemporary(unsigned i) { 2016 assert(i < NumTemps && "Index out of range"); 2017 return Temps[i]; 2018 } 2019 const CXXTemporary *getTemporary(unsigned i) const { 2020 return const_cast<ExprWithCleanups*>(this)->getTemporary(i); 2021 } 2022 void setTemporary(unsigned i, CXXTemporary *T) { 2023 assert(i < NumTemps && "Index out of range"); 2024 Temps[i] = T; 2025 } 2026 2027 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2028 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 2029 void setSubExpr(Expr *E) { SubExpr = E; } 2030 2031 SourceRange getSourceRange() const { 2032 return SubExpr->getSourceRange(); 2033 } 2034 2035 // Implement isa/cast/dyncast/etc. 2036 static bool classof(const Stmt *T) { 2037 return T->getStmtClass() == ExprWithCleanupsClass; 2038 } 2039 static bool classof(const ExprWithCleanups *) { return true; } 2040 2041 // Iterators 2042 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 2043}; 2044 2045/// \brief Describes an explicit type conversion that uses functional 2046/// notion but could not be resolved because one or more arguments are 2047/// type-dependent. 2048/// 2049/// The explicit type conversions expressed by 2050/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 2051/// where \c T is some type and \c a1, a2, ..., aN are values, and 2052/// either \C T is a dependent type or one or more of the \c a's is 2053/// type-dependent. For example, this would occur in a template such 2054/// as: 2055/// 2056/// \code 2057/// template<typename T, typename A1> 2058/// inline T make_a(const A1& a1) { 2059/// return T(a1); 2060/// } 2061/// \endcode 2062/// 2063/// When the returned expression is instantiated, it may resolve to a 2064/// constructor call, conversion function call, or some kind of type 2065/// conversion. 2066class CXXUnresolvedConstructExpr : public Expr { 2067 /// \brief The type being constructed. 2068 TypeSourceInfo *Type; 2069 2070 /// \brief The location of the left parentheses ('('). 2071 SourceLocation LParenLoc; 2072 2073 /// \brief The location of the right parentheses (')'). 2074 SourceLocation RParenLoc; 2075 2076 /// \brief The number of arguments used to construct the type. 2077 unsigned NumArgs; 2078 2079 CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 2080 SourceLocation LParenLoc, 2081 Expr **Args, 2082 unsigned NumArgs, 2083 SourceLocation RParenLoc); 2084 2085 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 2086 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 2087 2088 friend class ASTStmtReader; 2089 2090public: 2091 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 2092 TypeSourceInfo *Type, 2093 SourceLocation LParenLoc, 2094 Expr **Args, 2095 unsigned NumArgs, 2096 SourceLocation RParenLoc); 2097 2098 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 2099 unsigned NumArgs); 2100 2101 /// \brief Retrieve the type that is being constructed, as specified 2102 /// in the source code. 2103 QualType getTypeAsWritten() const { return Type->getType(); } 2104 2105 /// \brief Retrieve the type source information for the type being 2106 /// constructed. 2107 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 2108 2109 /// \brief Retrieve the location of the left parentheses ('(') that 2110 /// precedes the argument list. 2111 SourceLocation getLParenLoc() const { return LParenLoc; } 2112 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2113 2114 /// \brief Retrieve the location of the right parentheses (')') that 2115 /// follows the argument list. 2116 SourceLocation getRParenLoc() const { return RParenLoc; } 2117 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2118 2119 /// \brief Retrieve the number of arguments. 2120 unsigned arg_size() const { return NumArgs; } 2121 2122 typedef Expr** arg_iterator; 2123 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2124 arg_iterator arg_end() { return arg_begin() + NumArgs; } 2125 2126 typedef const Expr* const * const_arg_iterator; 2127 const_arg_iterator arg_begin() const { 2128 return reinterpret_cast<const Expr* const *>(this + 1); 2129 } 2130 const_arg_iterator arg_end() const { 2131 return arg_begin() + NumArgs; 2132 } 2133 2134 Expr *getArg(unsigned I) { 2135 assert(I < NumArgs && "Argument index out-of-range"); 2136 return *(arg_begin() + I); 2137 } 2138 2139 const Expr *getArg(unsigned I) const { 2140 assert(I < NumArgs && "Argument index out-of-range"); 2141 return *(arg_begin() + I); 2142 } 2143 2144 void setArg(unsigned I, Expr *E) { 2145 assert(I < NumArgs && "Argument index out-of-range"); 2146 *(arg_begin() + I) = E; 2147 } 2148 2149 SourceRange getSourceRange() const; 2150 2151 static bool classof(const Stmt *T) { 2152 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2153 } 2154 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 2155 2156 // Iterators 2157 child_range children() { 2158 Stmt **begin = reinterpret_cast<Stmt**>(this+1); 2159 return child_range(begin, begin + NumArgs); 2160 } 2161}; 2162 2163/// \brief Represents a C++ member access expression where the actual 2164/// member referenced could not be resolved because the base 2165/// expression or the member name was dependent. 2166/// 2167/// Like UnresolvedMemberExprs, these can be either implicit or 2168/// explicit accesses. It is only possible to get one of these with 2169/// an implicit access if a qualifier is provided. 2170class CXXDependentScopeMemberExpr : public Expr { 2171 /// \brief The expression for the base pointer or class reference, 2172 /// e.g., the \c x in x.f. Can be null in implicit accesses. 2173 Stmt *Base; 2174 2175 /// \brief The type of the base expression. Never null, even for 2176 /// implicit accesses. 2177 QualType BaseType; 2178 2179 /// \brief Whether this member expression used the '->' operator or 2180 /// the '.' operator. 2181 bool IsArrow : 1; 2182 2183 /// \brief Whether this member expression has explicitly-specified template 2184 /// arguments. 2185 bool HasExplicitTemplateArgs : 1; 2186 2187 /// \brief The location of the '->' or '.' operator. 2188 SourceLocation OperatorLoc; 2189 2190 /// \brief The nested-name-specifier that precedes the member name, if any. 2191 NestedNameSpecifier *Qualifier; 2192 2193 /// \brief The source range covering the nested name specifier. 2194 SourceRange QualifierRange; 2195 2196 /// \brief In a qualified member access expression such as t->Base::f, this 2197 /// member stores the resolves of name lookup in the context of the member 2198 /// access expression, to be used at instantiation time. 2199 /// 2200 /// FIXME: This member, along with the Qualifier and QualifierRange, could 2201 /// be stuck into a structure that is optionally allocated at the end of 2202 /// the CXXDependentScopeMemberExpr, to save space in the common case. 2203 NamedDecl *FirstQualifierFoundInScope; 2204 2205 /// \brief The member to which this member expression refers, which 2206 /// can be name, overloaded operator, or destructor. 2207 /// FIXME: could also be a template-id 2208 DeclarationNameInfo MemberNameInfo; 2209 2210 CXXDependentScopeMemberExpr(ASTContext &C, 2211 Expr *Base, QualType BaseType, bool IsArrow, 2212 SourceLocation OperatorLoc, 2213 NestedNameSpecifier *Qualifier, 2214 SourceRange QualifierRange, 2215 NamedDecl *FirstQualifierFoundInScope, 2216 DeclarationNameInfo MemberNameInfo, 2217 const TemplateArgumentListInfo *TemplateArgs); 2218 2219public: 2220 CXXDependentScopeMemberExpr(ASTContext &C, 2221 Expr *Base, QualType BaseType, 2222 bool IsArrow, 2223 SourceLocation OperatorLoc, 2224 NestedNameSpecifier *Qualifier, 2225 SourceRange QualifierRange, 2226 NamedDecl *FirstQualifierFoundInScope, 2227 DeclarationNameInfo MemberNameInfo); 2228 2229 static CXXDependentScopeMemberExpr * 2230 Create(ASTContext &C, 2231 Expr *Base, QualType BaseType, bool IsArrow, 2232 SourceLocation OperatorLoc, 2233 NestedNameSpecifier *Qualifier, 2234 SourceRange QualifierRange, 2235 NamedDecl *FirstQualifierFoundInScope, 2236 DeclarationNameInfo MemberNameInfo, 2237 const TemplateArgumentListInfo *TemplateArgs); 2238 2239 static CXXDependentScopeMemberExpr * 2240 CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs, 2241 unsigned NumTemplateArgs); 2242 2243 /// \brief True if this is an implicit access, i.e. one in which the 2244 /// member being accessed was not written in the source. The source 2245 /// location of the operator is invalid in this case. 2246 bool isImplicitAccess() const { return Base == 0; } 2247 2248 /// \brief Retrieve the base object of this member expressions, 2249 /// e.g., the \c x in \c x.m. 2250 Expr *getBase() const { 2251 assert(!isImplicitAccess()); 2252 return cast<Expr>(Base); 2253 } 2254 void setBase(Expr *E) { Base = E; } 2255 2256 QualType getBaseType() const { return BaseType; } 2257 void setBaseType(QualType T) { BaseType = T; } 2258 2259 /// \brief Determine whether this member expression used the '->' 2260 /// operator; otherwise, it used the '.' operator. 2261 bool isArrow() const { return IsArrow; } 2262 void setArrow(bool A) { IsArrow = A; } 2263 2264 /// \brief Retrieve the location of the '->' or '.' operator. 2265 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2266 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 2267 2268 /// \brief Retrieve the nested-name-specifier that qualifies the member 2269 /// name. 2270 NestedNameSpecifier *getQualifier() const { return Qualifier; } 2271 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 2272 2273 /// \brief Retrieve the source range covering the nested-name-specifier 2274 /// that qualifies the member name. 2275 SourceRange getQualifierRange() const { return QualifierRange; } 2276 void setQualifierRange(SourceRange R) { QualifierRange = R; } 2277 2278 /// \brief Retrieve the first part of the nested-name-specifier that was 2279 /// found in the scope of the member access expression when the member access 2280 /// was initially parsed. 2281 /// 2282 /// This function only returns a useful result when member access expression 2283 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 2284 /// returned by this function describes what was found by unqualified name 2285 /// lookup for the identifier "Base" within the scope of the member access 2286 /// expression itself. At template instantiation time, this information is 2287 /// combined with the results of name lookup into the type of the object 2288 /// expression itself (the class type of x). 2289 NamedDecl *getFirstQualifierFoundInScope() const { 2290 return FirstQualifierFoundInScope; 2291 } 2292 void setFirstQualifierFoundInScope(NamedDecl *D) { 2293 FirstQualifierFoundInScope = D; 2294 } 2295 2296 /// \brief Retrieve the name of the member that this expression 2297 /// refers to. 2298 const DeclarationNameInfo &getMemberNameInfo() const { 2299 return MemberNameInfo; 2300 } 2301 void setMemberNameInfo(const DeclarationNameInfo &N) { MemberNameInfo = N; } 2302 2303 /// \brief Retrieve the name of the member that this expression 2304 /// refers to. 2305 DeclarationName getMember() const { return MemberNameInfo.getName(); } 2306 void setMember(DeclarationName N) { MemberNameInfo.setName(N); } 2307 2308 // \brief Retrieve the location of the name of the member that this 2309 // expression refers to. 2310 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 2311 void setMemberLoc(SourceLocation L) { MemberNameInfo.setLoc(L); } 2312 2313 /// \brief Determines whether this member expression actually had a C++ 2314 /// template argument list explicitly specified, e.g., x.f<int>. 2315 bool hasExplicitTemplateArgs() const { 2316 return HasExplicitTemplateArgs; 2317 } 2318 2319 /// \brief Retrieve the explicit template argument list that followed the 2320 /// member template name, if any. 2321 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2322 assert(HasExplicitTemplateArgs); 2323 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2324 } 2325 2326 /// \brief Retrieve the explicit template argument list that followed the 2327 /// member template name, if any. 2328 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2329 return const_cast<CXXDependentScopeMemberExpr *>(this) 2330 ->getExplicitTemplateArgs(); 2331 } 2332 2333 /// \brief Retrieves the optional explicit template arguments. 2334 /// This points to the same data as getExplicitTemplateArgs(), but 2335 /// returns null if there are no explicit template arguments. 2336 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 2337 if (!hasExplicitTemplateArgs()) return 0; 2338 return &getExplicitTemplateArgs(); 2339 } 2340 2341 /// \brief Copies the template arguments (if present) into the given 2342 /// structure. 2343 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2344 getExplicitTemplateArgs().copyInto(List); 2345 } 2346 2347 /// \brief Initializes the template arguments using the given structure. 2348 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 2349 getExplicitTemplateArgs().initializeFrom(List); 2350 } 2351 2352 /// \brief Retrieve the location of the left angle bracket following the 2353 /// member name ('<'), if any. 2354 SourceLocation getLAngleLoc() const { 2355 return getExplicitTemplateArgs().LAngleLoc; 2356 } 2357 2358 /// \brief Retrieve the template arguments provided as part of this 2359 /// template-id. 2360 const TemplateArgumentLoc *getTemplateArgs() const { 2361 return getExplicitTemplateArgs().getTemplateArgs(); 2362 } 2363 2364 /// \brief Retrieve the number of template arguments provided as part of this 2365 /// template-id. 2366 unsigned getNumTemplateArgs() const { 2367 return getExplicitTemplateArgs().NumTemplateArgs; 2368 } 2369 2370 /// \brief Retrieve the location of the right angle bracket following the 2371 /// template arguments ('>'). 2372 SourceLocation getRAngleLoc() const { 2373 return getExplicitTemplateArgs().RAngleLoc; 2374 } 2375 2376 SourceRange getSourceRange() const { 2377 SourceRange Range; 2378 if (!isImplicitAccess()) 2379 Range.setBegin(Base->getSourceRange().getBegin()); 2380 else if (getQualifier()) 2381 Range.setBegin(getQualifierRange().getBegin()); 2382 else 2383 Range.setBegin(MemberNameInfo.getBeginLoc()); 2384 2385 if (hasExplicitTemplateArgs()) 2386 Range.setEnd(getRAngleLoc()); 2387 else 2388 Range.setEnd(MemberNameInfo.getEndLoc()); 2389 return Range; 2390 } 2391 2392 static bool classof(const Stmt *T) { 2393 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 2394 } 2395 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 2396 2397 // Iterators 2398 child_range children() { 2399 if (isImplicitAccess()) return child_range(); 2400 return child_range(&Base, &Base + 1); 2401 } 2402 2403 friend class ASTStmtReader; 2404 friend class ASTStmtWriter; 2405}; 2406 2407/// \brief Represents a C++ member access expression for which lookup 2408/// produced a set of overloaded functions. 2409/// 2410/// The member access may be explicit or implicit: 2411/// struct A { 2412/// int a, b; 2413/// int explicitAccess() { return this->a + this->A::b; } 2414/// int implicitAccess() { return a + A::b; } 2415/// }; 2416/// 2417/// In the final AST, an explicit access always becomes a MemberExpr. 2418/// An implicit access may become either a MemberExpr or a 2419/// DeclRefExpr, depending on whether the member is static. 2420class UnresolvedMemberExpr : public OverloadExpr { 2421 /// \brief Whether this member expression used the '->' operator or 2422 /// the '.' operator. 2423 bool IsArrow : 1; 2424 2425 /// \brief Whether the lookup results contain an unresolved using 2426 /// declaration. 2427 bool HasUnresolvedUsing : 1; 2428 2429 /// \brief The expression for the base pointer or class reference, 2430 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 2431 /// member expression 2432 Stmt *Base; 2433 2434 /// \brief The type of the base expression; never null. 2435 QualType BaseType; 2436 2437 /// \brief The location of the '->' or '.' operator. 2438 SourceLocation OperatorLoc; 2439 2440 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 2441 Expr *Base, QualType BaseType, bool IsArrow, 2442 SourceLocation OperatorLoc, 2443 NestedNameSpecifier *Qualifier, 2444 SourceRange QualifierRange, 2445 const DeclarationNameInfo &MemberNameInfo, 2446 const TemplateArgumentListInfo *TemplateArgs, 2447 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2448 2449 UnresolvedMemberExpr(EmptyShell Empty) 2450 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 2451 HasUnresolvedUsing(false), Base(0) { } 2452 2453public: 2454 static UnresolvedMemberExpr * 2455 Create(ASTContext &C, bool HasUnresolvedUsing, 2456 Expr *Base, QualType BaseType, bool IsArrow, 2457 SourceLocation OperatorLoc, 2458 NestedNameSpecifier *Qualifier, 2459 SourceRange QualifierRange, 2460 const DeclarationNameInfo &MemberNameInfo, 2461 const TemplateArgumentListInfo *TemplateArgs, 2462 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2463 2464 static UnresolvedMemberExpr * 2465 CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs, 2466 unsigned NumTemplateArgs); 2467 2468 /// \brief True if this is an implicit access, i.e. one in which the 2469 /// member being accessed was not written in the source. The source 2470 /// location of the operator is invalid in this case. 2471 bool isImplicitAccess() const { return Base == 0; } 2472 2473 /// \brief Retrieve the base object of this member expressions, 2474 /// e.g., the \c x in \c x.m. 2475 Expr *getBase() { 2476 assert(!isImplicitAccess()); 2477 return cast<Expr>(Base); 2478 } 2479 const Expr *getBase() const { 2480 assert(!isImplicitAccess()); 2481 return cast<Expr>(Base); 2482 } 2483 void setBase(Expr *E) { Base = E; } 2484 2485 QualType getBaseType() const { return BaseType; } 2486 void setBaseType(QualType T) { BaseType = T; } 2487 2488 /// \brief Determine whether the lookup results contain an unresolved using 2489 /// declaration. 2490 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 2491 void setHasUnresolvedUsing(bool V) { HasUnresolvedUsing = V; } 2492 2493 /// \brief Determine whether this member expression used the '->' 2494 /// operator; otherwise, it used the '.' operator. 2495 bool isArrow() const { return IsArrow; } 2496 void setArrow(bool A) { IsArrow = A; } 2497 2498 /// \brief Retrieve the location of the '->' or '.' operator. 2499 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2500 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 2501 2502 /// \brief Retrieves the naming class of this lookup. 2503 CXXRecordDecl *getNamingClass() const; 2504 2505 /// \brief Retrieve the full name info for the member that this expression 2506 /// refers to. 2507 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 2508 void setMemberNameInfo(const DeclarationNameInfo &N) { setNameInfo(N); } 2509 2510 /// \brief Retrieve the name of the member that this expression 2511 /// refers to. 2512 DeclarationName getMemberName() const { return getName(); } 2513 void setMemberName(DeclarationName N) { setName(N); } 2514 2515 // \brief Retrieve the location of the name of the member that this 2516 // expression refers to. 2517 SourceLocation getMemberLoc() const { return getNameLoc(); } 2518 void setMemberLoc(SourceLocation L) { setNameLoc(L); } 2519 2520 /// \brief Retrieve the explicit template argument list that followed the 2521 /// member template name. 2522 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2523 assert(hasExplicitTemplateArgs()); 2524 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2525 } 2526 2527 /// \brief Retrieve the explicit template argument list that followed the 2528 /// member template name, if any. 2529 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2530 assert(hasExplicitTemplateArgs()); 2531 return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1); 2532 } 2533 2534 /// \brief Retrieves the optional explicit template arguments. 2535 /// This points to the same data as getExplicitTemplateArgs(), but 2536 /// returns null if there are no explicit template arguments. 2537 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 2538 if (!hasExplicitTemplateArgs()) return 0; 2539 return &getExplicitTemplateArgs(); 2540 } 2541 2542 /// \brief Copies the template arguments into the given structure. 2543 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2544 getExplicitTemplateArgs().copyInto(List); 2545 } 2546 2547 /// \brief Retrieve the location of the left angle bracket following 2548 /// the member name ('<'). 2549 SourceLocation getLAngleLoc() const { 2550 return getExplicitTemplateArgs().LAngleLoc; 2551 } 2552 2553 /// \brief Retrieve the template arguments provided as part of this 2554 /// template-id. 2555 const TemplateArgumentLoc *getTemplateArgs() const { 2556 return getExplicitTemplateArgs().getTemplateArgs(); 2557 } 2558 2559 /// \brief Retrieve the number of template arguments provided as 2560 /// part of this template-id. 2561 unsigned getNumTemplateArgs() const { 2562 return getExplicitTemplateArgs().NumTemplateArgs; 2563 } 2564 2565 /// \brief Retrieve the location of the right angle bracket 2566 /// following the template arguments ('>'). 2567 SourceLocation getRAngleLoc() const { 2568 return getExplicitTemplateArgs().RAngleLoc; 2569 } 2570 2571 SourceRange getSourceRange() const { 2572 SourceRange Range = getMemberNameInfo().getSourceRange(); 2573 if (!isImplicitAccess()) 2574 Range.setBegin(Base->getSourceRange().getBegin()); 2575 else if (getQualifier()) 2576 Range.setBegin(getQualifierRange().getBegin()); 2577 2578 if (hasExplicitTemplateArgs()) 2579 Range.setEnd(getRAngleLoc()); 2580 return Range; 2581 } 2582 2583 static bool classof(const Stmt *T) { 2584 return T->getStmtClass() == UnresolvedMemberExprClass; 2585 } 2586 static bool classof(const UnresolvedMemberExpr *) { return true; } 2587 2588 // Iterators 2589 child_range children() { 2590 if (isImplicitAccess()) return child_range(); 2591 return child_range(&Base, &Base + 1); 2592 } 2593}; 2594 2595/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 2596/// 2597/// The noexcept expression tests whether a given expression might throw. Its 2598/// result is a boolean constant. 2599class CXXNoexceptExpr : public Expr { 2600 bool Value : 1; 2601 Stmt *Operand; 2602 SourceRange Range; 2603 2604 friend class ASTStmtReader; 2605 2606public: 2607 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 2608 SourceLocation Keyword, SourceLocation RParen) 2609 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 2610 /*TypeDependent*/false, 2611 /*ValueDependent*/Val == CT_Dependent, 2612 Operand->containsUnexpandedParameterPack()), 2613 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 2614 { } 2615 2616 CXXNoexceptExpr(EmptyShell Empty) 2617 : Expr(CXXNoexceptExprClass, Empty) 2618 { } 2619 2620 Expr *getOperand() const { return static_cast<Expr*>(Operand); } 2621 2622 SourceRange getSourceRange() const { return Range; } 2623 2624 bool getValue() const { return Value; } 2625 2626 static bool classof(const Stmt *T) { 2627 return T->getStmtClass() == CXXNoexceptExprClass; 2628 } 2629 static bool classof(const CXXNoexceptExpr *) { return true; } 2630 2631 // Iterators 2632 child_range children() { return child_range(&Operand, &Operand + 1); } 2633}; 2634 2635/// \brief Represents a C++0x pack expansion that produces a sequence of 2636/// expressions. 2637/// 2638/// A pack expansion expression contains a pattern (which itself is an 2639/// expression) followed by an ellipsis. For example: 2640/// 2641/// \code 2642/// template<typename F, typename ...Types> 2643/// void forward(F f, Types &&...args) { 2644/// f(static_cast<Types&&>(args)...); 2645/// } 2646/// \endcode 2647/// 2648/// Here, the argument to the function object \c f is a pack expansion whose 2649/// pattern is \c static_cast<Types&&>(args). When the \c forward function 2650/// template is instantiated, the pack expansion will instantiate to zero or 2651/// or more function arguments to the function object \c f. 2652class PackExpansionExpr : public Expr { 2653 SourceLocation EllipsisLoc; 2654 2655 /// \brief The number of expansions that will be produced by this pack 2656 /// expansion expression, if known. 2657 /// 2658 /// When zero, the number of expansions is not known. Otherwise, this value 2659 /// is the number of expansions + 1. 2660 unsigned NumExpansions; 2661 2662 Stmt *Pattern; 2663 2664 friend class ASTStmtReader; 2665 friend class ASTStmtWriter; 2666 2667public: 2668 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 2669 llvm::Optional<unsigned> NumExpansions) 2670 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 2671 Pattern->getObjectKind(), /*TypeDependent=*/true, 2672 /*ValueDependent=*/true, /*ContainsUnexpandedParameterPack=*/false), 2673 EllipsisLoc(EllipsisLoc), 2674 NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 2675 Pattern(Pattern) { } 2676 2677 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 2678 2679 /// \brief Retrieve the pattern of the pack expansion. 2680 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 2681 2682 /// \brief Retrieve the pattern of the pack expansion. 2683 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 2684 2685 /// \brief Retrieve the location of the ellipsis that describes this pack 2686 /// expansion. 2687 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 2688 2689 /// \brief Determine the number of expansions that will be produced when 2690 /// this pack expansion is instantiated, if already known. 2691 llvm::Optional<unsigned> getNumExpansions() const { 2692 if (NumExpansions) 2693 return NumExpansions - 1; 2694 2695 return llvm::Optional<unsigned>(); 2696 } 2697 2698 SourceRange getSourceRange() const { 2699 return SourceRange(Pattern->getLocStart(), EllipsisLoc); 2700 } 2701 2702 static bool classof(const Stmt *T) { 2703 return T->getStmtClass() == PackExpansionExprClass; 2704 } 2705 static bool classof(const PackExpansionExpr *) { return true; } 2706 2707 // Iterators 2708 child_range children() { 2709 return child_range(&Pattern, &Pattern + 1); 2710 } 2711}; 2712 2713inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() { 2714 if (isa<UnresolvedLookupExpr>(this)) 2715 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs(); 2716 else 2717 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs(); 2718} 2719 2720/// \brief Represents an expression that computes the length of a parameter 2721/// pack. 2722/// 2723/// \code 2724/// template<typename ...Types> 2725/// struct count { 2726/// static const unsigned value = sizeof...(Types); 2727/// }; 2728/// \endcode 2729class SizeOfPackExpr : public Expr { 2730 /// \brief The location of the 'sizeof' keyword. 2731 SourceLocation OperatorLoc; 2732 2733 /// \brief The location of the name of the parameter pack. 2734 SourceLocation PackLoc; 2735 2736 /// \brief The location of the closing parenthesis. 2737 SourceLocation RParenLoc; 2738 2739 /// \brief The length of the parameter pack, if known. 2740 /// 2741 /// When this expression is value-dependent, the length of the parameter pack 2742 /// is unknown. When this expression is not value-dependent, the length is 2743 /// known. 2744 unsigned Length; 2745 2746 /// \brief The parameter pack itself. 2747 NamedDecl *Pack; 2748 2749 friend class ASTStmtReader; 2750 friend class ASTStmtWriter; 2751 2752public: 2753 /// \brief Creates a value-dependent expression that computes the length of 2754 /// the given parameter pack. 2755 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 2756 SourceLocation PackLoc, SourceLocation RParenLoc) 2757 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 2758 /*TypeDependent=*/false, /*ValueDependent=*/true, 2759 /*ContainsUnexpandedParameterPack=*/false), 2760 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 2761 Length(0), Pack(Pack) { } 2762 2763 /// \brief Creates an expression that computes the length of 2764 /// the given parameter pack, which is already known. 2765 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 2766 SourceLocation PackLoc, SourceLocation RParenLoc, 2767 unsigned Length) 2768 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 2769 /*TypeDependent=*/false, /*ValueDependent=*/false, 2770 /*ContainsUnexpandedParameterPack=*/false), 2771 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 2772 Length(Length), Pack(Pack) { } 2773 2774 /// \brief Create an empty expression. 2775 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 2776 2777 /// \brief Determine the location of the 'sizeof' keyword. 2778 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2779 2780 /// \brief Determine the location of the parameter pack. 2781 SourceLocation getPackLoc() const { return PackLoc; } 2782 2783 /// \brief Determine the location of the right parenthesis. 2784 SourceLocation getRParenLoc() const { return RParenLoc; } 2785 2786 /// \brief Retrieve the parameter pack. 2787 NamedDecl *getPack() const { return Pack; } 2788 2789 /// \brief Retrieve the length of the parameter pack. 2790 /// 2791 /// This routine may only be invoked when the expression is not 2792 /// value-dependent. 2793 unsigned getPackLength() const { 2794 assert(!isValueDependent() && 2795 "Cannot get the length of a value-dependent pack size expression"); 2796 return Length; 2797 } 2798 2799 SourceRange getSourceRange() const { 2800 return SourceRange(OperatorLoc, RParenLoc); 2801 } 2802 2803 static bool classof(const Stmt *T) { 2804 return T->getStmtClass() == SizeOfPackExprClass; 2805 } 2806 static bool classof(const SizeOfPackExpr *) { return true; } 2807 2808 // Iterators 2809 child_range children() { return child_range(); } 2810}; 2811 2812/// \brief Represents a reference to a non-type template parameter pack that 2813/// has been substituted with a non-template argument pack. 2814/// 2815/// When a pack expansion in the source code contains multiple parameter packs 2816/// and those parameter packs correspond to different levels of template 2817/// parameter lists, this node node is used to represent a non-type template 2818/// parameter pack from an outer level, which has already had its argument pack 2819/// substituted but that still lives within a pack expansion that itself 2820/// could not be instantiated. When actually performing a substitution into 2821/// that pack expansion (e.g., when all template parameters have corresponding 2822/// arguments), this type will be replaced with the appropriate underlying 2823/// expression at the current pack substitution index. 2824class SubstNonTypeTemplateParmPackExpr : public Expr { 2825 /// \brief The non-type template parameter pack itself. 2826 NonTypeTemplateParmDecl *Param; 2827 2828 /// \brief A pointer to the set of template arguments that this 2829 /// parameter pack is instantiated with. 2830 const TemplateArgument *Arguments; 2831 2832 /// \brief The number of template arguments in \c Arguments. 2833 unsigned NumArguments; 2834 2835 /// \brief The location of the non-type template parameter pack reference. 2836 SourceLocation NameLoc; 2837 2838 friend class ASTStmtReader; 2839 friend class ASTStmtWriter; 2840 2841public: 2842 SubstNonTypeTemplateParmPackExpr(QualType T, 2843 NonTypeTemplateParmDecl *Param, 2844 SourceLocation NameLoc, 2845 const TemplateArgument &ArgPack); 2846 2847 SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 2848 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 2849 2850 /// \brief Retrieve the non-type template parameter pack being substituted. 2851 NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 2852 2853 /// \brief Retrieve the location of the parameter pack name. 2854 SourceLocation getParameterPackLocation() const { return NameLoc; } 2855 2856 /// \brief Retrieve the template argument pack containing the substituted 2857 /// template arguments. 2858 TemplateArgument getArgumentPack() const; 2859 2860 SourceRange getSourceRange() const { return NameLoc; } 2861 2862 static bool classof(const Stmt *T) { 2863 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 2864 } 2865 static bool classof(const SubstNonTypeTemplateParmPackExpr *) { 2866 return true; 2867 } 2868 2869 // Iterators 2870 child_range children() { return child_range(); } 2871}; 2872 2873} // end namespace clang 2874 2875#endif 2876