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