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