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