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