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