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