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