ExprCXX.h revision 76da55d3a49e1805f51b1ced7c5da5bcd7f759d8
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/// CXXTemporary - Represents a C++ temporary. 888class CXXTemporary { 889 /// Destructor - The destructor that needs to be called. 890 const CXXDestructorDecl *Destructor; 891 892 CXXTemporary(const CXXDestructorDecl *destructor) 893 : Destructor(destructor) { } 894 895public: 896 static CXXTemporary *Create(ASTContext &C, 897 const CXXDestructorDecl *Destructor); 898 899 const CXXDestructorDecl *getDestructor() const { return Destructor; } 900 void setDestructor(const CXXDestructorDecl *Dtor) { 901 Destructor = Dtor; 902 } 903}; 904 905/// \brief Represents binding an expression to a temporary. 906/// 907/// This ensures the destructor is called for the temporary. It should only be 908/// needed for non-POD, non-trivially destructable class types. For example: 909/// 910/// \code 911/// struct S { 912/// S() { } // User defined constructor makes S non-POD. 913/// ~S() { } // User defined destructor makes it non-trivial. 914/// }; 915/// void test() { 916/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 917/// } 918/// \endcode 919class CXXBindTemporaryExpr : public Expr { 920 CXXTemporary *Temp; 921 922 Stmt *SubExpr; 923 924 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 925 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 926 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 927 SubExpr->isValueDependent(), 928 SubExpr->isInstantiationDependent(), 929 SubExpr->containsUnexpandedParameterPack()), 930 Temp(temp), SubExpr(SubExpr) { } 931 932public: 933 CXXBindTemporaryExpr(EmptyShell Empty) 934 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 935 936 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 937 Expr* SubExpr); 938 939 CXXTemporary *getTemporary() { return Temp; } 940 const CXXTemporary *getTemporary() const { return Temp; } 941 void setTemporary(CXXTemporary *T) { Temp = T; } 942 943 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 944 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 945 void setSubExpr(Expr *E) { SubExpr = E; } 946 947 SourceLocation getLocStart() const LLVM_READONLY { 948 return SubExpr->getLocStart(); 949 } 950 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 951 952 // Implement isa/cast/dyncast/etc. 953 static bool classof(const Stmt *T) { 954 return T->getStmtClass() == CXXBindTemporaryExprClass; 955 } 956 957 // Iterators 958 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 959}; 960 961/// \brief Represents a call to a C++ constructor. 962class CXXConstructExpr : public Expr { 963public: 964 enum ConstructionKind { 965 CK_Complete, 966 CK_NonVirtualBase, 967 CK_VirtualBase, 968 CK_Delegating 969 }; 970 971private: 972 CXXConstructorDecl *Constructor; 973 974 SourceLocation Loc; 975 SourceRange ParenRange; 976 unsigned NumArgs : 16; 977 bool Elidable : 1; 978 bool HadMultipleCandidates : 1; 979 bool ListInitialization : 1; 980 bool ZeroInitialization : 1; 981 unsigned ConstructKind : 2; 982 Stmt **Args; 983 984protected: 985 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 986 SourceLocation Loc, 987 CXXConstructorDecl *d, bool elidable, 988 ArrayRef<Expr *> Args, 989 bool HadMultipleCandidates, 990 bool ListInitialization, 991 bool ZeroInitialization, 992 ConstructionKind ConstructKind, 993 SourceRange ParenRange); 994 995 /// \brief Construct an empty C++ construction expression. 996 CXXConstructExpr(StmtClass SC, EmptyShell Empty) 997 : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 998 HadMultipleCandidates(false), ListInitialization(false), 999 ZeroInitialization(false), ConstructKind(0), Args(0) 1000 { } 1001 1002public: 1003 /// \brief Construct an empty C++ construction expression. 1004 explicit CXXConstructExpr(EmptyShell Empty) 1005 : Expr(CXXConstructExprClass, Empty), Constructor(0), 1006 NumArgs(0), Elidable(false), HadMultipleCandidates(false), 1007 ListInitialization(false), ZeroInitialization(false), 1008 ConstructKind(0), Args(0) 1009 { } 1010 1011 static CXXConstructExpr *Create(ASTContext &C, QualType T, 1012 SourceLocation Loc, 1013 CXXConstructorDecl *D, bool Elidable, 1014 ArrayRef<Expr *> Args, 1015 bool HadMultipleCandidates, 1016 bool ListInitialization, 1017 bool ZeroInitialization, 1018 ConstructionKind ConstructKind, 1019 SourceRange ParenRange); 1020 1021 CXXConstructorDecl* getConstructor() const { return Constructor; } 1022 void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 1023 1024 SourceLocation getLocation() const { return Loc; } 1025 void setLocation(SourceLocation Loc) { this->Loc = Loc; } 1026 1027 /// \brief Whether this construction is elidable. 1028 bool isElidable() const { return Elidable; } 1029 void setElidable(bool E) { Elidable = E; } 1030 1031 /// \brief Whether the referred constructor was resolved from 1032 /// an overloaded set having size greater than 1. 1033 bool hadMultipleCandidates() const { return HadMultipleCandidates; } 1034 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 1035 1036 /// \brief Whether this constructor call was written as list-initialization. 1037 bool isListInitialization() const { return ListInitialization; } 1038 void setListInitialization(bool V) { ListInitialization = V; } 1039 1040 /// \brief Whether this construction first requires 1041 /// zero-initialization before the initializer is called. 1042 bool requiresZeroInitialization() const { return ZeroInitialization; } 1043 void setRequiresZeroInitialization(bool ZeroInit) { 1044 ZeroInitialization = ZeroInit; 1045 } 1046 1047 /// \brief Determines whether this constructor is actually constructing 1048 /// a base class (rather than a complete object). 1049 ConstructionKind getConstructionKind() const { 1050 return (ConstructionKind)ConstructKind; 1051 } 1052 void setConstructionKind(ConstructionKind CK) { 1053 ConstructKind = CK; 1054 } 1055 1056 typedef ExprIterator arg_iterator; 1057 typedef ConstExprIterator const_arg_iterator; 1058 1059 arg_iterator arg_begin() { return Args; } 1060 arg_iterator arg_end() { return Args + NumArgs; } 1061 const_arg_iterator arg_begin() const { return Args; } 1062 const_arg_iterator arg_end() const { return Args + NumArgs; } 1063 1064 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 1065 unsigned getNumArgs() const { return NumArgs; } 1066 1067 /// getArg - Return the specified argument. 1068 Expr *getArg(unsigned Arg) { 1069 assert(Arg < NumArgs && "Arg access out of range!"); 1070 return cast<Expr>(Args[Arg]); 1071 } 1072 const Expr *getArg(unsigned Arg) const { 1073 assert(Arg < NumArgs && "Arg access out of range!"); 1074 return cast<Expr>(Args[Arg]); 1075 } 1076 1077 /// setArg - Set the specified argument. 1078 void setArg(unsigned Arg, Expr *ArgExpr) { 1079 assert(Arg < NumArgs && "Arg access out of range!"); 1080 Args[Arg] = ArgExpr; 1081 } 1082 1083 SourceLocation getLocStart() const LLVM_READONLY; 1084 SourceLocation getLocEnd() const LLVM_READONLY; 1085 SourceRange getParenRange() const { return ParenRange; } 1086 void setParenRange(SourceRange Range) { ParenRange = Range; } 1087 1088 static bool classof(const Stmt *T) { 1089 return T->getStmtClass() == CXXConstructExprClass || 1090 T->getStmtClass() == CXXTemporaryObjectExprClass; 1091 } 1092 1093 // Iterators 1094 child_range children() { 1095 return child_range(&Args[0], &Args[0]+NumArgs); 1096 } 1097 1098 friend class ASTStmtReader; 1099}; 1100 1101/// \brief Represents an explicit C++ type conversion that uses "functional" 1102/// notation (C++ [expr.type.conv]). 1103/// 1104/// Example: 1105/// @code 1106/// x = int(0.5); 1107/// @endcode 1108class CXXFunctionalCastExpr : public ExplicitCastExpr { 1109 SourceLocation TyBeginLoc; 1110 SourceLocation RParenLoc; 1111 1112 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 1113 TypeSourceInfo *writtenTy, 1114 SourceLocation tyBeginLoc, CastKind kind, 1115 Expr *castExpr, unsigned pathSize, 1116 SourceLocation rParenLoc) 1117 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 1118 castExpr, pathSize, writtenTy), 1119 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 1120 1121 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 1122 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 1123 1124public: 1125 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T, 1126 ExprValueKind VK, 1127 TypeSourceInfo *Written, 1128 SourceLocation TyBeginLoc, 1129 CastKind Kind, Expr *Op, 1130 const CXXCastPath *Path, 1131 SourceLocation RPLoc); 1132 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context, 1133 unsigned PathSize); 1134 1135 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 1136 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 1137 SourceLocation getRParenLoc() const { return RParenLoc; } 1138 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1139 1140 SourceLocation getLocStart() const LLVM_READONLY { return TyBeginLoc; } 1141 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 1142 1143 static bool classof(const Stmt *T) { 1144 return T->getStmtClass() == CXXFunctionalCastExprClass; 1145 } 1146}; 1147 1148/// @brief Represents a C++ functional cast expression that builds a 1149/// temporary object. 1150/// 1151/// This expression type represents a C++ "functional" cast 1152/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 1153/// constructor to build a temporary object. With N == 1 arguments the 1154/// functional cast expression will be represented by CXXFunctionalCastExpr. 1155/// Example: 1156/// @code 1157/// struct X { X(int, float); } 1158/// 1159/// X create_X() { 1160/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 1161/// }; 1162/// @endcode 1163class CXXTemporaryObjectExpr : public CXXConstructExpr { 1164 TypeSourceInfo *Type; 1165 1166public: 1167 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 1168 TypeSourceInfo *Type, 1169 ArrayRef<Expr *> Args, 1170 SourceRange parenRange, 1171 bool HadMultipleCandidates, 1172 bool ListInitialization, 1173 bool ZeroInitialization); 1174 explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1175 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1176 1177 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1178 1179 SourceLocation getLocStart() const LLVM_READONLY; 1180 SourceLocation getLocEnd() const LLVM_READONLY; 1181 1182 static bool classof(const Stmt *T) { 1183 return T->getStmtClass() == CXXTemporaryObjectExprClass; 1184 } 1185 1186 friend class ASTStmtReader; 1187}; 1188 1189/// \brief A C++ lambda expression, which produces a function object 1190/// (of unspecified type) that can be invoked later. 1191/// 1192/// Example: 1193/// \code 1194/// void low_pass_filter(std::vector<double> &values, double cutoff) { 1195/// values.erase(std::remove_if(values.begin(), values.end(), 1196/// [=](double value) { return value > cutoff; }); 1197/// } 1198/// \endcode 1199/// 1200/// Lambda expressions can capture local variables, either by copying 1201/// the values of those local variables at the time the function 1202/// object is constructed (not when it is called!) or by holding a 1203/// reference to the local variable. These captures can occur either 1204/// implicitly or can be written explicitly between the square 1205/// brackets ([...]) that start the lambda expression. 1206class LambdaExpr : public Expr { 1207 enum { 1208 /// \brief Flag used by the Capture class to indicate that the given 1209 /// capture was implicit. 1210 Capture_Implicit = 0x01, 1211 1212 /// \brief Flag used by the Capture class to indciate that the 1213 /// given capture was by-copy. 1214 Capture_ByCopy = 0x02 1215 }; 1216 1217 /// \brief The source range that covers the lambda introducer ([...]). 1218 SourceRange IntroducerRange; 1219 1220 /// \brief The number of captures. 1221 unsigned NumCaptures : 16; 1222 1223 /// \brief The default capture kind, which is a value of type 1224 /// LambdaCaptureDefault. 1225 unsigned CaptureDefault : 2; 1226 1227 /// \brief Whether this lambda had an explicit parameter list vs. an 1228 /// implicit (and empty) parameter list. 1229 unsigned ExplicitParams : 1; 1230 1231 /// \brief Whether this lambda had the result type explicitly specified. 1232 unsigned ExplicitResultType : 1; 1233 1234 /// \brief Whether there are any array index variables stored at the end of 1235 /// this lambda expression. 1236 unsigned HasArrayIndexVars : 1; 1237 1238 /// \brief The location of the closing brace ('}') that completes 1239 /// the lambda. 1240 /// 1241 /// The location of the brace is also available by looking up the 1242 /// function call operator in the lambda class. However, it is 1243 /// stored here to improve the performance of getSourceRange(), and 1244 /// to avoid having to deserialize the function call operator from a 1245 /// module file just to determine the source range. 1246 SourceLocation ClosingBrace; 1247 1248 // Note: The capture initializers are stored directly after the lambda 1249 // expression, along with the index variables used to initialize by-copy 1250 // array captures. 1251 1252public: 1253 /// \brief Describes the capture of either a variable or 'this'. 1254 class Capture { 1255 llvm::PointerIntPair<VarDecl *, 2> VarAndBits; 1256 SourceLocation Loc; 1257 SourceLocation EllipsisLoc; 1258 1259 friend class ASTStmtReader; 1260 friend class ASTStmtWriter; 1261 1262 public: 1263 /// \brief Create a new capture. 1264 /// 1265 /// \param Loc The source location associated with this capture. 1266 /// 1267 /// \param Kind The kind of capture (this, byref, bycopy). 1268 /// 1269 /// \param Implicit Whether the capture was implicit or explicit. 1270 /// 1271 /// \param Var The local variable being captured, or null if capturing this. 1272 /// 1273 /// \param EllipsisLoc The location of the ellipsis (...) for a 1274 /// capture that is a pack expansion, or an invalid source 1275 /// location to indicate that this is not a pack expansion. 1276 Capture(SourceLocation Loc, bool Implicit, 1277 LambdaCaptureKind Kind, VarDecl *Var = 0, 1278 SourceLocation EllipsisLoc = SourceLocation()); 1279 1280 /// \brief Determine the kind of capture. 1281 LambdaCaptureKind getCaptureKind() const; 1282 1283 /// \brief Determine whether this capture handles the C++ 'this' 1284 /// pointer. 1285 bool capturesThis() const { return VarAndBits.getPointer() == 0; } 1286 1287 /// \brief Determine whether this capture handles a variable. 1288 bool capturesVariable() const { return VarAndBits.getPointer() != 0; } 1289 1290 /// \brief Retrieve the declaration of the local variable being 1291 /// captured. 1292 /// 1293 /// This operation is only valid if this capture does not capture 1294 /// 'this'. 1295 VarDecl *getCapturedVar() const { 1296 assert(!capturesThis() && "No variable available for 'this' capture"); 1297 return VarAndBits.getPointer(); 1298 } 1299 1300 /// \brief Determine whether this was an implicit capture (not 1301 /// written between the square brackets introducing the lambda). 1302 bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; } 1303 1304 /// \brief Determine whether this was an explicit capture, written 1305 /// between the square brackets introducing the lambda. 1306 bool isExplicit() const { return !isImplicit(); } 1307 1308 /// \brief Retrieve the source location of the capture. 1309 /// 1310 /// For an explicit capture, this returns the location of the 1311 /// explicit capture in the source. For an implicit capture, this 1312 /// returns the location at which the variable or 'this' was first 1313 /// used. 1314 SourceLocation getLocation() const { return Loc; } 1315 1316 /// \brief Determine whether this capture is a pack expansion, 1317 /// which captures a function parameter pack. 1318 bool isPackExpansion() const { return EllipsisLoc.isValid(); } 1319 1320 /// \brief Retrieve the location of the ellipsis for a capture 1321 /// that is a pack expansion. 1322 SourceLocation getEllipsisLoc() const { 1323 assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 1324 return EllipsisLoc; 1325 } 1326 }; 1327 1328private: 1329 /// \brief Construct a lambda expression. 1330 LambdaExpr(QualType T, SourceRange IntroducerRange, 1331 LambdaCaptureDefault CaptureDefault, 1332 ArrayRef<Capture> Captures, 1333 bool ExplicitParams, 1334 bool ExplicitResultType, 1335 ArrayRef<Expr *> CaptureInits, 1336 ArrayRef<VarDecl *> ArrayIndexVars, 1337 ArrayRef<unsigned> ArrayIndexStarts, 1338 SourceLocation ClosingBrace, 1339 bool ContainsUnexpandedParameterPack); 1340 1341 /// \brief Construct an empty lambda expression. 1342 LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars) 1343 : Expr(LambdaExprClass, Empty), 1344 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false), 1345 ExplicitResultType(false), HasArrayIndexVars(true) { 1346 getStoredStmts()[NumCaptures] = 0; 1347 } 1348 1349 Stmt **getStoredStmts() const { 1350 return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1); 1351 } 1352 1353 /// \brief Retrieve the mapping from captures to the first array index 1354 /// variable. 1355 unsigned *getArrayIndexStarts() const { 1356 return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1); 1357 } 1358 1359 /// \brief Retrieve the complete set of array-index variables. 1360 VarDecl **getArrayIndexVars() const { 1361 unsigned ArrayIndexSize = 1362 llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1), 1363 llvm::alignOf<VarDecl*>()); 1364 return reinterpret_cast<VarDecl **>( 1365 reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize); 1366 } 1367 1368public: 1369 /// \brief Construct a new lambda expression. 1370 static LambdaExpr *Create(ASTContext &C, 1371 CXXRecordDecl *Class, 1372 SourceRange IntroducerRange, 1373 LambdaCaptureDefault CaptureDefault, 1374 ArrayRef<Capture> Captures, 1375 bool ExplicitParams, 1376 bool ExplicitResultType, 1377 ArrayRef<Expr *> CaptureInits, 1378 ArrayRef<VarDecl *> ArrayIndexVars, 1379 ArrayRef<unsigned> ArrayIndexStarts, 1380 SourceLocation ClosingBrace, 1381 bool ContainsUnexpandedParameterPack); 1382 1383 /// \brief Construct a new lambda expression that will be deserialized from 1384 /// an external source. 1385 static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures, 1386 unsigned NumArrayIndexVars); 1387 1388 /// \brief Determine the default capture kind for this lambda. 1389 LambdaCaptureDefault getCaptureDefault() const { 1390 return static_cast<LambdaCaptureDefault>(CaptureDefault); 1391 } 1392 1393 /// \brief An iterator that walks over the captures of the lambda, 1394 /// both implicit and explicit. 1395 typedef const Capture *capture_iterator; 1396 1397 /// \brief Retrieve an iterator pointing to the first lambda capture. 1398 capture_iterator capture_begin() const; 1399 1400 /// \brief Retrieve an iterator pointing past the end of the 1401 /// sequence of lambda captures. 1402 capture_iterator capture_end() const; 1403 1404 /// \brief Determine the number of captures in this lambda. 1405 unsigned capture_size() const { return NumCaptures; } 1406 1407 /// \brief Retrieve an iterator pointing to the first explicit 1408 /// lambda capture. 1409 capture_iterator explicit_capture_begin() const; 1410 1411 /// \brief Retrieve an iterator pointing past the end of the sequence of 1412 /// explicit lambda captures. 1413 capture_iterator explicit_capture_end() const; 1414 1415 /// \brief Retrieve an iterator pointing to the first implicit 1416 /// lambda capture. 1417 capture_iterator implicit_capture_begin() const; 1418 1419 /// \brief Retrieve an iterator pointing past the end of the sequence of 1420 /// implicit lambda captures. 1421 capture_iterator implicit_capture_end() const; 1422 1423 /// \brief Iterator that walks over the capture initialization 1424 /// arguments. 1425 typedef Expr **capture_init_iterator; 1426 1427 /// \brief Retrieve the first initialization argument for this 1428 /// lambda expression (which initializes the first capture field). 1429 capture_init_iterator capture_init_begin() const { 1430 return reinterpret_cast<Expr **>(getStoredStmts()); 1431 } 1432 1433 /// \brief Retrieve the iterator pointing one past the last 1434 /// initialization argument for this lambda expression. 1435 capture_init_iterator capture_init_end() const { 1436 return capture_init_begin() + NumCaptures; 1437 } 1438 1439 /// \brief Retrieve the set of index variables used in the capture 1440 /// initializer of an array captured by copy. 1441 /// 1442 /// \param Iter The iterator that points at the capture initializer for 1443 /// which we are extracting the corresponding index variables. 1444 ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const; 1445 1446 /// \brief Retrieve the source range covering the lambda introducer, 1447 /// which contains the explicit capture list surrounded by square 1448 /// brackets ([...]). 1449 SourceRange getIntroducerRange() const { return IntroducerRange; } 1450 1451 /// \brief Retrieve the class that corresponds to the lambda, which 1452 /// stores the captures in its fields and provides the various 1453 /// operations permitted on a lambda (copying, calling). 1454 CXXRecordDecl *getLambdaClass() const; 1455 1456 /// \brief Retrieve the function call operator associated with this 1457 /// lambda expression. 1458 CXXMethodDecl *getCallOperator() const; 1459 1460 /// \brief Retrieve the body of the lambda. 1461 CompoundStmt *getBody() const; 1462 1463 /// \brief Determine whether the lambda is mutable, meaning that any 1464 /// captures values can be modified. 1465 bool isMutable() const; 1466 1467 /// \brief Determine whether this lambda has an explicit parameter 1468 /// list vs. an implicit (empty) parameter list. 1469 bool hasExplicitParameters() const { return ExplicitParams; } 1470 1471 /// \brief Whether this lambda had its result type explicitly specified. 1472 bool hasExplicitResultType() const { return ExplicitResultType; } 1473 1474 static bool classof(const Stmt *T) { 1475 return T->getStmtClass() == LambdaExprClass; 1476 } 1477 1478 SourceLocation getLocStart() const LLVM_READONLY { 1479 return IntroducerRange.getBegin(); 1480 } 1481 SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; } 1482 1483 child_range children() { 1484 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); 1485 } 1486 1487 friend class ASTStmtReader; 1488 friend class ASTStmtWriter; 1489}; 1490 1491/// CXXScalarValueInitExpr - [C++ 5.2.3p2] 1492/// Expression "T()" which creates a value-initialized rvalue of type 1493/// T, which is a non-class type. 1494/// 1495class CXXScalarValueInitExpr : public Expr { 1496 SourceLocation RParenLoc; 1497 TypeSourceInfo *TypeInfo; 1498 1499 friend class ASTStmtReader; 1500 1501public: 1502 /// \brief Create an explicitly-written scalar-value initialization 1503 /// expression. 1504 CXXScalarValueInitExpr(QualType Type, 1505 TypeSourceInfo *TypeInfo, 1506 SourceLocation rParenLoc ) : 1507 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 1508 false, false, Type->isInstantiationDependentType(), false), 1509 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 1510 1511 explicit CXXScalarValueInitExpr(EmptyShell Shell) 1512 : Expr(CXXScalarValueInitExprClass, Shell) { } 1513 1514 TypeSourceInfo *getTypeSourceInfo() const { 1515 return TypeInfo; 1516 } 1517 1518 SourceLocation getRParenLoc() const { return RParenLoc; } 1519 1520 SourceLocation getLocStart() const LLVM_READONLY; 1521 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 1522 1523 static bool classof(const Stmt *T) { 1524 return T->getStmtClass() == CXXScalarValueInitExprClass; 1525 } 1526 1527 // Iterators 1528 child_range children() { return child_range(); } 1529}; 1530 1531/// @brief Represents a new-expression for memory allocation and constructor 1532// calls, e.g: "new CXXNewExpr(foo)". 1533class CXXNewExpr : public Expr { 1534 // Contains an optional array size expression, an optional initialization 1535 // expression, and any number of optional placement arguments, in that order. 1536 Stmt **SubExprs; 1537 /// \brief Points to the allocation function used. 1538 FunctionDecl *OperatorNew; 1539 /// \brief Points to the deallocation function used in case of error. May be 1540 /// null. 1541 FunctionDecl *OperatorDelete; 1542 1543 /// \brief The allocated type-source information, as written in the source. 1544 TypeSourceInfo *AllocatedTypeInfo; 1545 1546 /// \brief If the allocated type was expressed as a parenthesized type-id, 1547 /// the source range covering the parenthesized type-id. 1548 SourceRange TypeIdParens; 1549 1550 /// \brief Range of the entire new expression. 1551 SourceRange Range; 1552 1553 /// \brief Source-range of a paren-delimited initializer. 1554 SourceRange DirectInitRange; 1555 1556 // Was the usage ::new, i.e. is the global new to be used? 1557 bool GlobalNew : 1; 1558 // Do we allocate an array? If so, the first SubExpr is the size expression. 1559 bool Array : 1; 1560 // If this is an array allocation, does the usual deallocation 1561 // function for the allocated type want to know the allocated size? 1562 bool UsualArrayDeleteWantsSize : 1; 1563 // The number of placement new arguments. 1564 unsigned NumPlacementArgs : 13; 1565 // What kind of initializer do we have? Could be none, parens, or braces. 1566 // In storage, we distinguish between "none, and no initializer expr", and 1567 // "none, but an implicit initializer expr". 1568 unsigned StoredInitializationStyle : 2; 1569 1570 friend class ASTStmtReader; 1571 friend class ASTStmtWriter; 1572public: 1573 enum InitializationStyle { 1574 NoInit, ///< New-expression has no initializer as written. 1575 CallInit, ///< New-expression has a C++98 paren-delimited initializer. 1576 ListInit ///< New-expression has a C++11 list-initializer. 1577 }; 1578 1579 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 1580 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, 1581 ArrayRef<Expr*> placementArgs, 1582 SourceRange typeIdParens, Expr *arraySize, 1583 InitializationStyle initializationStyle, Expr *initializer, 1584 QualType ty, TypeSourceInfo *AllocatedTypeInfo, 1585 SourceRange Range, SourceRange directInitRange); 1586 explicit CXXNewExpr(EmptyShell Shell) 1587 : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 1588 1589 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs, 1590 bool hasInitializer); 1591 1592 QualType getAllocatedType() const { 1593 assert(getType()->isPointerType()); 1594 return getType()->getAs<PointerType>()->getPointeeType(); 1595 } 1596 1597 TypeSourceInfo *getAllocatedTypeSourceInfo() const { 1598 return AllocatedTypeInfo; 1599 } 1600 1601 /// \brief True if the allocation result needs to be null-checked. 1602 /// C++0x [expr.new]p13: 1603 /// If the allocation function returns null, initialization shall 1604 /// not be done, the deallocation function shall not be called, 1605 /// and the value of the new-expression shall be null. 1606 /// An allocation function is not allowed to return null unless it 1607 /// has a non-throwing exception-specification. The '03 rule is 1608 /// identical except that the definition of a non-throwing 1609 /// exception specification is just "is it throw()?". 1610 bool shouldNullCheckAllocation(ASTContext &Ctx) const; 1611 1612 FunctionDecl *getOperatorNew() const { return OperatorNew; } 1613 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 1614 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1615 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 1616 1617 bool isArray() const { return Array; } 1618 Expr *getArraySize() { 1619 return Array ? cast<Expr>(SubExprs[0]) : 0; 1620 } 1621 const Expr *getArraySize() const { 1622 return Array ? cast<Expr>(SubExprs[0]) : 0; 1623 } 1624 1625 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1626 Expr **getPlacementArgs() { 1627 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer()); 1628 } 1629 1630 Expr *getPlacementArg(unsigned i) { 1631 assert(i < NumPlacementArgs && "Index out of range"); 1632 return getPlacementArgs()[i]; 1633 } 1634 const Expr *getPlacementArg(unsigned i) const { 1635 assert(i < NumPlacementArgs && "Index out of range"); 1636 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i); 1637 } 1638 1639 bool isParenTypeId() const { return TypeIdParens.isValid(); } 1640 SourceRange getTypeIdParens() const { return TypeIdParens; } 1641 1642 bool isGlobalNew() const { return GlobalNew; } 1643 1644 /// \brief Whether this new-expression has any initializer at all. 1645 bool hasInitializer() const { return StoredInitializationStyle > 0; } 1646 1647 /// \brief The kind of initializer this new-expression has. 1648 InitializationStyle getInitializationStyle() const { 1649 if (StoredInitializationStyle == 0) 1650 return NoInit; 1651 return static_cast<InitializationStyle>(StoredInitializationStyle-1); 1652 } 1653 1654 /// \brief The initializer of this new-expression. 1655 Expr *getInitializer() { 1656 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 1657 } 1658 const Expr *getInitializer() const { 1659 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 1660 } 1661 1662 /// \brief Returns the CXXConstructExpr from this new-expression, or NULL. 1663 const CXXConstructExpr* getConstructExpr() const { 1664 return dyn_cast_or_null<CXXConstructExpr>(getInitializer()); 1665 } 1666 1667 /// Answers whether the usual array deallocation function for the 1668 /// allocated type expects the size of the allocation as a 1669 /// parameter. 1670 bool doesUsualArrayDeleteWantSize() const { 1671 return UsualArrayDeleteWantsSize; 1672 } 1673 1674 typedef ExprIterator arg_iterator; 1675 typedef ConstExprIterator const_arg_iterator; 1676 1677 arg_iterator placement_arg_begin() { 1678 return SubExprs + Array + hasInitializer(); 1679 } 1680 arg_iterator placement_arg_end() { 1681 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1682 } 1683 const_arg_iterator placement_arg_begin() const { 1684 return SubExprs + Array + hasInitializer(); 1685 } 1686 const_arg_iterator placement_arg_end() const { 1687 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1688 } 1689 1690 typedef Stmt **raw_arg_iterator; 1691 raw_arg_iterator raw_arg_begin() { return SubExprs; } 1692 raw_arg_iterator raw_arg_end() { 1693 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1694 } 1695 const_arg_iterator raw_arg_begin() const { return SubExprs; } 1696 const_arg_iterator raw_arg_end() const { 1697 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1698 } 1699 1700 SourceLocation getStartLoc() const { return Range.getBegin(); } 1701 SourceLocation getEndLoc() const { return Range.getEnd(); } 1702 1703 SourceRange getDirectInitRange() const { return DirectInitRange; } 1704 1705 SourceRange getSourceRange() const LLVM_READONLY { 1706 return Range; 1707 } 1708 SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); } 1709 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 1710 1711 static bool classof(const Stmt *T) { 1712 return T->getStmtClass() == CXXNewExprClass; 1713 } 1714 1715 // Iterators 1716 child_range children() { 1717 return child_range(raw_arg_begin(), raw_arg_end()); 1718 } 1719}; 1720 1721/// \brief Represents a \c delete expression for memory deallocation and 1722/// destructor calls, e.g. "delete[] pArray". 1723class CXXDeleteExpr : public Expr { 1724 // Points to the operator delete overload that is used. Could be a member. 1725 FunctionDecl *OperatorDelete; 1726 // The pointer expression to be deleted. 1727 Stmt *Argument; 1728 // Location of the expression. 1729 SourceLocation Loc; 1730 // Is this a forced global delete, i.e. "::delete"? 1731 bool GlobalDelete : 1; 1732 // Is this the array form of delete, i.e. "delete[]"? 1733 bool ArrayForm : 1; 1734 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 1735 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 1736 // will be true). 1737 bool ArrayFormAsWritten : 1; 1738 // Does the usual deallocation function for the element type require 1739 // a size_t argument? 1740 bool UsualArrayDeleteWantsSize : 1; 1741public: 1742 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 1743 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize, 1744 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1745 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1746 arg->isInstantiationDependent(), 1747 arg->containsUnexpandedParameterPack()), 1748 OperatorDelete(operatorDelete), Argument(arg), Loc(loc), 1749 GlobalDelete(globalDelete), 1750 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 1751 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { } 1752 explicit CXXDeleteExpr(EmptyShell Shell) 1753 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 1754 1755 bool isGlobalDelete() const { return GlobalDelete; } 1756 bool isArrayForm() const { return ArrayForm; } 1757 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 1758 1759 /// Answers whether the usual array deallocation function for the 1760 /// allocated type expects the size of the allocation as a 1761 /// parameter. This can be true even if the actual deallocation 1762 /// function that we're using doesn't want a size. 1763 bool doesUsualArrayDeleteWantSize() const { 1764 return UsualArrayDeleteWantsSize; 1765 } 1766 1767 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1768 1769 Expr *getArgument() { return cast<Expr>(Argument); } 1770 const Expr *getArgument() const { return cast<Expr>(Argument); } 1771 1772 /// \brief Retrieve the type being destroyed. If the type being 1773 /// destroyed is a dependent type which may or may not be a pointer, 1774 /// return an invalid type. 1775 QualType getDestroyedType() const; 1776 1777 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 1778 SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();} 1779 1780 static bool classof(const Stmt *T) { 1781 return T->getStmtClass() == CXXDeleteExprClass; 1782 } 1783 1784 // Iterators 1785 child_range children() { return child_range(&Argument, &Argument+1); } 1786 1787 friend class ASTStmtReader; 1788}; 1789 1790/// \brief Stores the type being destroyed by a pseudo-destructor expression. 1791class PseudoDestructorTypeStorage { 1792 /// \brief Either the type source information or the name of the type, if 1793 /// it couldn't be resolved due to type-dependence. 1794 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1795 1796 /// \brief The starting source location of the pseudo-destructor type. 1797 SourceLocation Location; 1798 1799public: 1800 PseudoDestructorTypeStorage() { } 1801 1802 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1803 : Type(II), Location(Loc) { } 1804 1805 PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1806 1807 TypeSourceInfo *getTypeSourceInfo() const { 1808 return Type.dyn_cast<TypeSourceInfo *>(); 1809 } 1810 1811 IdentifierInfo *getIdentifier() const { 1812 return Type.dyn_cast<IdentifierInfo *>(); 1813 } 1814 1815 SourceLocation getLocation() const { return Location; } 1816}; 1817 1818/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1819/// 1820/// A pseudo-destructor is an expression that looks like a member access to a 1821/// destructor of a scalar type, except that scalar types don't have 1822/// destructors. For example: 1823/// 1824/// \code 1825/// typedef int T; 1826/// void f(int *p) { 1827/// p->T::~T(); 1828/// } 1829/// \endcode 1830/// 1831/// Pseudo-destructors typically occur when instantiating templates such as: 1832/// 1833/// \code 1834/// template<typename T> 1835/// void destroy(T* ptr) { 1836/// ptr->T::~T(); 1837/// } 1838/// \endcode 1839/// 1840/// for scalar types. A pseudo-destructor expression has no run-time semantics 1841/// beyond evaluating the base expression. 1842class CXXPseudoDestructorExpr : public Expr { 1843 /// \brief The base expression (that is being destroyed). 1844 Stmt *Base; 1845 1846 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1847 /// period ('.'). 1848 bool IsArrow : 1; 1849 1850 /// \brief The location of the '.' or '->' operator. 1851 SourceLocation OperatorLoc; 1852 1853 /// \brief The nested-name-specifier that follows the operator, if present. 1854 NestedNameSpecifierLoc QualifierLoc; 1855 1856 /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1857 /// expression. 1858 TypeSourceInfo *ScopeType; 1859 1860 /// \brief The location of the '::' in a qualified pseudo-destructor 1861 /// expression. 1862 SourceLocation ColonColonLoc; 1863 1864 /// \brief The location of the '~'. 1865 SourceLocation TildeLoc; 1866 1867 /// \brief The type being destroyed, or its name if we were unable to 1868 /// resolve the name. 1869 PseudoDestructorTypeStorage DestroyedType; 1870 1871 friend class ASTStmtReader; 1872 1873public: 1874 CXXPseudoDestructorExpr(ASTContext &Context, 1875 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1876 NestedNameSpecifierLoc QualifierLoc, 1877 TypeSourceInfo *ScopeType, 1878 SourceLocation ColonColonLoc, 1879 SourceLocation TildeLoc, 1880 PseudoDestructorTypeStorage DestroyedType); 1881 1882 explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1883 : Expr(CXXPseudoDestructorExprClass, Shell), 1884 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { } 1885 1886 Expr *getBase() const { return cast<Expr>(Base); } 1887 1888 /// \brief Determines whether this member expression actually had 1889 /// a C++ nested-name-specifier prior to the name of the member, e.g., 1890 /// x->Base::foo. 1891 bool hasQualifier() const { return QualifierLoc; } 1892 1893 /// \brief Retrieves the nested-name-specifier that qualifies the type name, 1894 /// with source-location information. 1895 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 1896 1897 /// \brief If the member name was qualified, retrieves the 1898 /// nested-name-specifier that precedes the member name. Otherwise, returns 1899 /// NULL. 1900 NestedNameSpecifier *getQualifier() const { 1901 return QualifierLoc.getNestedNameSpecifier(); 1902 } 1903 1904 /// \brief Determine whether this pseudo-destructor expression was written 1905 /// using an '->' (otherwise, it used a '.'). 1906 bool isArrow() const { return IsArrow; } 1907 1908 /// \brief Retrieve the location of the '.' or '->' operator. 1909 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1910 1911 /// \brief Retrieve the scope type in a qualified pseudo-destructor 1912 /// expression. 1913 /// 1914 /// Pseudo-destructor expressions can have extra qualification within them 1915 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1916 /// Here, if the object type of the expression is (or may be) a scalar type, 1917 /// \p T may also be a scalar type and, therefore, cannot be part of a 1918 /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1919 /// destructor expression. 1920 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1921 1922 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1923 /// expression. 1924 SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1925 1926 /// \brief Retrieve the location of the '~'. 1927 SourceLocation getTildeLoc() const { return TildeLoc; } 1928 1929 /// \brief Retrieve the source location information for the type 1930 /// being destroyed. 1931 /// 1932 /// This type-source information is available for non-dependent 1933 /// pseudo-destructor expressions and some dependent pseudo-destructor 1934 /// expressions. Returns NULL if we only have the identifier for a 1935 /// dependent pseudo-destructor expression. 1936 TypeSourceInfo *getDestroyedTypeInfo() const { 1937 return DestroyedType.getTypeSourceInfo(); 1938 } 1939 1940 /// \brief In a dependent pseudo-destructor expression for which we do not 1941 /// have full type information on the destroyed type, provides the name 1942 /// of the destroyed type. 1943 IdentifierInfo *getDestroyedTypeIdentifier() const { 1944 return DestroyedType.getIdentifier(); 1945 } 1946 1947 /// \brief Retrieve the type being destroyed. 1948 QualType getDestroyedType() const; 1949 1950 /// \brief Retrieve the starting location of the type being destroyed. 1951 SourceLocation getDestroyedTypeLoc() const { 1952 return DestroyedType.getLocation(); 1953 } 1954 1955 /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1956 /// expression. 1957 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1958 DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1959 } 1960 1961 /// \brief Set the destroyed type. 1962 void setDestroyedType(TypeSourceInfo *Info) { 1963 DestroyedType = PseudoDestructorTypeStorage(Info); 1964 } 1965 1966 SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();} 1967 SourceLocation getLocEnd() const LLVM_READONLY; 1968 1969 static bool classof(const Stmt *T) { 1970 return T->getStmtClass() == CXXPseudoDestructorExprClass; 1971 } 1972 1973 // Iterators 1974 child_range children() { return child_range(&Base, &Base + 1); } 1975}; 1976 1977/// \brief Represents a GCC or MS unary type trait, as used in the 1978/// implementation of TR1/C++11 type trait templates. 1979/// 1980/// Example: 1981/// @code 1982/// __is_pod(int) == true 1983/// __is_enum(std::string) == false 1984/// @endcode 1985class UnaryTypeTraitExpr : public Expr { 1986 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned. 1987 unsigned UTT : 31; 1988 /// The value of the type trait. Unspecified if dependent. 1989 bool Value : 1; 1990 1991 /// Loc - The location of the type trait keyword. 1992 SourceLocation Loc; 1993 1994 /// RParen - The location of the closing paren. 1995 SourceLocation RParen; 1996 1997 /// The type being queried. 1998 TypeSourceInfo *QueriedType; 1999 2000public: 2001 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 2002 TypeSourceInfo *queried, bool value, 2003 SourceLocation rparen, QualType ty) 2004 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 2005 false, queried->getType()->isDependentType(), 2006 queried->getType()->isInstantiationDependentType(), 2007 queried->getType()->containsUnexpandedParameterPack()), 2008 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 2009 2010 explicit UnaryTypeTraitExpr(EmptyShell Empty) 2011 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 2012 QueriedType() { } 2013 2014 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2015 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2016 2017 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 2018 2019 QualType getQueriedType() const { return QueriedType->getType(); } 2020 2021 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 2022 2023 bool getValue() const { return Value; } 2024 2025 static bool classof(const Stmt *T) { 2026 return T->getStmtClass() == UnaryTypeTraitExprClass; 2027 } 2028 2029 // Iterators 2030 child_range children() { return child_range(); } 2031 2032 friend class ASTStmtReader; 2033}; 2034 2035/// \brief Represents a GCC or MS binary type trait, as used in the 2036/// implementation of TR1/C++11 type trait templates. 2037/// 2038/// Example: 2039/// @code 2040/// __is_base_of(Base, Derived) == true 2041/// @endcode 2042class BinaryTypeTraitExpr : public Expr { 2043 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned. 2044 unsigned BTT : 8; 2045 2046 /// The value of the type trait. Unspecified if dependent. 2047 bool Value : 1; 2048 2049 /// Loc - The location of the type trait keyword. 2050 SourceLocation Loc; 2051 2052 /// RParen - The location of the closing paren. 2053 SourceLocation RParen; 2054 2055 /// The lhs type being queried. 2056 TypeSourceInfo *LhsType; 2057 2058 /// The rhs type being queried. 2059 TypeSourceInfo *RhsType; 2060 2061public: 2062 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 2063 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 2064 bool value, SourceLocation rparen, QualType ty) 2065 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 2066 lhsType->getType()->isDependentType() || 2067 rhsType->getType()->isDependentType(), 2068 (lhsType->getType()->isInstantiationDependentType() || 2069 rhsType->getType()->isInstantiationDependentType()), 2070 (lhsType->getType()->containsUnexpandedParameterPack() || 2071 rhsType->getType()->containsUnexpandedParameterPack())), 2072 BTT(btt), Value(value), Loc(loc), RParen(rparen), 2073 LhsType(lhsType), RhsType(rhsType) { } 2074 2075 2076 explicit BinaryTypeTraitExpr(EmptyShell Empty) 2077 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 2078 LhsType(), RhsType() { } 2079 2080 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2081 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2082 2083 BinaryTypeTrait getTrait() const { 2084 return static_cast<BinaryTypeTrait>(BTT); 2085 } 2086 2087 QualType getLhsType() const { return LhsType->getType(); } 2088 QualType getRhsType() const { return RhsType->getType(); } 2089 2090 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 2091 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 2092 2093 bool getValue() const { assert(!isTypeDependent()); return Value; } 2094 2095 static bool classof(const Stmt *T) { 2096 return T->getStmtClass() == BinaryTypeTraitExprClass; 2097 } 2098 2099 // Iterators 2100 child_range children() { return child_range(); } 2101 2102 friend class ASTStmtReader; 2103}; 2104 2105/// \brief A type trait used in the implementation of various C++11 and 2106/// Library TR1 trait templates. 2107/// 2108/// \code 2109/// __is_trivially_constructible(vector<int>, int*, int*) 2110/// \endcode 2111class TypeTraitExpr : public Expr { 2112 /// \brief The location of the type trait keyword. 2113 SourceLocation Loc; 2114 2115 /// \brief The location of the closing parenthesis. 2116 SourceLocation RParenLoc; 2117 2118 // Note: The TypeSourceInfos for the arguments are allocated after the 2119 // TypeTraitExpr. 2120 2121 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, 2122 ArrayRef<TypeSourceInfo *> Args, 2123 SourceLocation RParenLoc, 2124 bool Value); 2125 2126 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { } 2127 2128 /// \brief Retrieve the argument types. 2129 TypeSourceInfo **getTypeSourceInfos() { 2130 return reinterpret_cast<TypeSourceInfo **>(this+1); 2131 } 2132 2133 /// \brief Retrieve the argument types. 2134 TypeSourceInfo * const *getTypeSourceInfos() const { 2135 return reinterpret_cast<TypeSourceInfo * const*>(this+1); 2136 } 2137 2138public: 2139 /// \brief Create a new type trait expression. 2140 static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc, 2141 TypeTrait Kind, 2142 ArrayRef<TypeSourceInfo *> Args, 2143 SourceLocation RParenLoc, 2144 bool Value); 2145 2146 static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs); 2147 2148 /// \brief Determine which type trait this expression uses. 2149 TypeTrait getTrait() const { 2150 return static_cast<TypeTrait>(TypeTraitExprBits.Kind); 2151 } 2152 2153 bool getValue() const { 2154 assert(!isValueDependent()); 2155 return TypeTraitExprBits.Value; 2156 } 2157 2158 /// \brief Determine the number of arguments to this type trait. 2159 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; } 2160 2161 /// \brief Retrieve the Ith argument. 2162 TypeSourceInfo *getArg(unsigned I) const { 2163 assert(I < getNumArgs() && "Argument out-of-range"); 2164 return getArgs()[I]; 2165 } 2166 2167 /// \brief Retrieve the argument types. 2168 ArrayRef<TypeSourceInfo *> getArgs() const { 2169 return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs()); 2170 } 2171 2172 typedef TypeSourceInfo **arg_iterator; 2173 arg_iterator arg_begin() { 2174 return getTypeSourceInfos(); 2175 } 2176 arg_iterator arg_end() { 2177 return getTypeSourceInfos() + getNumArgs(); 2178 } 2179 2180 typedef TypeSourceInfo const * const *arg_const_iterator; 2181 arg_const_iterator arg_begin() const { return getTypeSourceInfos(); } 2182 arg_const_iterator arg_end() const { 2183 return getTypeSourceInfos() + getNumArgs(); 2184 } 2185 2186 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2187 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 2188 2189 static bool classof(const Stmt *T) { 2190 return T->getStmtClass() == TypeTraitExprClass; 2191 } 2192 2193 // Iterators 2194 child_range children() { return child_range(); } 2195 2196 friend class ASTStmtReader; 2197 friend class ASTStmtWriter; 2198 2199}; 2200 2201/// \brief An Embarcadero array type trait, as used in the implementation of 2202/// __array_rank and __array_extent. 2203/// 2204/// Example: 2205/// @code 2206/// __array_rank(int[10][20]) == 2 2207/// __array_extent(int, 1) == 20 2208/// @endcode 2209class ArrayTypeTraitExpr : public Expr { 2210 virtual void anchor(); 2211 2212 /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 2213 unsigned ATT : 2; 2214 2215 /// \brief The value of the type trait. Unspecified if dependent. 2216 uint64_t Value; 2217 2218 /// \brief The array dimension being queried, or -1 if not used. 2219 Expr *Dimension; 2220 2221 /// \brief The location of the type trait keyword. 2222 SourceLocation Loc; 2223 2224 /// \brief The location of the closing paren. 2225 SourceLocation RParen; 2226 2227 /// \brief The type being queried. 2228 TypeSourceInfo *QueriedType; 2229 2230public: 2231 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 2232 TypeSourceInfo *queried, uint64_t value, 2233 Expr *dimension, SourceLocation rparen, QualType ty) 2234 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 2235 false, queried->getType()->isDependentType(), 2236 (queried->getType()->isInstantiationDependentType() || 2237 (dimension && dimension->isInstantiationDependent())), 2238 queried->getType()->containsUnexpandedParameterPack()), 2239 ATT(att), Value(value), Dimension(dimension), 2240 Loc(loc), RParen(rparen), QueriedType(queried) { } 2241 2242 2243 explicit ArrayTypeTraitExpr(EmptyShell Empty) 2244 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 2245 QueriedType() { } 2246 2247 virtual ~ArrayTypeTraitExpr() { } 2248 2249 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2250 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2251 2252 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 2253 2254 QualType getQueriedType() const { return QueriedType->getType(); } 2255 2256 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 2257 2258 uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 2259 2260 Expr *getDimensionExpression() const { return Dimension; } 2261 2262 static bool classof(const Stmt *T) { 2263 return T->getStmtClass() == ArrayTypeTraitExprClass; 2264 } 2265 2266 // Iterators 2267 child_range children() { return child_range(); } 2268 2269 friend class ASTStmtReader; 2270}; 2271 2272/// \brief An expression trait intrinsic. 2273/// 2274/// Example: 2275/// @code 2276/// __is_lvalue_expr(std::cout) == true 2277/// __is_lvalue_expr(1) == false 2278/// @endcode 2279class ExpressionTraitExpr : public Expr { 2280 /// \brief The trait. A ExpressionTrait enum in MSVC compat unsigned. 2281 unsigned ET : 31; 2282 /// \brief The value of the type trait. Unspecified if dependent. 2283 bool Value : 1; 2284 2285 /// \brief The location of the type trait keyword. 2286 SourceLocation Loc; 2287 2288 /// \brief The location of the closing paren. 2289 SourceLocation RParen; 2290 2291 /// \brief The expression being queried. 2292 Expr* QueriedExpression; 2293public: 2294 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2295 Expr *queried, bool value, 2296 SourceLocation rparen, QualType resultType) 2297 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2298 false, // Not type-dependent 2299 // Value-dependent if the argument is type-dependent. 2300 queried->isTypeDependent(), 2301 queried->isInstantiationDependent(), 2302 queried->containsUnexpandedParameterPack()), 2303 ET(et), Value(value), Loc(loc), RParen(rparen), 2304 QueriedExpression(queried) { } 2305 2306 explicit ExpressionTraitExpr(EmptyShell Empty) 2307 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2308 QueriedExpression() { } 2309 2310 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2311 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2312 2313 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2314 2315 Expr *getQueriedExpression() const { return QueriedExpression; } 2316 2317 bool getValue() const { return Value; } 2318 2319 static bool classof(const Stmt *T) { 2320 return T->getStmtClass() == ExpressionTraitExprClass; 2321 } 2322 2323 // Iterators 2324 child_range children() { return child_range(); } 2325 2326 friend class ASTStmtReader; 2327}; 2328 2329 2330/// \brief A reference to an overloaded function set, either an 2331/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr. 2332class OverloadExpr : public Expr { 2333 /// \brief The common name of these declarations. 2334 DeclarationNameInfo NameInfo; 2335 2336 /// \brief The nested-name-specifier that qualifies the name, if any. 2337 NestedNameSpecifierLoc QualifierLoc; 2338 2339 /// The results. These are undesugared, which is to say, they may 2340 /// include UsingShadowDecls. Access is relative to the naming 2341 /// class. 2342 // FIXME: Allocate this data after the OverloadExpr subclass. 2343 DeclAccessPair *Results; 2344 unsigned NumResults; 2345 2346protected: 2347 /// \brief Whether the name includes info for explicit template 2348 /// keyword and arguments. 2349 bool HasTemplateKWAndArgsInfo; 2350 2351 /// \brief Return the optional template keyword and arguments info. 2352 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2353 2354 /// \brief Return the optional template keyword and arguments info. 2355 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2356 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2357 } 2358 2359 OverloadExpr(StmtClass K, ASTContext &C, 2360 NestedNameSpecifierLoc QualifierLoc, 2361 SourceLocation TemplateKWLoc, 2362 const DeclarationNameInfo &NameInfo, 2363 const TemplateArgumentListInfo *TemplateArgs, 2364 UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2365 bool KnownDependent, 2366 bool KnownInstantiationDependent, 2367 bool KnownContainsUnexpandedParameterPack); 2368 2369 OverloadExpr(StmtClass K, EmptyShell Empty) 2370 : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0), 2371 HasTemplateKWAndArgsInfo(false) { } 2372 2373 void initializeResults(ASTContext &C, 2374 UnresolvedSetIterator Begin, 2375 UnresolvedSetIterator End); 2376 2377public: 2378 struct FindResult { 2379 OverloadExpr *Expression; 2380 bool IsAddressOfOperand; 2381 bool HasFormOfMemberPointer; 2382 }; 2383 2384 /// Finds the overloaded expression in the given expression of 2385 /// OverloadTy. 2386 /// 2387 /// \return the expression (which must be there) and true if it has 2388 /// the particular form of a member pointer expression 2389 static FindResult find(Expr *E) { 2390 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 2391 2392 FindResult Result; 2393 2394 E = E->IgnoreParens(); 2395 if (isa<UnaryOperator>(E)) { 2396 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 2397 E = cast<UnaryOperator>(E)->getSubExpr(); 2398 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 2399 2400 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 2401 Result.IsAddressOfOperand = true; 2402 Result.Expression = Ovl; 2403 } else { 2404 Result.HasFormOfMemberPointer = false; 2405 Result.IsAddressOfOperand = false; 2406 Result.Expression = cast<OverloadExpr>(E); 2407 } 2408 2409 return Result; 2410 } 2411 2412 /// \brief Gets the naming class of this lookup, if any. 2413 CXXRecordDecl *getNamingClass() const; 2414 2415 typedef UnresolvedSetImpl::iterator decls_iterator; 2416 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2417 decls_iterator decls_end() const { 2418 return UnresolvedSetIterator(Results + NumResults); 2419 } 2420 2421 /// \brief Gets the number of declarations in the unresolved set. 2422 unsigned getNumDecls() const { return NumResults; } 2423 2424 /// \brief Gets the full name info. 2425 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2426 2427 /// \brief Gets the name looked up. 2428 DeclarationName getName() const { return NameInfo.getName(); } 2429 2430 /// \brief Gets the location of the name. 2431 SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 2432 2433 /// \brief Fetches the nested-name qualifier, if one was given. 2434 NestedNameSpecifier *getQualifier() const { 2435 return QualifierLoc.getNestedNameSpecifier(); 2436 } 2437 2438 /// \brief Fetches the nested-name qualifier with source-location 2439 /// information, if one was given. 2440 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2441 2442 /// \brief Retrieve the location of the template keyword preceding 2443 /// this name, if any. 2444 SourceLocation getTemplateKeywordLoc() const { 2445 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2446 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2447 } 2448 2449 /// \brief Retrieve the location of the left angle bracket starting the 2450 /// explicit template argument list following the name, if any. 2451 SourceLocation getLAngleLoc() const { 2452 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2453 return getTemplateKWAndArgsInfo()->LAngleLoc; 2454 } 2455 2456 /// \brief Retrieve the location of the right angle bracket ending the 2457 /// explicit template argument list following the name, if any. 2458 SourceLocation getRAngleLoc() const { 2459 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2460 return getTemplateKWAndArgsInfo()->RAngleLoc; 2461 } 2462 2463 /// \brief Determines whether the name was preceded by the template keyword. 2464 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2465 2466 /// \brief Determines whether this expression had explicit template arguments. 2467 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2468 2469 // Note that, inconsistently with the explicit-template-argument AST 2470 // nodes, users are *forbidden* from calling these methods on objects 2471 // without explicit template arguments. 2472 2473 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2474 assert(hasExplicitTemplateArgs()); 2475 return *getTemplateKWAndArgsInfo(); 2476 } 2477 2478 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2479 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 2480 } 2481 2482 TemplateArgumentLoc const *getTemplateArgs() const { 2483 return getExplicitTemplateArgs().getTemplateArgs(); 2484 } 2485 2486 unsigned getNumTemplateArgs() const { 2487 return getExplicitTemplateArgs().NumTemplateArgs; 2488 } 2489 2490 /// \brief Copies the template arguments into the given structure. 2491 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2492 getExplicitTemplateArgs().copyInto(List); 2493 } 2494 2495 /// \brief Retrieves the optional explicit template arguments. 2496 /// 2497 /// This points to the same data as getExplicitTemplateArgs(), but 2498 /// returns null if there are no explicit template arguments. 2499 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2500 if (!hasExplicitTemplateArgs()) return 0; 2501 return &getExplicitTemplateArgs(); 2502 } 2503 2504 static bool classof(const Stmt *T) { 2505 return T->getStmtClass() == UnresolvedLookupExprClass || 2506 T->getStmtClass() == UnresolvedMemberExprClass; 2507 } 2508 2509 friend class ASTStmtReader; 2510 friend class ASTStmtWriter; 2511}; 2512 2513/// \brief A reference to a name which we were able to look up during 2514/// parsing but could not resolve to a specific declaration. 2515/// 2516/// This arises in several ways: 2517/// * we might be waiting for argument-dependent lookup 2518/// * the name might resolve to an overloaded function 2519/// and eventually: 2520/// * the lookup might have included a function template 2521/// These never include UnresolvedUsingValueDecls, which are always class 2522/// members and therefore appear only in UnresolvedMemberLookupExprs. 2523class UnresolvedLookupExpr : public OverloadExpr { 2524 /// True if these lookup results should be extended by 2525 /// argument-dependent lookup if this is the operand of a function 2526 /// call. 2527 bool RequiresADL; 2528 2529 /// True if these lookup results are overloaded. This is pretty 2530 /// trivially rederivable if we urgently need to kill this field. 2531 bool Overloaded; 2532 2533 /// The naming class (C++ [class.access.base]p5) of the lookup, if 2534 /// any. This can generally be recalculated from the context chain, 2535 /// but that can be fairly expensive for unqualified lookups. If we 2536 /// want to improve memory use here, this could go in a union 2537 /// against the qualified-lookup bits. 2538 CXXRecordDecl *NamingClass; 2539 2540 UnresolvedLookupExpr(ASTContext &C, 2541 CXXRecordDecl *NamingClass, 2542 NestedNameSpecifierLoc QualifierLoc, 2543 SourceLocation TemplateKWLoc, 2544 const DeclarationNameInfo &NameInfo, 2545 bool RequiresADL, bool Overloaded, 2546 const TemplateArgumentListInfo *TemplateArgs, 2547 UnresolvedSetIterator Begin, UnresolvedSetIterator End) 2548 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2549 NameInfo, TemplateArgs, Begin, End, false, false, false), 2550 RequiresADL(RequiresADL), 2551 Overloaded(Overloaded), NamingClass(NamingClass) 2552 {} 2553 2554 UnresolvedLookupExpr(EmptyShell Empty) 2555 : OverloadExpr(UnresolvedLookupExprClass, Empty), 2556 RequiresADL(false), Overloaded(false), NamingClass(0) 2557 {} 2558 2559 friend class ASTStmtReader; 2560 2561public: 2562 static UnresolvedLookupExpr *Create(ASTContext &C, 2563 CXXRecordDecl *NamingClass, 2564 NestedNameSpecifierLoc QualifierLoc, 2565 const DeclarationNameInfo &NameInfo, 2566 bool ADL, bool Overloaded, 2567 UnresolvedSetIterator Begin, 2568 UnresolvedSetIterator End) { 2569 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2570 SourceLocation(), NameInfo, 2571 ADL, Overloaded, 0, Begin, End); 2572 } 2573 2574 static UnresolvedLookupExpr *Create(ASTContext &C, 2575 CXXRecordDecl *NamingClass, 2576 NestedNameSpecifierLoc QualifierLoc, 2577 SourceLocation TemplateKWLoc, 2578 const DeclarationNameInfo &NameInfo, 2579 bool ADL, 2580 const TemplateArgumentListInfo *Args, 2581 UnresolvedSetIterator Begin, 2582 UnresolvedSetIterator End); 2583 2584 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 2585 bool HasTemplateKWAndArgsInfo, 2586 unsigned NumTemplateArgs); 2587 2588 /// True if this declaration should be extended by 2589 /// argument-dependent lookup. 2590 bool requiresADL() const { return RequiresADL; } 2591 2592 /// True if this lookup is overloaded. 2593 bool isOverloaded() const { return Overloaded; } 2594 2595 /// Gets the 'naming class' (in the sense of C++0x 2596 /// [class.access.base]p5) of the lookup. This is the scope 2597 /// that was looked in to find these results. 2598 CXXRecordDecl *getNamingClass() const { return NamingClass; } 2599 2600 SourceLocation getLocStart() const LLVM_READONLY { 2601 if (NestedNameSpecifierLoc l = getQualifierLoc()) 2602 return l.getBeginLoc(); 2603 return getNameInfo().getLocStart(); 2604 } 2605 SourceLocation getLocEnd() const LLVM_READONLY { 2606 if (hasExplicitTemplateArgs()) 2607 return getRAngleLoc(); 2608 return getNameInfo().getLocEnd(); 2609 } 2610 2611 child_range children() { return child_range(); } 2612 2613 static bool classof(const Stmt *T) { 2614 return T->getStmtClass() == UnresolvedLookupExprClass; 2615 } 2616}; 2617 2618/// \brief A qualified reference to a name whose declaration cannot 2619/// yet be resolved. 2620/// 2621/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2622/// it expresses a reference to a declaration such as 2623/// X<T>::value. The difference, however, is that an 2624/// DependentScopeDeclRefExpr node is used only within C++ templates when 2625/// the qualification (e.g., X<T>::) refers to a dependent type. In 2626/// this case, X<T>::value cannot resolve to a declaration because the 2627/// declaration will differ from on instantiation of X<T> to the 2628/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2629/// qualifier (X<T>::) and the name of the entity being referenced 2630/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2631/// declaration can be found. 2632class DependentScopeDeclRefExpr : public Expr { 2633 /// \brief The nested-name-specifier that qualifies this unresolved 2634 /// declaration name. 2635 NestedNameSpecifierLoc QualifierLoc; 2636 2637 /// The name of the entity we will be referencing. 2638 DeclarationNameInfo NameInfo; 2639 2640 /// \brief Whether the name includes info for explicit template 2641 /// keyword and arguments. 2642 bool HasTemplateKWAndArgsInfo; 2643 2644 /// \brief Return the optional template keyword and arguments info. 2645 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2646 if (!HasTemplateKWAndArgsInfo) return 0; 2647 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2648 } 2649 /// \brief Return the optional template keyword and arguments info. 2650 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2651 return const_cast<DependentScopeDeclRefExpr*>(this) 2652 ->getTemplateKWAndArgsInfo(); 2653 } 2654 2655 DependentScopeDeclRefExpr(QualType T, 2656 NestedNameSpecifierLoc QualifierLoc, 2657 SourceLocation TemplateKWLoc, 2658 const DeclarationNameInfo &NameInfo, 2659 const TemplateArgumentListInfo *Args); 2660 2661public: 2662 static DependentScopeDeclRefExpr *Create(ASTContext &C, 2663 NestedNameSpecifierLoc QualifierLoc, 2664 SourceLocation TemplateKWLoc, 2665 const DeclarationNameInfo &NameInfo, 2666 const TemplateArgumentListInfo *TemplateArgs); 2667 2668 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 2669 bool HasTemplateKWAndArgsInfo, 2670 unsigned NumTemplateArgs); 2671 2672 /// \brief Retrieve the name that this expression refers to. 2673 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2674 2675 /// \brief Retrieve the name that this expression refers to. 2676 DeclarationName getDeclName() const { return NameInfo.getName(); } 2677 2678 /// \brief Retrieve the location of the name within the expression. 2679 SourceLocation getLocation() const { return NameInfo.getLoc(); } 2680 2681 /// \brief Retrieve the nested-name-specifier that qualifies the 2682 /// name, with source location information. 2683 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2684 2685 2686 /// \brief Retrieve the nested-name-specifier that qualifies this 2687 /// declaration. 2688 NestedNameSpecifier *getQualifier() const { 2689 return QualifierLoc.getNestedNameSpecifier(); 2690 } 2691 2692 /// \brief Retrieve the location of the template keyword preceding 2693 /// this name, if any. 2694 SourceLocation getTemplateKeywordLoc() const { 2695 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2696 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2697 } 2698 2699 /// \brief Retrieve the location of the left angle bracket starting the 2700 /// explicit template argument list following the name, if any. 2701 SourceLocation getLAngleLoc() const { 2702 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2703 return getTemplateKWAndArgsInfo()->LAngleLoc; 2704 } 2705 2706 /// \brief Retrieve the location of the right angle bracket ending the 2707 /// explicit template argument list following the name, if any. 2708 SourceLocation getRAngleLoc() const { 2709 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2710 return getTemplateKWAndArgsInfo()->RAngleLoc; 2711 } 2712 2713 /// Determines whether the name was preceded by the template keyword. 2714 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2715 2716 /// Determines whether this lookup had explicit template arguments. 2717 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2718 2719 // Note that, inconsistently with the explicit-template-argument AST 2720 // nodes, users are *forbidden* from calling these methods on objects 2721 // without explicit template arguments. 2722 2723 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2724 assert(hasExplicitTemplateArgs()); 2725 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 2726 } 2727 2728 /// Gets a reference to the explicit template argument list. 2729 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2730 assert(hasExplicitTemplateArgs()); 2731 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2732 } 2733 2734 /// \brief Retrieves the optional explicit template arguments. 2735 /// This points to the same data as getExplicitTemplateArgs(), but 2736 /// returns null if there are no explicit template arguments. 2737 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2738 if (!hasExplicitTemplateArgs()) return 0; 2739 return &getExplicitTemplateArgs(); 2740 } 2741 2742 /// \brief Copies the template arguments (if present) into the given 2743 /// structure. 2744 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2745 getExplicitTemplateArgs().copyInto(List); 2746 } 2747 2748 TemplateArgumentLoc const *getTemplateArgs() const { 2749 return getExplicitTemplateArgs().getTemplateArgs(); 2750 } 2751 2752 unsigned getNumTemplateArgs() const { 2753 return getExplicitTemplateArgs().NumTemplateArgs; 2754 } 2755 2756 SourceLocation getLocStart() const LLVM_READONLY { 2757 return QualifierLoc.getBeginLoc(); 2758 } 2759 SourceLocation getLocEnd() const LLVM_READONLY { 2760 if (hasExplicitTemplateArgs()) 2761 return getRAngleLoc(); 2762 return getLocation(); 2763 } 2764 2765 static bool classof(const Stmt *T) { 2766 return T->getStmtClass() == DependentScopeDeclRefExprClass; 2767 } 2768 2769 child_range children() { return child_range(); } 2770 2771 friend class ASTStmtReader; 2772 friend class ASTStmtWriter; 2773}; 2774 2775/// Represents an expression --- generally a full-expression --- which 2776/// introduces cleanups to be run at the end of the sub-expression's 2777/// evaluation. The most common source of expression-introduced 2778/// cleanups is temporary objects in C++, but several other kinds of 2779/// expressions can create cleanups, including basically every 2780/// call in ARC that returns an Objective-C pointer. 2781/// 2782/// This expression also tracks whether the sub-expression contains a 2783/// potentially-evaluated block literal. The lifetime of a block 2784/// literal is the extent of the enclosing scope. 2785class ExprWithCleanups : public Expr { 2786public: 2787 /// The type of objects that are kept in the cleanup. 2788 /// It's useful to remember the set of blocks; we could also 2789 /// remember the set of temporaries, but there's currently 2790 /// no need. 2791 typedef BlockDecl *CleanupObject; 2792 2793private: 2794 Stmt *SubExpr; 2795 2796 ExprWithCleanups(EmptyShell, unsigned NumObjects); 2797 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 2798 2799 CleanupObject *getObjectsBuffer() { 2800 return reinterpret_cast<CleanupObject*>(this + 1); 2801 } 2802 const CleanupObject *getObjectsBuffer() const { 2803 return reinterpret_cast<const CleanupObject*>(this + 1); 2804 } 2805 friend class ASTStmtReader; 2806 2807public: 2808 static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty, 2809 unsigned numObjects); 2810 2811 static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr, 2812 ArrayRef<CleanupObject> objects); 2813 2814 ArrayRef<CleanupObject> getObjects() const { 2815 return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2816 } 2817 2818 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 2819 2820 CleanupObject getObject(unsigned i) const { 2821 assert(i < getNumObjects() && "Index out of range"); 2822 return getObjects()[i]; 2823 } 2824 2825 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2826 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 2827 2828 /// setSubExpr - As with any mutator of the AST, be very careful 2829 /// when modifying an existing AST to preserve its invariants. 2830 void setSubExpr(Expr *E) { SubExpr = E; } 2831 2832 SourceLocation getLocStart() const LLVM_READONLY { 2833 return SubExpr->getLocStart(); 2834 } 2835 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 2836 2837 // Implement isa/cast/dyncast/etc. 2838 static bool classof(const Stmt *T) { 2839 return T->getStmtClass() == ExprWithCleanupsClass; 2840 } 2841 2842 // Iterators 2843 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 2844}; 2845 2846/// \brief Describes an explicit type conversion that uses functional 2847/// notion but could not be resolved because one or more arguments are 2848/// type-dependent. 2849/// 2850/// The explicit type conversions expressed by 2851/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>, 2852/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and 2853/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is 2854/// type-dependent. For example, this would occur in a template such 2855/// as: 2856/// 2857/// \code 2858/// template<typename T, typename A1> 2859/// inline T make_a(const A1& a1) { 2860/// return T(a1); 2861/// } 2862/// \endcode 2863/// 2864/// When the returned expression is instantiated, it may resolve to a 2865/// constructor call, conversion function call, or some kind of type 2866/// conversion. 2867class CXXUnresolvedConstructExpr : public Expr { 2868 /// \brief The type being constructed. 2869 TypeSourceInfo *Type; 2870 2871 /// \brief The location of the left parentheses ('('). 2872 SourceLocation LParenLoc; 2873 2874 /// \brief The location of the right parentheses (')'). 2875 SourceLocation RParenLoc; 2876 2877 /// \brief The number of arguments used to construct the type. 2878 unsigned NumArgs; 2879 2880 CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 2881 SourceLocation LParenLoc, 2882 ArrayRef<Expr*> Args, 2883 SourceLocation RParenLoc); 2884 2885 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 2886 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 2887 2888 friend class ASTStmtReader; 2889 2890public: 2891 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 2892 TypeSourceInfo *Type, 2893 SourceLocation LParenLoc, 2894 ArrayRef<Expr*> Args, 2895 SourceLocation RParenLoc); 2896 2897 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 2898 unsigned NumArgs); 2899 2900 /// \brief Retrieve the type that is being constructed, as specified 2901 /// in the source code. 2902 QualType getTypeAsWritten() const { return Type->getType(); } 2903 2904 /// \brief Retrieve the type source information for the type being 2905 /// constructed. 2906 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 2907 2908 /// \brief Retrieve the location of the left parentheses ('(') that 2909 /// precedes the argument list. 2910 SourceLocation getLParenLoc() const { return LParenLoc; } 2911 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2912 2913 /// \brief Retrieve the location of the right parentheses (')') that 2914 /// follows the argument list. 2915 SourceLocation getRParenLoc() const { return RParenLoc; } 2916 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2917 2918 /// \brief Retrieve the number of arguments. 2919 unsigned arg_size() const { return NumArgs; } 2920 2921 typedef Expr** arg_iterator; 2922 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2923 arg_iterator arg_end() { return arg_begin() + NumArgs; } 2924 2925 typedef const Expr* const * const_arg_iterator; 2926 const_arg_iterator arg_begin() const { 2927 return reinterpret_cast<const Expr* const *>(this + 1); 2928 } 2929 const_arg_iterator arg_end() const { 2930 return arg_begin() + NumArgs; 2931 } 2932 2933 Expr *getArg(unsigned I) { 2934 assert(I < NumArgs && "Argument index out-of-range"); 2935 return *(arg_begin() + I); 2936 } 2937 2938 const Expr *getArg(unsigned I) const { 2939 assert(I < NumArgs && "Argument index out-of-range"); 2940 return *(arg_begin() + I); 2941 } 2942 2943 void setArg(unsigned I, Expr *E) { 2944 assert(I < NumArgs && "Argument index out-of-range"); 2945 *(arg_begin() + I) = E; 2946 } 2947 2948 SourceLocation getLocStart() const LLVM_READONLY; 2949 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 2950 2951 static bool classof(const Stmt *T) { 2952 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2953 } 2954 2955 // Iterators 2956 child_range children() { 2957 Stmt **begin = reinterpret_cast<Stmt**>(this+1); 2958 return child_range(begin, begin + NumArgs); 2959 } 2960}; 2961 2962/// \brief Represents a C++ member access expression where the actual 2963/// member referenced could not be resolved because the base 2964/// expression or the member name was dependent. 2965/// 2966/// Like UnresolvedMemberExprs, these can be either implicit or 2967/// explicit accesses. It is only possible to get one of these with 2968/// an implicit access if a qualifier is provided. 2969class CXXDependentScopeMemberExpr : public Expr { 2970 /// \brief The expression for the base pointer or class reference, 2971 /// e.g., the \c x in x.f. Can be null in implicit accesses. 2972 Stmt *Base; 2973 2974 /// \brief The type of the base expression. Never null, even for 2975 /// implicit accesses. 2976 QualType BaseType; 2977 2978 /// \brief Whether this member expression used the '->' operator or 2979 /// the '.' operator. 2980 bool IsArrow : 1; 2981 2982 /// \brief Whether this member expression has info for explicit template 2983 /// keyword and arguments. 2984 bool HasTemplateKWAndArgsInfo : 1; 2985 2986 /// \brief The location of the '->' or '.' operator. 2987 SourceLocation OperatorLoc; 2988 2989 /// \brief The nested-name-specifier that precedes the member name, if any. 2990 NestedNameSpecifierLoc QualifierLoc; 2991 2992 /// \brief In a qualified member access expression such as t->Base::f, this 2993 /// member stores the resolves of name lookup in the context of the member 2994 /// access expression, to be used at instantiation time. 2995 /// 2996 /// FIXME: This member, along with the QualifierLoc, could 2997 /// be stuck into a structure that is optionally allocated at the end of 2998 /// the CXXDependentScopeMemberExpr, to save space in the common case. 2999 NamedDecl *FirstQualifierFoundInScope; 3000 3001 /// \brief The member to which this member expression refers, which 3002 /// can be name, overloaded operator, or destructor. 3003 /// FIXME: could also be a template-id 3004 DeclarationNameInfo MemberNameInfo; 3005 3006 /// \brief Return the optional template keyword and arguments info. 3007 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 3008 if (!HasTemplateKWAndArgsInfo) return 0; 3009 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 3010 } 3011 /// \brief Return the optional template keyword and arguments info. 3012 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 3013 return const_cast<CXXDependentScopeMemberExpr*>(this) 3014 ->getTemplateKWAndArgsInfo(); 3015 } 3016 3017 CXXDependentScopeMemberExpr(ASTContext &C, 3018 Expr *Base, QualType BaseType, bool IsArrow, 3019 SourceLocation OperatorLoc, 3020 NestedNameSpecifierLoc QualifierLoc, 3021 SourceLocation TemplateKWLoc, 3022 NamedDecl *FirstQualifierFoundInScope, 3023 DeclarationNameInfo MemberNameInfo, 3024 const TemplateArgumentListInfo *TemplateArgs); 3025 3026public: 3027 CXXDependentScopeMemberExpr(ASTContext &C, 3028 Expr *Base, QualType BaseType, 3029 bool IsArrow, 3030 SourceLocation OperatorLoc, 3031 NestedNameSpecifierLoc QualifierLoc, 3032 NamedDecl *FirstQualifierFoundInScope, 3033 DeclarationNameInfo MemberNameInfo); 3034 3035 static CXXDependentScopeMemberExpr * 3036 Create(ASTContext &C, 3037 Expr *Base, QualType BaseType, bool IsArrow, 3038 SourceLocation OperatorLoc, 3039 NestedNameSpecifierLoc QualifierLoc, 3040 SourceLocation TemplateKWLoc, 3041 NamedDecl *FirstQualifierFoundInScope, 3042 DeclarationNameInfo MemberNameInfo, 3043 const TemplateArgumentListInfo *TemplateArgs); 3044 3045 static CXXDependentScopeMemberExpr * 3046 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3047 unsigned NumTemplateArgs); 3048 3049 /// \brief True if this is an implicit access, i.e. one in which the 3050 /// member being accessed was not written in the source. The source 3051 /// location of the operator is invalid in this case. 3052 bool isImplicitAccess() const; 3053 3054 /// \brief Retrieve the base object of this member expressions, 3055 /// e.g., the \c x in \c x.m. 3056 Expr *getBase() const { 3057 assert(!isImplicitAccess()); 3058 return cast<Expr>(Base); 3059 } 3060 3061 QualType getBaseType() const { return BaseType; } 3062 3063 /// \brief Determine whether this member expression used the '->' 3064 /// operator; otherwise, it used the '.' operator. 3065 bool isArrow() const { return IsArrow; } 3066 3067 /// \brief Retrieve the location of the '->' or '.' operator. 3068 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3069 3070 /// \brief Retrieve the nested-name-specifier that qualifies the member 3071 /// name. 3072 NestedNameSpecifier *getQualifier() const { 3073 return QualifierLoc.getNestedNameSpecifier(); 3074 } 3075 3076 /// \brief Retrieve the nested-name-specifier that qualifies the member 3077 /// name, with source location information. 3078 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 3079 3080 3081 /// \brief Retrieve the first part of the nested-name-specifier that was 3082 /// found in the scope of the member access expression when the member access 3083 /// was initially parsed. 3084 /// 3085 /// This function only returns a useful result when member access expression 3086 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 3087 /// returned by this function describes what was found by unqualified name 3088 /// lookup for the identifier "Base" within the scope of the member access 3089 /// expression itself. At template instantiation time, this information is 3090 /// combined with the results of name lookup into the type of the object 3091 /// expression itself (the class type of x). 3092 NamedDecl *getFirstQualifierFoundInScope() const { 3093 return FirstQualifierFoundInScope; 3094 } 3095 3096 /// \brief Retrieve the name of the member that this expression 3097 /// refers to. 3098 const DeclarationNameInfo &getMemberNameInfo() const { 3099 return MemberNameInfo; 3100 } 3101 3102 /// \brief Retrieve the name of the member that this expression 3103 /// refers to. 3104 DeclarationName getMember() const { return MemberNameInfo.getName(); } 3105 3106 // \brief Retrieve the location of the name of the member that this 3107 // expression refers to. 3108 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 3109 3110 /// \brief Retrieve the location of the template keyword preceding the 3111 /// member name, if any. 3112 SourceLocation getTemplateKeywordLoc() const { 3113 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3114 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 3115 } 3116 3117 /// \brief Retrieve the location of the left angle bracket starting the 3118 /// explicit template argument list following the member name, if any. 3119 SourceLocation getLAngleLoc() const { 3120 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3121 return getTemplateKWAndArgsInfo()->LAngleLoc; 3122 } 3123 3124 /// \brief Retrieve the location of the right angle bracket ending the 3125 /// explicit template argument list following the member name, if any. 3126 SourceLocation getRAngleLoc() const { 3127 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3128 return getTemplateKWAndArgsInfo()->RAngleLoc; 3129 } 3130 3131 /// Determines whether the member name was preceded by the template keyword. 3132 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 3133 3134 /// \brief Determines whether this member expression actually had a C++ 3135 /// template argument list explicitly specified, e.g., x.f<int>. 3136 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 3137 3138 /// \brief Retrieve the explicit template argument list that followed the 3139 /// member template name, if any. 3140 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 3141 assert(hasExplicitTemplateArgs()); 3142 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 3143 } 3144 3145 /// \brief Retrieve the explicit template argument list that followed the 3146 /// member template name, if any. 3147 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 3148 return const_cast<CXXDependentScopeMemberExpr *>(this) 3149 ->getExplicitTemplateArgs(); 3150 } 3151 3152 /// \brief Retrieves the optional explicit template arguments. 3153 /// This points to the same data as getExplicitTemplateArgs(), but 3154 /// returns null if there are no explicit template arguments. 3155 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 3156 if (!hasExplicitTemplateArgs()) return 0; 3157 return &getExplicitTemplateArgs(); 3158 } 3159 3160 /// \brief Copies the template arguments (if present) into the given 3161 /// structure. 3162 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 3163 getExplicitTemplateArgs().copyInto(List); 3164 } 3165 3166 /// \brief Initializes the template arguments using the given structure. 3167 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 3168 getExplicitTemplateArgs().initializeFrom(List); 3169 } 3170 3171 /// \brief Retrieve the template arguments provided as part of this 3172 /// template-id. 3173 const TemplateArgumentLoc *getTemplateArgs() const { 3174 return getExplicitTemplateArgs().getTemplateArgs(); 3175 } 3176 3177 /// \brief Retrieve the number of template arguments provided as part of this 3178 /// template-id. 3179 unsigned getNumTemplateArgs() const { 3180 return getExplicitTemplateArgs().NumTemplateArgs; 3181 } 3182 3183 SourceLocation getLocStart() const LLVM_READONLY { 3184 if (!isImplicitAccess()) 3185 return Base->getLocStart(); 3186 if (getQualifier()) 3187 return getQualifierLoc().getBeginLoc(); 3188 return MemberNameInfo.getBeginLoc(); 3189 3190 } 3191 SourceLocation getLocEnd() const LLVM_READONLY { 3192 if (hasExplicitTemplateArgs()) 3193 return getRAngleLoc(); 3194 return MemberNameInfo.getEndLoc(); 3195 } 3196 3197 static bool classof(const Stmt *T) { 3198 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 3199 } 3200 3201 // Iterators 3202 child_range children() { 3203 if (isImplicitAccess()) return child_range(); 3204 return child_range(&Base, &Base + 1); 3205 } 3206 3207 friend class ASTStmtReader; 3208 friend class ASTStmtWriter; 3209}; 3210 3211/// \brief Represents a C++ member access expression for which lookup 3212/// produced a set of overloaded functions. 3213/// 3214/// The member access may be explicit or implicit: 3215/// struct A { 3216/// int a, b; 3217/// int explicitAccess() { return this->a + this->A::b; } 3218/// int implicitAccess() { return a + A::b; } 3219/// }; 3220/// 3221/// In the final AST, an explicit access always becomes a MemberExpr. 3222/// An implicit access may become either a MemberExpr or a 3223/// DeclRefExpr, depending on whether the member is static. 3224class UnresolvedMemberExpr : public OverloadExpr { 3225 /// \brief Whether this member expression used the '->' operator or 3226 /// the '.' operator. 3227 bool IsArrow : 1; 3228 3229 /// \brief Whether the lookup results contain an unresolved using 3230 /// declaration. 3231 bool HasUnresolvedUsing : 1; 3232 3233 /// \brief The expression for the base pointer or class reference, 3234 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 3235 /// member expression 3236 Stmt *Base; 3237 3238 /// \brief The type of the base expression; never null. 3239 QualType BaseType; 3240 3241 /// \brief The location of the '->' or '.' operator. 3242 SourceLocation OperatorLoc; 3243 3244 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 3245 Expr *Base, QualType BaseType, bool IsArrow, 3246 SourceLocation OperatorLoc, 3247 NestedNameSpecifierLoc QualifierLoc, 3248 SourceLocation TemplateKWLoc, 3249 const DeclarationNameInfo &MemberNameInfo, 3250 const TemplateArgumentListInfo *TemplateArgs, 3251 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3252 3253 UnresolvedMemberExpr(EmptyShell Empty) 3254 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 3255 HasUnresolvedUsing(false), Base(0) { } 3256 3257 friend class ASTStmtReader; 3258 3259public: 3260 static UnresolvedMemberExpr * 3261 Create(ASTContext &C, bool HasUnresolvedUsing, 3262 Expr *Base, QualType BaseType, bool IsArrow, 3263 SourceLocation OperatorLoc, 3264 NestedNameSpecifierLoc QualifierLoc, 3265 SourceLocation TemplateKWLoc, 3266 const DeclarationNameInfo &MemberNameInfo, 3267 const TemplateArgumentListInfo *TemplateArgs, 3268 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3269 3270 static UnresolvedMemberExpr * 3271 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3272 unsigned NumTemplateArgs); 3273 3274 /// \brief True if this is an implicit access, i.e. one in which the 3275 /// member being accessed was not written in the source. The source 3276 /// location of the operator is invalid in this case. 3277 bool isImplicitAccess() const; 3278 3279 /// \brief Retrieve the base object of this member expressions, 3280 /// e.g., the \c x in \c x.m. 3281 Expr *getBase() { 3282 assert(!isImplicitAccess()); 3283 return cast<Expr>(Base); 3284 } 3285 const Expr *getBase() const { 3286 assert(!isImplicitAccess()); 3287 return cast<Expr>(Base); 3288 } 3289 3290 QualType getBaseType() const { return BaseType; } 3291 3292 /// \brief Determine whether the lookup results contain an unresolved using 3293 /// declaration. 3294 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3295 3296 /// \brief Determine whether this member expression used the '->' 3297 /// operator; otherwise, it used the '.' operator. 3298 bool isArrow() const { return IsArrow; } 3299 3300 /// \brief Retrieve the location of the '->' or '.' operator. 3301 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3302 3303 /// \brief Retrieves the naming class of this lookup. 3304 CXXRecordDecl *getNamingClass() const; 3305 3306 /// \brief Retrieve the full name info for the member that this expression 3307 /// refers to. 3308 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 3309 3310 /// \brief Retrieve the name of the member that this expression 3311 /// refers to. 3312 DeclarationName getMemberName() const { return getName(); } 3313 3314 // \brief Retrieve the location of the name of the member that this 3315 // expression refers to. 3316 SourceLocation getMemberLoc() const { return getNameLoc(); } 3317 3318 SourceLocation getLocStart() const LLVM_READONLY { 3319 if (!isImplicitAccess()) 3320 return Base->getLocStart(); 3321 if (NestedNameSpecifierLoc l = getQualifierLoc()) 3322 return l.getBeginLoc(); 3323 return getMemberNameInfo().getLocStart(); 3324 } 3325 SourceLocation getLocEnd() const LLVM_READONLY { 3326 if (hasExplicitTemplateArgs()) 3327 return getRAngleLoc(); 3328 return getMemberNameInfo().getLocEnd(); 3329 } 3330 3331 static bool classof(const Stmt *T) { 3332 return T->getStmtClass() == UnresolvedMemberExprClass; 3333 } 3334 3335 // Iterators 3336 child_range children() { 3337 if (isImplicitAccess()) return child_range(); 3338 return child_range(&Base, &Base + 1); 3339 } 3340}; 3341 3342/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 3343/// 3344/// The noexcept expression tests whether a given expression might throw. Its 3345/// result is a boolean constant. 3346class CXXNoexceptExpr : public Expr { 3347 bool Value : 1; 3348 Stmt *Operand; 3349 SourceRange Range; 3350 3351 friend class ASTStmtReader; 3352 3353public: 3354 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 3355 SourceLocation Keyword, SourceLocation RParen) 3356 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3357 /*TypeDependent*/false, 3358 /*ValueDependent*/Val == CT_Dependent, 3359 Val == CT_Dependent || Operand->isInstantiationDependent(), 3360 Operand->containsUnexpandedParameterPack()), 3361 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 3362 { } 3363 3364 CXXNoexceptExpr(EmptyShell Empty) 3365 : Expr(CXXNoexceptExprClass, Empty) 3366 { } 3367 3368 Expr *getOperand() const { return static_cast<Expr*>(Operand); } 3369 3370 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 3371 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 3372 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 3373 3374 bool getValue() const { return Value; } 3375 3376 static bool classof(const Stmt *T) { 3377 return T->getStmtClass() == CXXNoexceptExprClass; 3378 } 3379 3380 // Iterators 3381 child_range children() { return child_range(&Operand, &Operand + 1); } 3382}; 3383 3384/// \brief Represents a C++0x pack expansion that produces a sequence of 3385/// expressions. 3386/// 3387/// A pack expansion expression contains a pattern (which itself is an 3388/// expression) followed by an ellipsis. For example: 3389/// 3390/// \code 3391/// template<typename F, typename ...Types> 3392/// void forward(F f, Types &&...args) { 3393/// f(static_cast<Types&&>(args)...); 3394/// } 3395/// \endcode 3396/// 3397/// Here, the argument to the function object \c f is a pack expansion whose 3398/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3399/// template is instantiated, the pack expansion will instantiate to zero or 3400/// or more function arguments to the function object \c f. 3401class PackExpansionExpr : public Expr { 3402 SourceLocation EllipsisLoc; 3403 3404 /// \brief The number of expansions that will be produced by this pack 3405 /// expansion expression, if known. 3406 /// 3407 /// When zero, the number of expansions is not known. Otherwise, this value 3408 /// is the number of expansions + 1. 3409 unsigned NumExpansions; 3410 3411 Stmt *Pattern; 3412 3413 friend class ASTStmtReader; 3414 friend class ASTStmtWriter; 3415 3416public: 3417 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 3418 Optional<unsigned> NumExpansions) 3419 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3420 Pattern->getObjectKind(), /*TypeDependent=*/true, 3421 /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3422 /*ContainsUnexpandedParameterPack=*/false), 3423 EllipsisLoc(EllipsisLoc), 3424 NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3425 Pattern(Pattern) { } 3426 3427 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3428 3429 /// \brief Retrieve the pattern of the pack expansion. 3430 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3431 3432 /// \brief Retrieve the pattern of the pack expansion. 3433 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3434 3435 /// \brief Retrieve the location of the ellipsis that describes this pack 3436 /// expansion. 3437 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3438 3439 /// \brief Determine the number of expansions that will be produced when 3440 /// this pack expansion is instantiated, if already known. 3441 Optional<unsigned> getNumExpansions() const { 3442 if (NumExpansions) 3443 return NumExpansions - 1; 3444 3445 return None; 3446 } 3447 3448 SourceLocation getLocStart() const LLVM_READONLY { 3449 return Pattern->getLocStart(); 3450 } 3451 SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; } 3452 3453 static bool classof(const Stmt *T) { 3454 return T->getStmtClass() == PackExpansionExprClass; 3455 } 3456 3457 // Iterators 3458 child_range children() { 3459 return child_range(&Pattern, &Pattern + 1); 3460 } 3461}; 3462 3463inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3464 if (!HasTemplateKWAndArgsInfo) return 0; 3465 if (isa<UnresolvedLookupExpr>(this)) 3466 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3467 (cast<UnresolvedLookupExpr>(this) + 1); 3468 else 3469 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3470 (cast<UnresolvedMemberExpr>(this) + 1); 3471} 3472 3473/// \brief Represents an expression that computes the length of a parameter 3474/// pack. 3475/// 3476/// \code 3477/// template<typename ...Types> 3478/// struct count { 3479/// static const unsigned value = sizeof...(Types); 3480/// }; 3481/// \endcode 3482class SizeOfPackExpr : public Expr { 3483 /// \brief The location of the 'sizeof' keyword. 3484 SourceLocation OperatorLoc; 3485 3486 /// \brief The location of the name of the parameter pack. 3487 SourceLocation PackLoc; 3488 3489 /// \brief The location of the closing parenthesis. 3490 SourceLocation RParenLoc; 3491 3492 /// \brief The length of the parameter pack, if known. 3493 /// 3494 /// When this expression is value-dependent, the length of the parameter pack 3495 /// is unknown. When this expression is not value-dependent, the length is 3496 /// known. 3497 unsigned Length; 3498 3499 /// \brief The parameter pack itself. 3500 NamedDecl *Pack; 3501 3502 friend class ASTStmtReader; 3503 friend class ASTStmtWriter; 3504 3505public: 3506 /// \brief Creates a value-dependent expression that computes the length of 3507 /// the given parameter pack. 3508 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3509 SourceLocation PackLoc, SourceLocation RParenLoc) 3510 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3511 /*TypeDependent=*/false, /*ValueDependent=*/true, 3512 /*InstantiationDependent=*/true, 3513 /*ContainsUnexpandedParameterPack=*/false), 3514 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3515 Length(0), Pack(Pack) { } 3516 3517 /// \brief Creates an expression that computes the length of 3518 /// the given parameter pack, which is already known. 3519 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3520 SourceLocation PackLoc, SourceLocation RParenLoc, 3521 unsigned Length) 3522 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3523 /*TypeDependent=*/false, /*ValueDependent=*/false, 3524 /*InstantiationDependent=*/false, 3525 /*ContainsUnexpandedParameterPack=*/false), 3526 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3527 Length(Length), Pack(Pack) { } 3528 3529 /// \brief Create an empty expression. 3530 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3531 3532 /// \brief Determine the location of the 'sizeof' keyword. 3533 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3534 3535 /// \brief Determine the location of the parameter pack. 3536 SourceLocation getPackLoc() const { return PackLoc; } 3537 3538 /// \brief Determine the location of the right parenthesis. 3539 SourceLocation getRParenLoc() const { return RParenLoc; } 3540 3541 /// \brief Retrieve the parameter pack. 3542 NamedDecl *getPack() const { return Pack; } 3543 3544 /// \brief Retrieve the length of the parameter pack. 3545 /// 3546 /// This routine may only be invoked when the expression is not 3547 /// value-dependent. 3548 unsigned getPackLength() const { 3549 assert(!isValueDependent() && 3550 "Cannot get the length of a value-dependent pack size expression"); 3551 return Length; 3552 } 3553 3554 SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; } 3555 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 3556 3557 static bool classof(const Stmt *T) { 3558 return T->getStmtClass() == SizeOfPackExprClass; 3559 } 3560 3561 // Iterators 3562 child_range children() { return child_range(); } 3563}; 3564 3565/// \brief Represents a reference to a non-type template parameter 3566/// that has been substituted with a template argument. 3567class SubstNonTypeTemplateParmExpr : public Expr { 3568 /// \brief The replaced parameter. 3569 NonTypeTemplateParmDecl *Param; 3570 3571 /// \brief The replacement expression. 3572 Stmt *Replacement; 3573 3574 /// \brief The location of the non-type template parameter reference. 3575 SourceLocation NameLoc; 3576 3577 friend class ASTReader; 3578 friend class ASTStmtReader; 3579 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 3580 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 3581 3582public: 3583 SubstNonTypeTemplateParmExpr(QualType type, 3584 ExprValueKind valueKind, 3585 SourceLocation loc, 3586 NonTypeTemplateParmDecl *param, 3587 Expr *replacement) 3588 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 3589 replacement->isTypeDependent(), replacement->isValueDependent(), 3590 replacement->isInstantiationDependent(), 3591 replacement->containsUnexpandedParameterPack()), 3592 Param(param), Replacement(replacement), NameLoc(loc) {} 3593 3594 SourceLocation getNameLoc() const { return NameLoc; } 3595 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3596 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3597 3598 Expr *getReplacement() const { return cast<Expr>(Replacement); } 3599 3600 NonTypeTemplateParmDecl *getParameter() const { return Param; } 3601 3602 static bool classof(const Stmt *s) { 3603 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 3604 } 3605 3606 // Iterators 3607 child_range children() { return child_range(&Replacement, &Replacement+1); } 3608}; 3609 3610/// \brief Represents a reference to a non-type template parameter pack that 3611/// has been substituted with a non-template argument pack. 3612/// 3613/// When a pack expansion in the source code contains multiple parameter packs 3614/// and those parameter packs correspond to different levels of template 3615/// parameter lists, this node is used to represent a non-type template 3616/// parameter pack from an outer level, which has already had its argument pack 3617/// substituted but that still lives within a pack expansion that itself 3618/// could not be instantiated. When actually performing a substitution into 3619/// that pack expansion (e.g., when all template parameters have corresponding 3620/// arguments), this type will be replaced with the appropriate underlying 3621/// expression at the current pack substitution index. 3622class SubstNonTypeTemplateParmPackExpr : public Expr { 3623 /// \brief The non-type template parameter pack itself. 3624 NonTypeTemplateParmDecl *Param; 3625 3626 /// \brief A pointer to the set of template arguments that this 3627 /// parameter pack is instantiated with. 3628 const TemplateArgument *Arguments; 3629 3630 /// \brief The number of template arguments in \c Arguments. 3631 unsigned NumArguments; 3632 3633 /// \brief The location of the non-type template parameter pack reference. 3634 SourceLocation NameLoc; 3635 3636 friend class ASTReader; 3637 friend class ASTStmtReader; 3638 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 3639 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3640 3641public: 3642 SubstNonTypeTemplateParmPackExpr(QualType T, 3643 NonTypeTemplateParmDecl *Param, 3644 SourceLocation NameLoc, 3645 const TemplateArgument &ArgPack); 3646 3647 /// \brief Retrieve the non-type template parameter pack being substituted. 3648 NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3649 3650 /// \brief Retrieve the location of the parameter pack name. 3651 SourceLocation getParameterPackLocation() const { return NameLoc; } 3652 3653 /// \brief Retrieve the template argument pack containing the substituted 3654 /// template arguments. 3655 TemplateArgument getArgumentPack() const; 3656 3657 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3658 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3659 3660 static bool classof(const Stmt *T) { 3661 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3662 } 3663 3664 // Iterators 3665 child_range children() { return child_range(); } 3666}; 3667 3668/// \brief Represents a reference to a function parameter pack that has been 3669/// substituted but not yet expanded. 3670/// 3671/// When a pack expansion contains multiple parameter packs at different levels, 3672/// this node is used to represent a function parameter pack at an outer level 3673/// which we have already substituted to refer to expanded parameters, but where 3674/// the containing pack expansion cannot yet be expanded. 3675/// 3676/// \code 3677/// template<typename...Ts> struct S { 3678/// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...)); 3679/// }; 3680/// template struct S<int, int>; 3681/// \endcode 3682class FunctionParmPackExpr : public Expr { 3683 /// \brief The function parameter pack which was referenced. 3684 ParmVarDecl *ParamPack; 3685 3686 /// \brief The location of the function parameter pack reference. 3687 SourceLocation NameLoc; 3688 3689 /// \brief The number of expansions of this pack. 3690 unsigned NumParameters; 3691 3692 FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, 3693 SourceLocation NameLoc, unsigned NumParams, 3694 Decl * const *Params); 3695 3696 friend class ASTReader; 3697 friend class ASTStmtReader; 3698 3699public: 3700 static FunctionParmPackExpr *Create(ASTContext &Context, QualType T, 3701 ParmVarDecl *ParamPack, 3702 SourceLocation NameLoc, 3703 ArrayRef<Decl *> Params); 3704 static FunctionParmPackExpr *CreateEmpty(ASTContext &Context, 3705 unsigned NumParams); 3706 3707 /// \brief Get the parameter pack which this expression refers to. 3708 ParmVarDecl *getParameterPack() const { return ParamPack; } 3709 3710 /// \brief Get the location of the parameter pack. 3711 SourceLocation getParameterPackLocation() const { return NameLoc; } 3712 3713 /// \brief Iterators over the parameters which the parameter pack expanded 3714 /// into. 3715 typedef ParmVarDecl * const *iterator; 3716 iterator begin() const { return reinterpret_cast<iterator>(this+1); } 3717 iterator end() const { return begin() + NumParameters; } 3718 3719 /// \brief Get the number of parameters in this parameter pack. 3720 unsigned getNumExpansions() const { return NumParameters; } 3721 3722 /// \brief Get an expansion of the parameter pack by index. 3723 ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; } 3724 3725 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3726 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3727 3728 static bool classof(const Stmt *T) { 3729 return T->getStmtClass() == FunctionParmPackExprClass; 3730 } 3731 3732 child_range children() { return child_range(); } 3733}; 3734 3735/// \brief Represents a prvalue temporary that written into memory so that 3736/// a reference can bind to it. 3737/// 3738/// Prvalue expressions are materialized when they need to have an address 3739/// in memory for a reference to bind to. This happens when binding a 3740/// reference to the result of a conversion, e.g., 3741/// 3742/// \code 3743/// const int &r = 1.0; 3744/// \endcode 3745/// 3746/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 3747/// then materialized via a \c MaterializeTemporaryExpr, and the reference 3748/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 3749/// (either an lvalue or an xvalue, depending on the kind of reference binding 3750/// to it), maintaining the invariant that references always bind to glvalues. 3751class MaterializeTemporaryExpr : public Expr { 3752 /// \brief The temporary-generating expression whose value will be 3753 /// materialized. 3754 Stmt *Temporary; 3755 3756 friend class ASTStmtReader; 3757 friend class ASTStmtWriter; 3758 3759public: 3760 MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3761 bool BoundToLvalueReference) 3762 : Expr(MaterializeTemporaryExprClass, T, 3763 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 3764 Temporary->isTypeDependent(), Temporary->isValueDependent(), 3765 Temporary->isInstantiationDependent(), 3766 Temporary->containsUnexpandedParameterPack()), 3767 Temporary(Temporary) { } 3768 3769 MaterializeTemporaryExpr(EmptyShell Empty) 3770 : Expr(MaterializeTemporaryExprClass, Empty) { } 3771 3772 /// \brief Retrieve the temporary-generating subexpression whose value will 3773 /// be materialized into a glvalue. 3774 Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); } 3775 3776 /// \brief Determine whether this materialized temporary is bound to an 3777 /// lvalue reference; otherwise, it's bound to an rvalue reference. 3778 bool isBoundToLvalueReference() const { 3779 return getValueKind() == VK_LValue; 3780 } 3781 3782 SourceLocation getLocStart() const LLVM_READONLY { 3783 return Temporary->getLocStart(); 3784 } 3785 SourceLocation getLocEnd() const LLVM_READONLY { 3786 return Temporary->getLocEnd(); 3787 } 3788 3789 static bool classof(const Stmt *T) { 3790 return T->getStmtClass() == MaterializeTemporaryExprClass; 3791 } 3792 3793 // Iterators 3794 child_range children() { return child_range(&Temporary, &Temporary + 1); } 3795}; 3796 3797} // end namespace clang 3798 3799#endif 3800