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