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