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