ExprCXX.h revision f68af647dda5cca00b49be27d24f62b0a7fff986
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(ASTContext &Context, QualType T, 244 ExprValueKind VK, CastKind K, Expr *Op, 245 const CXXCastPath *Path, 246 TypeSourceInfo *Written, SourceLocation L, 247 SourceLocation RParenLoc, 248 SourceRange AngleBrackets); 249 static CXXStaticCastExpr *CreateEmpty(ASTContext &Context, 250 unsigned PathSize); 251 252 static bool classof(const Stmt *T) { 253 return T->getStmtClass() == CXXStaticCastExprClass; 254 } 255}; 256 257/// \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(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(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(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(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(ASTContext &Context, QualType T, 345 ExprValueKind VK, Expr *Op, 346 TypeSourceInfo *WrittenTy, SourceLocation L, 347 SourceLocation RParenLoc, 348 SourceRange AngleBrackets); 349 static CXXConstCastExpr *CreateEmpty(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(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(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 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 728 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 729 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 730 void setSourceRange(SourceRange R) { Range = R; } 731 732 static bool classof(const Stmt *T) { 733 return T->getStmtClass() == CXXUuidofExprClass; 734 } 735 736 /// Grabs __declspec(uuid()) off a type, or returns 0 if there is none. 737 static UuidAttr *GetUuidAttrOfType(QualType QT); 738 739 // Iterators 740 child_range children() { 741 if (isTypeOperand()) return child_range(); 742 Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 743 return child_range(begin, begin + 1); 744 } 745}; 746 747/// \brief Represents the \c this expression in C++. 748/// 749/// This is a pointer to the object on which the current member function is 750/// executing (C++ [expr.prim]p3). Example: 751/// 752/// \code 753/// class Foo { 754/// public: 755/// void bar(); 756/// void test() { this->bar(); } 757/// }; 758/// \endcode 759class CXXThisExpr : public Expr { 760 SourceLocation Loc; 761 bool Implicit : 1; 762 763public: 764 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 765 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, 766 // 'this' is type-dependent if the class type of the enclosing 767 // member function is dependent (C++ [temp.dep.expr]p2) 768 Type->isDependentType(), Type->isDependentType(), 769 Type->isInstantiationDependentType(), 770 /*ContainsUnexpandedParameterPack=*/false), 771 Loc(L), Implicit(isImplicit) { } 772 773 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} 774 775 SourceLocation getLocation() const { return Loc; } 776 void setLocation(SourceLocation L) { Loc = L; } 777 778 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 779 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 780 781 bool isImplicit() const { return Implicit; } 782 void setImplicit(bool I) { Implicit = I; } 783 784 static bool classof(const Stmt *T) { 785 return T->getStmtClass() == CXXThisExprClass; 786 } 787 788 // Iterators 789 child_range children() { return child_range(); } 790}; 791 792/// \brief A C++ throw-expression (C++ [except.throw]). 793/// 794/// This handles 'throw' (for re-throwing the current exception) and 795/// 'throw' assignment-expression. When assignment-expression isn't 796/// present, Op will be null. 797class CXXThrowExpr : public Expr { 798 Stmt *Op; 799 SourceLocation ThrowLoc; 800 /// \brief Whether the thrown variable (if any) is in scope. 801 unsigned IsThrownVariableInScope : 1; 802 803 friend class ASTStmtReader; 804 805public: 806 // \p Ty is the void type which is used as the result type of the 807 // expression. The \p l is the location of the throw keyword. \p expr 808 // can by null, if the optional expression to throw isn't present. 809 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l, 810 bool IsThrownVariableInScope) : 811 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 812 expr && expr->isInstantiationDependent(), 813 expr && expr->containsUnexpandedParameterPack()), 814 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {} 815 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} 816 817 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 818 Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 819 820 SourceLocation getThrowLoc() const { return ThrowLoc; } 821 822 /// \brief Determines whether the variable thrown by this expression (if any!) 823 /// is within the innermost try block. 824 /// 825 /// This information is required to determine whether the NRVO can apply to 826 /// this variable. 827 bool isThrownVariableInScope() const { return IsThrownVariableInScope; } 828 829 SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; } 830 SourceLocation getLocEnd() const LLVM_READONLY { 831 if (getSubExpr() == 0) 832 return ThrowLoc; 833 return getSubExpr()->getLocEnd(); 834 } 835 836 static bool classof(const Stmt *T) { 837 return T->getStmtClass() == CXXThrowExprClass; 838 } 839 840 // Iterators 841 child_range children() { 842 return child_range(&Op, Op ? &Op+1 : &Op); 843 } 844}; 845 846/// \brief A default argument (C++ [dcl.fct.default]). 847/// 848/// This wraps up a function call argument that was created from the 849/// corresponding parameter's default argument, when the call did not 850/// explicitly supply arguments for all of the parameters. 851class CXXDefaultArgExpr : public Expr { 852 /// \brief The parameter whose default is being used. 853 /// 854 /// When the bit is set, the subexpression is stored after the 855 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 856 /// actual default expression is the subexpression. 857 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 858 859 /// \brief The location where the default argument expression was used. 860 SourceLocation Loc; 861 862 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 863 : Expr(SC, 864 param->hasUnparsedDefaultArg() 865 ? param->getType().getNonReferenceType() 866 : param->getDefaultArg()->getType(), 867 param->getDefaultArg()->getValueKind(), 868 param->getDefaultArg()->getObjectKind(), false, false, false, false), 869 Param(param, false), Loc(Loc) { } 870 871 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 872 Expr *SubExpr) 873 : Expr(SC, SubExpr->getType(), 874 SubExpr->getValueKind(), SubExpr->getObjectKind(), 875 false, false, false, false), 876 Param(param, true), Loc(Loc) { 877 *reinterpret_cast<Expr **>(this + 1) = SubExpr; 878 } 879 880public: 881 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} 882 883 // \p Param is the parameter whose default argument is used by this 884 // expression. 885 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc, 886 ParmVarDecl *Param) { 887 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 888 } 889 890 // \p Param is the parameter whose default argument is used by this 891 // expression, and \p SubExpr is the expression that will actually be used. 892 static CXXDefaultArgExpr *Create(ASTContext &C, 893 SourceLocation Loc, 894 ParmVarDecl *Param, 895 Expr *SubExpr); 896 897 // Retrieve the parameter that the argument was created from. 898 const ParmVarDecl *getParam() const { return Param.getPointer(); } 899 ParmVarDecl *getParam() { return Param.getPointer(); } 900 901 // Retrieve the actual argument to the function call. 902 const Expr *getExpr() const { 903 if (Param.getInt()) 904 return *reinterpret_cast<Expr const * const*> (this + 1); 905 return getParam()->getDefaultArg(); 906 } 907 Expr *getExpr() { 908 if (Param.getInt()) 909 return *reinterpret_cast<Expr **> (this + 1); 910 return getParam()->getDefaultArg(); 911 } 912 913 /// \brief Retrieve the location where this default argument was actually 914 /// used. 915 SourceLocation getUsedLocation() const { return Loc; } 916 917 /// Default argument expressions have no representation in the 918 /// source, so they have an empty source range. 919 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } 920 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } 921 922 SourceLocation getExprLoc() const LLVM_READONLY { return Loc; } 923 924 static bool classof(const Stmt *T) { 925 return T->getStmtClass() == CXXDefaultArgExprClass; 926 } 927 928 // Iterators 929 child_range children() { return child_range(); } 930 931 friend class ASTStmtReader; 932 friend class ASTStmtWriter; 933}; 934 935/// \brief A use of a default initializer in a constructor or in aggregate 936/// initialization. 937/// 938/// This wraps a use of a C++ default initializer (technically, 939/// a brace-or-equal-initializer for a non-static data member) when it 940/// is implicitly used in a mem-initializer-list in a constructor 941/// (C++11 [class.base.init]p8) or in aggregate initialization 942/// (C++1y [dcl.init.aggr]p7). 943class CXXDefaultInitExpr : public Expr { 944 /// \brief The field whose default is being used. 945 FieldDecl *Field; 946 947 /// \brief The location where the default initializer expression was used. 948 SourceLocation Loc; 949 950 CXXDefaultInitExpr(ASTContext &C, SourceLocation Loc, FieldDecl *Field, 951 QualType T); 952 953 CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {} 954 955public: 956 /// \p Field is the non-static data member whose default initializer is used 957 /// by this expression. 958 static CXXDefaultInitExpr *Create(ASTContext &C, SourceLocation Loc, 959 FieldDecl *Field) { 960 return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType()); 961 } 962 963 /// \brief Get the field whose initializer will be used. 964 FieldDecl *getField() { return Field; } 965 const FieldDecl *getField() const { return Field; } 966 967 /// \brief Get the initialization expression that will be used. 968 const Expr *getExpr() const { return Field->getInClassInitializer(); } 969 Expr *getExpr() { return Field->getInClassInitializer(); } 970 971 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 972 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 973 974 static bool classof(const Stmt *T) { 975 return T->getStmtClass() == CXXDefaultInitExprClass; 976 } 977 978 // Iterators 979 child_range children() { return child_range(); } 980 981 friend class ASTReader; 982 friend class ASTStmtReader; 983}; 984 985/// \brief Represents a C++ temporary. 986class CXXTemporary { 987 /// \brief The destructor that needs to be called. 988 const CXXDestructorDecl *Destructor; 989 990 explicit CXXTemporary(const CXXDestructorDecl *destructor) 991 : Destructor(destructor) { } 992 993public: 994 static CXXTemporary *Create(ASTContext &C, 995 const CXXDestructorDecl *Destructor); 996 997 const CXXDestructorDecl *getDestructor() const { return Destructor; } 998 void setDestructor(const CXXDestructorDecl *Dtor) { 999 Destructor = Dtor; 1000 } 1001}; 1002 1003/// \brief Represents binding an expression to a temporary. 1004/// 1005/// This ensures the destructor is called for the temporary. It should only be 1006/// needed for non-POD, non-trivially destructable class types. For example: 1007/// 1008/// \code 1009/// struct S { 1010/// S() { } // User defined constructor makes S non-POD. 1011/// ~S() { } // User defined destructor makes it non-trivial. 1012/// }; 1013/// void test() { 1014/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 1015/// } 1016/// \endcode 1017class CXXBindTemporaryExpr : public Expr { 1018 CXXTemporary *Temp; 1019 1020 Stmt *SubExpr; 1021 1022 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 1023 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 1024 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 1025 SubExpr->isValueDependent(), 1026 SubExpr->isInstantiationDependent(), 1027 SubExpr->containsUnexpandedParameterPack()), 1028 Temp(temp), SubExpr(SubExpr) { } 1029 1030public: 1031 CXXBindTemporaryExpr(EmptyShell Empty) 1032 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 1033 1034 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 1035 Expr* SubExpr); 1036 1037 CXXTemporary *getTemporary() { return Temp; } 1038 const CXXTemporary *getTemporary() const { return Temp; } 1039 void setTemporary(CXXTemporary *T) { Temp = T; } 1040 1041 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1042 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1043 void setSubExpr(Expr *E) { SubExpr = E; } 1044 1045 SourceLocation getLocStart() const LLVM_READONLY { 1046 return SubExpr->getLocStart(); 1047 } 1048 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 1049 1050 // Implement isa/cast/dyncast/etc. 1051 static bool classof(const Stmt *T) { 1052 return T->getStmtClass() == CXXBindTemporaryExprClass; 1053 } 1054 1055 // Iterators 1056 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 1057}; 1058 1059/// \brief Represents a call to a C++ constructor. 1060class CXXConstructExpr : public Expr { 1061public: 1062 enum ConstructionKind { 1063 CK_Complete, 1064 CK_NonVirtualBase, 1065 CK_VirtualBase, 1066 CK_Delegating 1067 }; 1068 1069private: 1070 CXXConstructorDecl *Constructor; 1071 1072 SourceLocation Loc; 1073 SourceRange ParenRange; 1074 unsigned NumArgs : 16; 1075 bool Elidable : 1; 1076 bool HadMultipleCandidates : 1; 1077 bool ListInitialization : 1; 1078 bool ZeroInitialization : 1; 1079 unsigned ConstructKind : 2; 1080 Stmt **Args; 1081 1082protected: 1083 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 1084 SourceLocation Loc, 1085 CXXConstructorDecl *d, bool elidable, 1086 ArrayRef<Expr *> Args, 1087 bool HadMultipleCandidates, 1088 bool ListInitialization, 1089 bool ZeroInitialization, 1090 ConstructionKind ConstructKind, 1091 SourceRange ParenRange); 1092 1093 /// \brief Construct an empty C++ construction expression. 1094 CXXConstructExpr(StmtClass SC, EmptyShell Empty) 1095 : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 1096 HadMultipleCandidates(false), ListInitialization(false), 1097 ZeroInitialization(false), ConstructKind(0), Args(0) 1098 { } 1099 1100public: 1101 /// \brief Construct an empty C++ construction expression. 1102 explicit CXXConstructExpr(EmptyShell Empty) 1103 : Expr(CXXConstructExprClass, Empty), Constructor(0), 1104 NumArgs(0), Elidable(false), HadMultipleCandidates(false), 1105 ListInitialization(false), ZeroInitialization(false), 1106 ConstructKind(0), Args(0) 1107 { } 1108 1109 static CXXConstructExpr *Create(ASTContext &C, QualType T, 1110 SourceLocation Loc, 1111 CXXConstructorDecl *D, bool Elidable, 1112 ArrayRef<Expr *> Args, 1113 bool HadMultipleCandidates, 1114 bool ListInitialization, 1115 bool ZeroInitialization, 1116 ConstructionKind ConstructKind, 1117 SourceRange ParenRange); 1118 1119 CXXConstructorDecl* getConstructor() const { return Constructor; } 1120 void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 1121 1122 SourceLocation getLocation() const { return Loc; } 1123 void setLocation(SourceLocation Loc) { this->Loc = Loc; } 1124 1125 /// \brief Whether this construction is elidable. 1126 bool isElidable() const { return Elidable; } 1127 void setElidable(bool E) { Elidable = E; } 1128 1129 /// \brief Whether the referred constructor was resolved from 1130 /// an overloaded set having size greater than 1. 1131 bool hadMultipleCandidates() const { return HadMultipleCandidates; } 1132 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 1133 1134 /// \brief Whether this constructor call was written as list-initialization. 1135 bool isListInitialization() const { return ListInitialization; } 1136 void setListInitialization(bool V) { ListInitialization = V; } 1137 1138 /// \brief Whether this construction first requires 1139 /// zero-initialization before the initializer is called. 1140 bool requiresZeroInitialization() const { return ZeroInitialization; } 1141 void setRequiresZeroInitialization(bool ZeroInit) { 1142 ZeroInitialization = ZeroInit; 1143 } 1144 1145 /// \brief Determine whether this constructor is actually constructing 1146 /// a base class (rather than a complete object). 1147 ConstructionKind getConstructionKind() const { 1148 return (ConstructionKind)ConstructKind; 1149 } 1150 void setConstructionKind(ConstructionKind CK) { 1151 ConstructKind = CK; 1152 } 1153 1154 typedef ExprIterator arg_iterator; 1155 typedef ConstExprIterator const_arg_iterator; 1156 1157 arg_iterator arg_begin() { return Args; } 1158 arg_iterator arg_end() { return Args + NumArgs; } 1159 const_arg_iterator arg_begin() const { return Args; } 1160 const_arg_iterator arg_end() const { return Args + NumArgs; } 1161 1162 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 1163 unsigned getNumArgs() const { return NumArgs; } 1164 1165 /// \brief Return the specified argument. 1166 Expr *getArg(unsigned Arg) { 1167 assert(Arg < NumArgs && "Arg access out of range!"); 1168 return cast<Expr>(Args[Arg]); 1169 } 1170 const Expr *getArg(unsigned Arg) const { 1171 assert(Arg < NumArgs && "Arg access out of range!"); 1172 return cast<Expr>(Args[Arg]); 1173 } 1174 1175 /// \brief Set the specified argument. 1176 void setArg(unsigned Arg, Expr *ArgExpr) { 1177 assert(Arg < NumArgs && "Arg access out of range!"); 1178 Args[Arg] = ArgExpr; 1179 } 1180 1181 SourceLocation getLocStart() const LLVM_READONLY; 1182 SourceLocation getLocEnd() const LLVM_READONLY; 1183 SourceRange getParenRange() const { return ParenRange; } 1184 void setParenRange(SourceRange Range) { ParenRange = Range; } 1185 1186 static bool classof(const Stmt *T) { 1187 return T->getStmtClass() == CXXConstructExprClass || 1188 T->getStmtClass() == CXXTemporaryObjectExprClass; 1189 } 1190 1191 // Iterators 1192 child_range children() { 1193 return child_range(&Args[0], &Args[0]+NumArgs); 1194 } 1195 1196 friend class ASTStmtReader; 1197}; 1198 1199/// \brief Represents an explicit C++ type conversion that uses "functional" 1200/// notation (C++ [expr.type.conv]). 1201/// 1202/// Example: 1203/// \code 1204/// x = int(0.5); 1205/// \endcode 1206class CXXFunctionalCastExpr : public ExplicitCastExpr { 1207 SourceLocation TyBeginLoc; 1208 SourceLocation RParenLoc; 1209 1210 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 1211 TypeSourceInfo *writtenTy, 1212 SourceLocation tyBeginLoc, CastKind kind, 1213 Expr *castExpr, unsigned pathSize, 1214 SourceLocation rParenLoc) 1215 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 1216 castExpr, pathSize, writtenTy), 1217 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 1218 1219 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 1220 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 1221 1222public: 1223 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T, 1224 ExprValueKind VK, 1225 TypeSourceInfo *Written, 1226 SourceLocation TyBeginLoc, 1227 CastKind Kind, Expr *Op, 1228 const CXXCastPath *Path, 1229 SourceLocation RPLoc); 1230 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context, 1231 unsigned PathSize); 1232 1233 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 1234 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 1235 SourceLocation getRParenLoc() const { return RParenLoc; } 1236 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1237 1238 SourceLocation getLocStart() const LLVM_READONLY { return TyBeginLoc; } 1239 SourceLocation getLocEnd() const LLVM_READONLY { 1240 return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getLocEnd(); 1241 } 1242 1243 static bool classof(const Stmt *T) { 1244 return T->getStmtClass() == CXXFunctionalCastExprClass; 1245 } 1246}; 1247 1248/// @brief Represents a C++ functional cast expression that builds a 1249/// temporary object. 1250/// 1251/// This expression type represents a C++ "functional" cast 1252/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 1253/// constructor to build a temporary object. With N == 1 arguments the 1254/// functional cast expression will be represented by CXXFunctionalCastExpr. 1255/// Example: 1256/// \code 1257/// struct X { X(int, float); } 1258/// 1259/// X create_X() { 1260/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 1261/// }; 1262/// \endcode 1263class CXXTemporaryObjectExpr : public CXXConstructExpr { 1264 TypeSourceInfo *Type; 1265 1266public: 1267 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 1268 TypeSourceInfo *Type, 1269 ArrayRef<Expr *> Args, 1270 SourceRange parenRange, 1271 bool HadMultipleCandidates, 1272 bool ListInitialization, 1273 bool ZeroInitialization); 1274 explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1275 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1276 1277 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1278 1279 SourceLocation getLocStart() const LLVM_READONLY; 1280 SourceLocation getLocEnd() const LLVM_READONLY; 1281 1282 static bool classof(const Stmt *T) { 1283 return T->getStmtClass() == CXXTemporaryObjectExprClass; 1284 } 1285 1286 friend class ASTStmtReader; 1287}; 1288 1289/// \brief A C++ lambda expression, which produces a function object 1290/// (of unspecified type) that can be invoked later. 1291/// 1292/// Example: 1293/// \code 1294/// void low_pass_filter(std::vector<double> &values, double cutoff) { 1295/// values.erase(std::remove_if(values.begin(), values.end(), 1296/// [=](double value) { return value > cutoff; }); 1297/// } 1298/// \endcode 1299/// 1300/// C++11 lambda expressions can capture local variables, either by copying 1301/// the values of those local variables at the time the function 1302/// object is constructed (not when it is called!) or by holding a 1303/// reference to the local variable. These captures can occur either 1304/// implicitly or can be written explicitly between the square 1305/// brackets ([...]) that start the lambda expression. 1306/// 1307/// C++1y introduces a new form of "capture" called an init-capture that 1308/// includes an initializing expression (rather than capturing a variable), 1309/// and which can never occur implicitly. 1310class LambdaExpr : public Expr { 1311 enum { 1312 /// \brief Flag used by the Capture class to indicate that the given 1313 /// capture was implicit. 1314 Capture_Implicit = 0x01, 1315 1316 /// \brief Flag used by the Capture class to indicate that the 1317 /// given capture was by-copy. 1318 /// 1319 /// This includes the case of a non-reference init-capture. 1320 Capture_ByCopy = 0x02 1321 }; 1322 1323 /// \brief The source range that covers the lambda introducer ([...]). 1324 SourceRange IntroducerRange; 1325 1326 /// \brief The source location of this lambda's capture-default ('=' or '&'). 1327 SourceLocation CaptureDefaultLoc; 1328 1329 /// \brief The number of captures. 1330 unsigned NumCaptures : 16; 1331 1332 /// \brief The default capture kind, which is a value of type 1333 /// LambdaCaptureDefault. 1334 unsigned CaptureDefault : 2; 1335 1336 /// \brief Whether this lambda had an explicit parameter list vs. an 1337 /// implicit (and empty) parameter list. 1338 unsigned ExplicitParams : 1; 1339 1340 /// \brief Whether this lambda had the result type explicitly specified. 1341 unsigned ExplicitResultType : 1; 1342 1343 /// \brief Whether there are any array index variables stored at the end of 1344 /// this lambda expression. 1345 unsigned HasArrayIndexVars : 1; 1346 1347 /// \brief The location of the closing brace ('}') that completes 1348 /// the lambda. 1349 /// 1350 /// The location of the brace is also available by looking up the 1351 /// function call operator in the lambda class. However, it is 1352 /// stored here to improve the performance of getSourceRange(), and 1353 /// to avoid having to deserialize the function call operator from a 1354 /// module file just to determine the source range. 1355 SourceLocation ClosingBrace; 1356 1357 // Note: The capture initializers are stored directly after the lambda 1358 // expression, along with the index variables used to initialize by-copy 1359 // array captures. 1360 1361public: 1362 /// \brief Describes the capture of a variable or of \c this, or of a 1363 /// C++1y init-capture. 1364 class Capture { 1365 llvm::PointerIntPair<Decl *, 2> DeclAndBits; 1366 SourceLocation Loc; 1367 SourceLocation EllipsisLoc; 1368 1369 friend class ASTStmtReader; 1370 friend class ASTStmtWriter; 1371 1372 public: 1373 /// \brief Create a new capture of a variable or of \c this. 1374 /// 1375 /// \param Loc The source location associated with this capture. 1376 /// 1377 /// \param Kind The kind of capture (this, byref, bycopy), which must 1378 /// not be init-capture. 1379 /// 1380 /// \param Implicit Whether the capture was implicit or explicit. 1381 /// 1382 /// \param Var The local variable being captured, or null if capturing 1383 /// \c this. 1384 /// 1385 /// \param EllipsisLoc The location of the ellipsis (...) for a 1386 /// capture that is a pack expansion, or an invalid source 1387 /// location to indicate that this is not a pack expansion. 1388 Capture(SourceLocation Loc, bool Implicit, 1389 LambdaCaptureKind Kind, VarDecl *Var = 0, 1390 SourceLocation EllipsisLoc = SourceLocation()); 1391 1392 /// \brief Create a new init-capture. 1393 Capture(FieldDecl *Field); 1394 1395 /// \brief Determine the kind of capture. 1396 LambdaCaptureKind getCaptureKind() const; 1397 1398 /// \brief Determine whether this capture handles the C++ \c this 1399 /// pointer. 1400 bool capturesThis() const { return DeclAndBits.getPointer() == 0; } 1401 1402 /// \brief Determine whether this capture handles a variable. 1403 bool capturesVariable() const { 1404 return dyn_cast_or_null<VarDecl>(DeclAndBits.getPointer()); 1405 } 1406 1407 /// \brief Determine whether this is an init-capture. 1408 bool isInitCapture() const { return getCaptureKind() == LCK_Init; } 1409 1410 /// \brief Retrieve the declaration of the local variable being 1411 /// captured. 1412 /// 1413 /// This operation is only valid if this capture is a variable capture 1414 /// (other than a capture of \c this). 1415 VarDecl *getCapturedVar() const { 1416 assert(capturesVariable() && "No variable available for 'this' capture"); 1417 return cast<VarDecl>(DeclAndBits.getPointer()); 1418 } 1419 1420 /// \brief Retrieve the field for an init-capture. 1421 /// 1422 /// This works only for an init-capture. To retrieve the FieldDecl for 1423 /// a captured variable or for a capture of \c this, use 1424 /// LambdaExpr::getLambdaClass and CXXRecordDecl::getCaptureFields. 1425 FieldDecl *getInitCaptureField() const { 1426 assert(getCaptureKind() == LCK_Init && "no field for non-init-capture"); 1427 return cast<FieldDecl>(DeclAndBits.getPointer()); 1428 } 1429 1430 /// \brief Determine whether this was an implicit capture (not 1431 /// written between the square brackets introducing the lambda). 1432 bool isImplicit() const { return DeclAndBits.getInt() & Capture_Implicit; } 1433 1434 /// \brief Determine whether this was an explicit capture (written 1435 /// between the square brackets introducing the lambda). 1436 bool isExplicit() const { return !isImplicit(); } 1437 1438 /// \brief Retrieve the source location of the capture. 1439 /// 1440 /// For an explicit capture, this returns the location of the 1441 /// explicit capture in the source. For an implicit capture, this 1442 /// returns the location at which the variable or \c this was first 1443 /// used. 1444 SourceLocation getLocation() const { return Loc; } 1445 1446 /// \brief Determine whether this capture is a pack expansion, 1447 /// which captures a function parameter pack. 1448 bool isPackExpansion() const { return EllipsisLoc.isValid(); } 1449 1450 /// \brief Retrieve the location of the ellipsis for a capture 1451 /// that is a pack expansion. 1452 SourceLocation getEllipsisLoc() const { 1453 assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 1454 return EllipsisLoc; 1455 } 1456 }; 1457 1458private: 1459 /// \brief Construct a lambda expression. 1460 LambdaExpr(QualType T, SourceRange IntroducerRange, 1461 LambdaCaptureDefault CaptureDefault, 1462 SourceLocation CaptureDefaultLoc, 1463 ArrayRef<Capture> Captures, 1464 bool ExplicitParams, 1465 bool ExplicitResultType, 1466 ArrayRef<Expr *> CaptureInits, 1467 ArrayRef<VarDecl *> ArrayIndexVars, 1468 ArrayRef<unsigned> ArrayIndexStarts, 1469 SourceLocation ClosingBrace, 1470 bool ContainsUnexpandedParameterPack); 1471 1472 /// \brief Construct an empty lambda expression. 1473 LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars) 1474 : Expr(LambdaExprClass, Empty), 1475 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false), 1476 ExplicitResultType(false), HasArrayIndexVars(true) { 1477 getStoredStmts()[NumCaptures] = 0; 1478 } 1479 1480 Stmt **getStoredStmts() const { 1481 return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1); 1482 } 1483 1484 /// \brief Retrieve the mapping from captures to the first array index 1485 /// variable. 1486 unsigned *getArrayIndexStarts() const { 1487 return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1); 1488 } 1489 1490 /// \brief Retrieve the complete set of array-index variables. 1491 VarDecl **getArrayIndexVars() const { 1492 unsigned ArrayIndexSize = 1493 llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1), 1494 llvm::alignOf<VarDecl*>()); 1495 return reinterpret_cast<VarDecl **>( 1496 reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize); 1497 } 1498 1499public: 1500 /// \brief Construct a new lambda expression. 1501 static LambdaExpr *Create(ASTContext &C, 1502 CXXRecordDecl *Class, 1503 SourceRange IntroducerRange, 1504 LambdaCaptureDefault CaptureDefault, 1505 SourceLocation CaptureDefaultLoc, 1506 ArrayRef<Capture> Captures, 1507 bool ExplicitParams, 1508 bool ExplicitResultType, 1509 ArrayRef<Expr *> CaptureInits, 1510 ArrayRef<VarDecl *> ArrayIndexVars, 1511 ArrayRef<unsigned> ArrayIndexStarts, 1512 SourceLocation ClosingBrace, 1513 bool ContainsUnexpandedParameterPack); 1514 1515 /// \brief Construct a new lambda expression that will be deserialized from 1516 /// an external source. 1517 static LambdaExpr *CreateDeserialized(ASTContext &C, 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(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(ASTContext &C, bool isArray, unsigned numPlaceArgs, 1737 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(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(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(ASTContext &C, QualType T, SourceLocation Loc, 2291 TypeTrait Kind, 2292 ArrayRef<TypeSourceInfo *> Args, 2293 SourceLocation RParenLoc, 2294 bool Value); 2295 2296 static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs); 2297 2298 /// \brief Determine which type trait this expression uses. 2299 TypeTrait getTrait() const { 2300 return static_cast<TypeTrait>(TypeTraitExprBits.Kind); 2301 } 2302 2303 bool getValue() const { 2304 assert(!isValueDependent()); 2305 return TypeTraitExprBits.Value; 2306 } 2307 2308 /// \brief Determine the number of arguments to this type trait. 2309 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; } 2310 2311 /// \brief Retrieve the Ith argument. 2312 TypeSourceInfo *getArg(unsigned I) const { 2313 assert(I < getNumArgs() && "Argument out-of-range"); 2314 return getArgs()[I]; 2315 } 2316 2317 /// \brief Retrieve the argument types. 2318 ArrayRef<TypeSourceInfo *> getArgs() const { 2319 return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs()); 2320 } 2321 2322 typedef TypeSourceInfo **arg_iterator; 2323 arg_iterator arg_begin() { 2324 return getTypeSourceInfos(); 2325 } 2326 arg_iterator arg_end() { 2327 return getTypeSourceInfos() + getNumArgs(); 2328 } 2329 2330 typedef TypeSourceInfo const * const *arg_const_iterator; 2331 arg_const_iterator arg_begin() const { return getTypeSourceInfos(); } 2332 arg_const_iterator arg_end() const { 2333 return getTypeSourceInfos() + getNumArgs(); 2334 } 2335 2336 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2337 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 2338 2339 static bool classof(const Stmt *T) { 2340 return T->getStmtClass() == TypeTraitExprClass; 2341 } 2342 2343 // Iterators 2344 child_range children() { return child_range(); } 2345 2346 friend class ASTStmtReader; 2347 friend class ASTStmtWriter; 2348 2349}; 2350 2351/// \brief An Embarcadero array type trait, as used in the implementation of 2352/// __array_rank and __array_extent. 2353/// 2354/// Example: 2355/// \code 2356/// __array_rank(int[10][20]) == 2 2357/// __array_extent(int, 1) == 20 2358/// \endcode 2359class ArrayTypeTraitExpr : public Expr { 2360 virtual void anchor(); 2361 2362 /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 2363 unsigned ATT : 2; 2364 2365 /// \brief The value of the type trait. Unspecified if dependent. 2366 uint64_t Value; 2367 2368 /// \brief The array dimension being queried, or -1 if not used. 2369 Expr *Dimension; 2370 2371 /// \brief The location of the type trait keyword. 2372 SourceLocation Loc; 2373 2374 /// \brief The location of the closing paren. 2375 SourceLocation RParen; 2376 2377 /// \brief The type being queried. 2378 TypeSourceInfo *QueriedType; 2379 2380public: 2381 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 2382 TypeSourceInfo *queried, uint64_t value, 2383 Expr *dimension, SourceLocation rparen, QualType ty) 2384 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 2385 false, queried->getType()->isDependentType(), 2386 (queried->getType()->isInstantiationDependentType() || 2387 (dimension && dimension->isInstantiationDependent())), 2388 queried->getType()->containsUnexpandedParameterPack()), 2389 ATT(att), Value(value), Dimension(dimension), 2390 Loc(loc), RParen(rparen), QueriedType(queried) { } 2391 2392 2393 explicit ArrayTypeTraitExpr(EmptyShell Empty) 2394 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 2395 QueriedType() { } 2396 2397 virtual ~ArrayTypeTraitExpr() { } 2398 2399 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2400 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2401 2402 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 2403 2404 QualType getQueriedType() const { return QueriedType->getType(); } 2405 2406 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 2407 2408 uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 2409 2410 Expr *getDimensionExpression() const { return Dimension; } 2411 2412 static bool classof(const Stmt *T) { 2413 return T->getStmtClass() == ArrayTypeTraitExprClass; 2414 } 2415 2416 // Iterators 2417 child_range children() { return child_range(); } 2418 2419 friend class ASTStmtReader; 2420}; 2421 2422/// \brief An expression trait intrinsic. 2423/// 2424/// Example: 2425/// \code 2426/// __is_lvalue_expr(std::cout) == true 2427/// __is_lvalue_expr(1) == false 2428/// \endcode 2429class ExpressionTraitExpr : public Expr { 2430 /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned. 2431 unsigned ET : 31; 2432 /// \brief The value of the type trait. Unspecified if dependent. 2433 bool Value : 1; 2434 2435 /// \brief The location of the type trait keyword. 2436 SourceLocation Loc; 2437 2438 /// \brief The location of the closing paren. 2439 SourceLocation RParen; 2440 2441 /// \brief The expression being queried. 2442 Expr* QueriedExpression; 2443public: 2444 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2445 Expr *queried, bool value, 2446 SourceLocation rparen, QualType resultType) 2447 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2448 false, // Not type-dependent 2449 // Value-dependent if the argument is type-dependent. 2450 queried->isTypeDependent(), 2451 queried->isInstantiationDependent(), 2452 queried->containsUnexpandedParameterPack()), 2453 ET(et), Value(value), Loc(loc), RParen(rparen), 2454 QueriedExpression(queried) { } 2455 2456 explicit ExpressionTraitExpr(EmptyShell Empty) 2457 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2458 QueriedExpression() { } 2459 2460 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2461 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2462 2463 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2464 2465 Expr *getQueriedExpression() const { return QueriedExpression; } 2466 2467 bool getValue() const { return Value; } 2468 2469 static bool classof(const Stmt *T) { 2470 return T->getStmtClass() == ExpressionTraitExprClass; 2471 } 2472 2473 // Iterators 2474 child_range children() { return child_range(); } 2475 2476 friend class ASTStmtReader; 2477}; 2478 2479 2480/// \brief A reference to an overloaded function set, either an 2481/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr. 2482class OverloadExpr : public Expr { 2483 /// \brief The common name of these declarations. 2484 DeclarationNameInfo NameInfo; 2485 2486 /// \brief The nested-name-specifier that qualifies the name, if any. 2487 NestedNameSpecifierLoc QualifierLoc; 2488 2489 /// The results. These are undesugared, which is to say, they may 2490 /// include UsingShadowDecls. Access is relative to the naming 2491 /// class. 2492 // FIXME: Allocate this data after the OverloadExpr subclass. 2493 DeclAccessPair *Results; 2494 unsigned NumResults; 2495 2496protected: 2497 /// \brief Whether the name includes info for explicit template 2498 /// keyword and arguments. 2499 bool HasTemplateKWAndArgsInfo; 2500 2501 /// \brief Return the optional template keyword and arguments info. 2502 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2503 2504 /// \brief Return the optional template keyword and arguments info. 2505 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2506 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2507 } 2508 2509 OverloadExpr(StmtClass K, ASTContext &C, 2510 NestedNameSpecifierLoc QualifierLoc, 2511 SourceLocation TemplateKWLoc, 2512 const DeclarationNameInfo &NameInfo, 2513 const TemplateArgumentListInfo *TemplateArgs, 2514 UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2515 bool KnownDependent, 2516 bool KnownInstantiationDependent, 2517 bool KnownContainsUnexpandedParameterPack); 2518 2519 OverloadExpr(StmtClass K, EmptyShell Empty) 2520 : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0), 2521 HasTemplateKWAndArgsInfo(false) { } 2522 2523 void initializeResults(ASTContext &C, 2524 UnresolvedSetIterator Begin, 2525 UnresolvedSetIterator End); 2526 2527public: 2528 struct FindResult { 2529 OverloadExpr *Expression; 2530 bool IsAddressOfOperand; 2531 bool HasFormOfMemberPointer; 2532 }; 2533 2534 /// \brief Finds the overloaded expression in the given expression \p E of 2535 /// OverloadTy. 2536 /// 2537 /// \return the expression (which must be there) and true if it has 2538 /// the particular form of a member pointer expression 2539 static FindResult find(Expr *E) { 2540 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 2541 2542 FindResult Result; 2543 2544 E = E->IgnoreParens(); 2545 if (isa<UnaryOperator>(E)) { 2546 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 2547 E = cast<UnaryOperator>(E)->getSubExpr(); 2548 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 2549 2550 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 2551 Result.IsAddressOfOperand = true; 2552 Result.Expression = Ovl; 2553 } else { 2554 Result.HasFormOfMemberPointer = false; 2555 Result.IsAddressOfOperand = false; 2556 Result.Expression = cast<OverloadExpr>(E); 2557 } 2558 2559 return Result; 2560 } 2561 2562 /// \brief Gets the naming class of this lookup, if any. 2563 CXXRecordDecl *getNamingClass() const; 2564 2565 typedef UnresolvedSetImpl::iterator decls_iterator; 2566 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2567 decls_iterator decls_end() const { 2568 return UnresolvedSetIterator(Results + NumResults); 2569 } 2570 2571 /// \brief Gets the number of declarations in the unresolved set. 2572 unsigned getNumDecls() const { return NumResults; } 2573 2574 /// \brief Gets the full name info. 2575 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2576 2577 /// \brief Gets the name looked up. 2578 DeclarationName getName() const { return NameInfo.getName(); } 2579 2580 /// \brief Gets the location of the name. 2581 SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 2582 2583 /// \brief Fetches the nested-name qualifier, if one was given. 2584 NestedNameSpecifier *getQualifier() const { 2585 return QualifierLoc.getNestedNameSpecifier(); 2586 } 2587 2588 /// \brief Fetches the nested-name qualifier with source-location 2589 /// information, if one was given. 2590 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2591 2592 /// \brief Retrieve the location of the template keyword preceding 2593 /// this name, if any. 2594 SourceLocation getTemplateKeywordLoc() const { 2595 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2596 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2597 } 2598 2599 /// \brief Retrieve the location of the left angle bracket starting the 2600 /// explicit template argument list following the name, if any. 2601 SourceLocation getLAngleLoc() const { 2602 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2603 return getTemplateKWAndArgsInfo()->LAngleLoc; 2604 } 2605 2606 /// \brief Retrieve the location of the right angle bracket ending the 2607 /// explicit template argument list following the name, if any. 2608 SourceLocation getRAngleLoc() const { 2609 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2610 return getTemplateKWAndArgsInfo()->RAngleLoc; 2611 } 2612 2613 /// \brief Determines whether the name was preceded by the template keyword. 2614 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2615 2616 /// \brief Determines whether this expression had explicit template arguments. 2617 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2618 2619 // Note that, inconsistently with the explicit-template-argument AST 2620 // nodes, users are *forbidden* from calling these methods on objects 2621 // without explicit template arguments. 2622 2623 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2624 assert(hasExplicitTemplateArgs()); 2625 return *getTemplateKWAndArgsInfo(); 2626 } 2627 2628 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2629 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 2630 } 2631 2632 TemplateArgumentLoc const *getTemplateArgs() const { 2633 return getExplicitTemplateArgs().getTemplateArgs(); 2634 } 2635 2636 unsigned getNumTemplateArgs() const { 2637 return getExplicitTemplateArgs().NumTemplateArgs; 2638 } 2639 2640 /// \brief Copies the template arguments into the given structure. 2641 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2642 getExplicitTemplateArgs().copyInto(List); 2643 } 2644 2645 /// \brief Retrieves the optional explicit template arguments. 2646 /// 2647 /// This points to the same data as getExplicitTemplateArgs(), but 2648 /// returns null if there are no explicit template arguments. 2649 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2650 if (!hasExplicitTemplateArgs()) return 0; 2651 return &getExplicitTemplateArgs(); 2652 } 2653 2654 static bool classof(const Stmt *T) { 2655 return T->getStmtClass() == UnresolvedLookupExprClass || 2656 T->getStmtClass() == UnresolvedMemberExprClass; 2657 } 2658 2659 friend class ASTStmtReader; 2660 friend class ASTStmtWriter; 2661}; 2662 2663/// \brief A reference to a name which we were able to look up during 2664/// parsing but could not resolve to a specific declaration. 2665/// 2666/// This arises in several ways: 2667/// * we might be waiting for argument-dependent lookup; 2668/// * the name might resolve to an overloaded function; 2669/// and eventually: 2670/// * the lookup might have included a function template. 2671/// 2672/// These never include UnresolvedUsingValueDecls, which are always class 2673/// members and therefore appear only in UnresolvedMemberLookupExprs. 2674class UnresolvedLookupExpr : public OverloadExpr { 2675 /// True if these lookup results should be extended by 2676 /// argument-dependent lookup if this is the operand of a function 2677 /// call. 2678 bool RequiresADL; 2679 2680 /// True if these lookup results are overloaded. This is pretty 2681 /// trivially rederivable if we urgently need to kill this field. 2682 bool Overloaded; 2683 2684 /// The naming class (C++ [class.access.base]p5) of the lookup, if 2685 /// any. This can generally be recalculated from the context chain, 2686 /// but that can be fairly expensive for unqualified lookups. If we 2687 /// want to improve memory use here, this could go in a union 2688 /// against the qualified-lookup bits. 2689 CXXRecordDecl *NamingClass; 2690 2691 UnresolvedLookupExpr(ASTContext &C, 2692 CXXRecordDecl *NamingClass, 2693 NestedNameSpecifierLoc QualifierLoc, 2694 SourceLocation TemplateKWLoc, 2695 const DeclarationNameInfo &NameInfo, 2696 bool RequiresADL, bool Overloaded, 2697 const TemplateArgumentListInfo *TemplateArgs, 2698 UnresolvedSetIterator Begin, UnresolvedSetIterator End) 2699 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2700 NameInfo, TemplateArgs, Begin, End, false, false, false), 2701 RequiresADL(RequiresADL), 2702 Overloaded(Overloaded), NamingClass(NamingClass) 2703 {} 2704 2705 UnresolvedLookupExpr(EmptyShell Empty) 2706 : OverloadExpr(UnresolvedLookupExprClass, Empty), 2707 RequiresADL(false), Overloaded(false), NamingClass(0) 2708 {} 2709 2710 friend class ASTStmtReader; 2711 2712public: 2713 static UnresolvedLookupExpr *Create(ASTContext &C, 2714 CXXRecordDecl *NamingClass, 2715 NestedNameSpecifierLoc QualifierLoc, 2716 const DeclarationNameInfo &NameInfo, 2717 bool ADL, bool Overloaded, 2718 UnresolvedSetIterator Begin, 2719 UnresolvedSetIterator End) { 2720 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2721 SourceLocation(), NameInfo, 2722 ADL, Overloaded, 0, Begin, End); 2723 } 2724 2725 static UnresolvedLookupExpr *Create(ASTContext &C, 2726 CXXRecordDecl *NamingClass, 2727 NestedNameSpecifierLoc QualifierLoc, 2728 SourceLocation TemplateKWLoc, 2729 const DeclarationNameInfo &NameInfo, 2730 bool ADL, 2731 const TemplateArgumentListInfo *Args, 2732 UnresolvedSetIterator Begin, 2733 UnresolvedSetIterator End); 2734 2735 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 2736 bool HasTemplateKWAndArgsInfo, 2737 unsigned NumTemplateArgs); 2738 2739 /// True if this declaration should be extended by 2740 /// argument-dependent lookup. 2741 bool requiresADL() const { return RequiresADL; } 2742 2743 /// True if this lookup is overloaded. 2744 bool isOverloaded() const { return Overloaded; } 2745 2746 /// Gets the 'naming class' (in the sense of C++0x 2747 /// [class.access.base]p5) of the lookup. This is the scope 2748 /// that was looked in to find these results. 2749 CXXRecordDecl *getNamingClass() const { return NamingClass; } 2750 2751 SourceLocation getLocStart() const LLVM_READONLY { 2752 if (NestedNameSpecifierLoc l = getQualifierLoc()) 2753 return l.getBeginLoc(); 2754 return getNameInfo().getLocStart(); 2755 } 2756 SourceLocation getLocEnd() const LLVM_READONLY { 2757 if (hasExplicitTemplateArgs()) 2758 return getRAngleLoc(); 2759 return getNameInfo().getLocEnd(); 2760 } 2761 2762 child_range children() { return child_range(); } 2763 2764 static bool classof(const Stmt *T) { 2765 return T->getStmtClass() == UnresolvedLookupExprClass; 2766 } 2767}; 2768 2769/// \brief A qualified reference to a name whose declaration cannot 2770/// yet be resolved. 2771/// 2772/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2773/// it expresses a reference to a declaration such as 2774/// X<T>::value. The difference, however, is that an 2775/// DependentScopeDeclRefExpr node is used only within C++ templates when 2776/// the qualification (e.g., X<T>::) refers to a dependent type. In 2777/// this case, X<T>::value cannot resolve to a declaration because the 2778/// declaration will differ from on instantiation of X<T> to the 2779/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2780/// qualifier (X<T>::) and the name of the entity being referenced 2781/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2782/// declaration can be found. 2783class DependentScopeDeclRefExpr : public Expr { 2784 /// \brief The nested-name-specifier that qualifies this unresolved 2785 /// declaration name. 2786 NestedNameSpecifierLoc QualifierLoc; 2787 2788 /// \brief The name of the entity we will be referencing. 2789 DeclarationNameInfo NameInfo; 2790 2791 /// \brief Whether the name includes info for explicit template 2792 /// keyword and arguments. 2793 bool HasTemplateKWAndArgsInfo; 2794 2795 /// \brief Return the optional template keyword and arguments info. 2796 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2797 if (!HasTemplateKWAndArgsInfo) return 0; 2798 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2799 } 2800 /// \brief Return the optional template keyword and arguments info. 2801 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2802 return const_cast<DependentScopeDeclRefExpr*>(this) 2803 ->getTemplateKWAndArgsInfo(); 2804 } 2805 2806 DependentScopeDeclRefExpr(QualType T, 2807 NestedNameSpecifierLoc QualifierLoc, 2808 SourceLocation TemplateKWLoc, 2809 const DeclarationNameInfo &NameInfo, 2810 const TemplateArgumentListInfo *Args); 2811 2812public: 2813 static DependentScopeDeclRefExpr *Create(ASTContext &C, 2814 NestedNameSpecifierLoc QualifierLoc, 2815 SourceLocation TemplateKWLoc, 2816 const DeclarationNameInfo &NameInfo, 2817 const TemplateArgumentListInfo *TemplateArgs); 2818 2819 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 2820 bool HasTemplateKWAndArgsInfo, 2821 unsigned NumTemplateArgs); 2822 2823 /// \brief Retrieve the name that this expression refers to. 2824 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2825 2826 /// \brief Retrieve the name that this expression refers to. 2827 DeclarationName getDeclName() const { return NameInfo.getName(); } 2828 2829 /// \brief Retrieve the location of the name within the expression. 2830 SourceLocation getLocation() const { return NameInfo.getLoc(); } 2831 2832 /// \brief Retrieve the nested-name-specifier that qualifies the 2833 /// name, with source location information. 2834 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2835 2836 2837 /// \brief Retrieve the nested-name-specifier that qualifies this 2838 /// declaration. 2839 NestedNameSpecifier *getQualifier() const { 2840 return QualifierLoc.getNestedNameSpecifier(); 2841 } 2842 2843 /// \brief Retrieve the location of the template keyword preceding 2844 /// this name, if any. 2845 SourceLocation getTemplateKeywordLoc() const { 2846 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2847 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2848 } 2849 2850 /// \brief Retrieve the location of the left angle bracket starting the 2851 /// explicit template argument list following the name, if any. 2852 SourceLocation getLAngleLoc() const { 2853 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2854 return getTemplateKWAndArgsInfo()->LAngleLoc; 2855 } 2856 2857 /// \brief Retrieve the location of the right angle bracket ending the 2858 /// explicit template argument list following the name, if any. 2859 SourceLocation getRAngleLoc() const { 2860 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2861 return getTemplateKWAndArgsInfo()->RAngleLoc; 2862 } 2863 2864 /// Determines whether the name was preceded by the template keyword. 2865 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2866 2867 /// Determines whether this lookup had explicit template arguments. 2868 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2869 2870 // Note that, inconsistently with the explicit-template-argument AST 2871 // nodes, users are *forbidden* from calling these methods on objects 2872 // without explicit template arguments. 2873 2874 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2875 assert(hasExplicitTemplateArgs()); 2876 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 2877 } 2878 2879 /// Gets a reference to the explicit template argument list. 2880 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2881 assert(hasExplicitTemplateArgs()); 2882 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2883 } 2884 2885 /// \brief Retrieves the optional explicit template arguments. 2886 /// 2887 /// This points to the same data as getExplicitTemplateArgs(), but 2888 /// returns null if there are no explicit template arguments. 2889 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2890 if (!hasExplicitTemplateArgs()) return 0; 2891 return &getExplicitTemplateArgs(); 2892 } 2893 2894 /// \brief Copies the template arguments (if present) into the given 2895 /// structure. 2896 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2897 getExplicitTemplateArgs().copyInto(List); 2898 } 2899 2900 TemplateArgumentLoc const *getTemplateArgs() const { 2901 return getExplicitTemplateArgs().getTemplateArgs(); 2902 } 2903 2904 unsigned getNumTemplateArgs() const { 2905 return getExplicitTemplateArgs().NumTemplateArgs; 2906 } 2907 2908 SourceLocation getLocStart() const LLVM_READONLY { 2909 return QualifierLoc.getBeginLoc(); 2910 } 2911 SourceLocation getLocEnd() const LLVM_READONLY { 2912 if (hasExplicitTemplateArgs()) 2913 return getRAngleLoc(); 2914 return getLocation(); 2915 } 2916 2917 static bool classof(const Stmt *T) { 2918 return T->getStmtClass() == DependentScopeDeclRefExprClass; 2919 } 2920 2921 child_range children() { return child_range(); } 2922 2923 friend class ASTStmtReader; 2924 friend class ASTStmtWriter; 2925}; 2926 2927/// Represents an expression -- generally a full-expression -- that 2928/// introduces cleanups to be run at the end of the sub-expression's 2929/// evaluation. The most common source of expression-introduced 2930/// cleanups is temporary objects in C++, but several other kinds of 2931/// expressions can create cleanups, including basically every 2932/// call in ARC that returns an Objective-C pointer. 2933/// 2934/// This expression also tracks whether the sub-expression contains a 2935/// potentially-evaluated block literal. The lifetime of a block 2936/// literal is the extent of the enclosing scope. 2937class ExprWithCleanups : public Expr { 2938public: 2939 /// The type of objects that are kept in the cleanup. 2940 /// It's useful to remember the set of blocks; we could also 2941 /// remember the set of temporaries, but there's currently 2942 /// no need. 2943 typedef BlockDecl *CleanupObject; 2944 2945private: 2946 Stmt *SubExpr; 2947 2948 ExprWithCleanups(EmptyShell, unsigned NumObjects); 2949 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 2950 2951 CleanupObject *getObjectsBuffer() { 2952 return reinterpret_cast<CleanupObject*>(this + 1); 2953 } 2954 const CleanupObject *getObjectsBuffer() const { 2955 return reinterpret_cast<const CleanupObject*>(this + 1); 2956 } 2957 friend class ASTStmtReader; 2958 2959public: 2960 static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty, 2961 unsigned numObjects); 2962 2963 static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr, 2964 ArrayRef<CleanupObject> objects); 2965 2966 ArrayRef<CleanupObject> getObjects() const { 2967 return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2968 } 2969 2970 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 2971 2972 CleanupObject getObject(unsigned i) const { 2973 assert(i < getNumObjects() && "Index out of range"); 2974 return getObjects()[i]; 2975 } 2976 2977 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2978 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 2979 2980 /// As with any mutator of the AST, be very careful 2981 /// when modifying an existing AST to preserve its invariants. 2982 void setSubExpr(Expr *E) { SubExpr = E; } 2983 2984 SourceLocation getLocStart() const LLVM_READONLY { 2985 return SubExpr->getLocStart(); 2986 } 2987 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 2988 2989 // Implement isa/cast/dyncast/etc. 2990 static bool classof(const Stmt *T) { 2991 return T->getStmtClass() == ExprWithCleanupsClass; 2992 } 2993 2994 // Iterators 2995 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 2996}; 2997 2998/// \brief Describes an explicit type conversion that uses functional 2999/// notion but could not be resolved because one or more arguments are 3000/// type-dependent. 3001/// 3002/// The explicit type conversions expressed by 3003/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>, 3004/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and 3005/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is 3006/// type-dependent. For example, this would occur in a template such 3007/// as: 3008/// 3009/// \code 3010/// template<typename T, typename A1> 3011/// inline T make_a(const A1& a1) { 3012/// return T(a1); 3013/// } 3014/// \endcode 3015/// 3016/// When the returned expression is instantiated, it may resolve to a 3017/// constructor call, conversion function call, or some kind of type 3018/// conversion. 3019class CXXUnresolvedConstructExpr : public Expr { 3020 /// \brief The type being constructed. 3021 TypeSourceInfo *Type; 3022 3023 /// \brief The location of the left parentheses ('('). 3024 SourceLocation LParenLoc; 3025 3026 /// \brief The location of the right parentheses (')'). 3027 SourceLocation RParenLoc; 3028 3029 /// \brief The number of arguments used to construct the type. 3030 unsigned NumArgs; 3031 3032 CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 3033 SourceLocation LParenLoc, 3034 ArrayRef<Expr*> Args, 3035 SourceLocation RParenLoc); 3036 3037 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 3038 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 3039 3040 friend class ASTStmtReader; 3041 3042public: 3043 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 3044 TypeSourceInfo *Type, 3045 SourceLocation LParenLoc, 3046 ArrayRef<Expr*> Args, 3047 SourceLocation RParenLoc); 3048 3049 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 3050 unsigned NumArgs); 3051 3052 /// \brief Retrieve the type that is being constructed, as specified 3053 /// in the source code. 3054 QualType getTypeAsWritten() const { return Type->getType(); } 3055 3056 /// \brief Retrieve the type source information for the type being 3057 /// constructed. 3058 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 3059 3060 /// \brief Retrieve the location of the left parentheses ('(') that 3061 /// precedes the argument list. 3062 SourceLocation getLParenLoc() const { return LParenLoc; } 3063 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 3064 3065 /// \brief Retrieve the location of the right parentheses (')') that 3066 /// follows the argument list. 3067 SourceLocation getRParenLoc() const { return RParenLoc; } 3068 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3069 3070 /// \brief Retrieve the number of arguments. 3071 unsigned arg_size() const { return NumArgs; } 3072 3073 typedef Expr** arg_iterator; 3074 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 3075 arg_iterator arg_end() { return arg_begin() + NumArgs; } 3076 3077 typedef const Expr* const * const_arg_iterator; 3078 const_arg_iterator arg_begin() const { 3079 return reinterpret_cast<const Expr* const *>(this + 1); 3080 } 3081 const_arg_iterator arg_end() const { 3082 return arg_begin() + NumArgs; 3083 } 3084 3085 Expr *getArg(unsigned I) { 3086 assert(I < NumArgs && "Argument index out-of-range"); 3087 return *(arg_begin() + I); 3088 } 3089 3090 const Expr *getArg(unsigned I) const { 3091 assert(I < NumArgs && "Argument index out-of-range"); 3092 return *(arg_begin() + I); 3093 } 3094 3095 void setArg(unsigned I, Expr *E) { 3096 assert(I < NumArgs && "Argument index out-of-range"); 3097 *(arg_begin() + I) = E; 3098 } 3099 3100 SourceLocation getLocStart() const LLVM_READONLY; 3101 SourceLocation getLocEnd() const LLVM_READONLY { 3102 assert(RParenLoc.isValid() || NumArgs == 1); 3103 return RParenLoc.isValid() ? RParenLoc : getArg(0)->getLocEnd(); 3104 } 3105 3106 static bool classof(const Stmt *T) { 3107 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 3108 } 3109 3110 // Iterators 3111 child_range children() { 3112 Stmt **begin = reinterpret_cast<Stmt**>(this+1); 3113 return child_range(begin, begin + NumArgs); 3114 } 3115}; 3116 3117/// \brief Represents a C++ member access expression where the actual 3118/// member referenced could not be resolved because the base 3119/// expression or the member name was dependent. 3120/// 3121/// Like UnresolvedMemberExprs, these can be either implicit or 3122/// explicit accesses. It is only possible to get one of these with 3123/// an implicit access if a qualifier is provided. 3124class CXXDependentScopeMemberExpr : public Expr { 3125 /// \brief The expression for the base pointer or class reference, 3126 /// e.g., the \c x in x.f. Can be null in implicit accesses. 3127 Stmt *Base; 3128 3129 /// \brief The type of the base expression. Never null, even for 3130 /// implicit accesses. 3131 QualType BaseType; 3132 3133 /// \brief Whether this member expression used the '->' operator or 3134 /// the '.' operator. 3135 bool IsArrow : 1; 3136 3137 /// \brief Whether this member expression has info for explicit template 3138 /// keyword and arguments. 3139 bool HasTemplateKWAndArgsInfo : 1; 3140 3141 /// \brief The location of the '->' or '.' operator. 3142 SourceLocation OperatorLoc; 3143 3144 /// \brief The nested-name-specifier that precedes the member name, if any. 3145 NestedNameSpecifierLoc QualifierLoc; 3146 3147 /// \brief In a qualified member access expression such as t->Base::f, this 3148 /// member stores the resolves of name lookup in the context of the member 3149 /// access expression, to be used at instantiation time. 3150 /// 3151 /// FIXME: This member, along with the QualifierLoc, could 3152 /// be stuck into a structure that is optionally allocated at the end of 3153 /// the CXXDependentScopeMemberExpr, to save space in the common case. 3154 NamedDecl *FirstQualifierFoundInScope; 3155 3156 /// \brief The member to which this member expression refers, which 3157 /// can be name, overloaded operator, or destructor. 3158 /// 3159 /// FIXME: could also be a template-id 3160 DeclarationNameInfo MemberNameInfo; 3161 3162 /// \brief Return the optional template keyword and arguments info. 3163 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 3164 if (!HasTemplateKWAndArgsInfo) return 0; 3165 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 3166 } 3167 /// \brief Return the optional template keyword and arguments info. 3168 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 3169 return const_cast<CXXDependentScopeMemberExpr*>(this) 3170 ->getTemplateKWAndArgsInfo(); 3171 } 3172 3173 CXXDependentScopeMemberExpr(ASTContext &C, 3174 Expr *Base, QualType BaseType, bool IsArrow, 3175 SourceLocation OperatorLoc, 3176 NestedNameSpecifierLoc QualifierLoc, 3177 SourceLocation TemplateKWLoc, 3178 NamedDecl *FirstQualifierFoundInScope, 3179 DeclarationNameInfo MemberNameInfo, 3180 const TemplateArgumentListInfo *TemplateArgs); 3181 3182public: 3183 CXXDependentScopeMemberExpr(ASTContext &C, 3184 Expr *Base, QualType BaseType, 3185 bool IsArrow, 3186 SourceLocation OperatorLoc, 3187 NestedNameSpecifierLoc QualifierLoc, 3188 NamedDecl *FirstQualifierFoundInScope, 3189 DeclarationNameInfo MemberNameInfo); 3190 3191 static CXXDependentScopeMemberExpr * 3192 Create(ASTContext &C, 3193 Expr *Base, QualType BaseType, bool IsArrow, 3194 SourceLocation OperatorLoc, 3195 NestedNameSpecifierLoc QualifierLoc, 3196 SourceLocation TemplateKWLoc, 3197 NamedDecl *FirstQualifierFoundInScope, 3198 DeclarationNameInfo MemberNameInfo, 3199 const TemplateArgumentListInfo *TemplateArgs); 3200 3201 static CXXDependentScopeMemberExpr * 3202 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3203 unsigned NumTemplateArgs); 3204 3205 /// \brief True if this is an implicit access, i.e. one in which the 3206 /// member being accessed was not written in the source. The source 3207 /// location of the operator is invalid in this case. 3208 bool isImplicitAccess() const; 3209 3210 /// \brief Retrieve the base object of this member expressions, 3211 /// e.g., the \c x in \c x.m. 3212 Expr *getBase() const { 3213 assert(!isImplicitAccess()); 3214 return cast<Expr>(Base); 3215 } 3216 3217 QualType getBaseType() const { return BaseType; } 3218 3219 /// \brief Determine whether this member expression used the '->' 3220 /// operator; otherwise, it used the '.' operator. 3221 bool isArrow() const { return IsArrow; } 3222 3223 /// \brief Retrieve the location of the '->' or '.' operator. 3224 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3225 3226 /// \brief Retrieve the nested-name-specifier that qualifies the member 3227 /// name. 3228 NestedNameSpecifier *getQualifier() const { 3229 return QualifierLoc.getNestedNameSpecifier(); 3230 } 3231 3232 /// \brief Retrieve the nested-name-specifier that qualifies the member 3233 /// name, with source location information. 3234 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 3235 3236 3237 /// \brief Retrieve the first part of the nested-name-specifier that was 3238 /// found in the scope of the member access expression when the member access 3239 /// was initially parsed. 3240 /// 3241 /// This function only returns a useful result when member access expression 3242 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 3243 /// returned by this function describes what was found by unqualified name 3244 /// lookup for the identifier "Base" within the scope of the member access 3245 /// expression itself. At template instantiation time, this information is 3246 /// combined with the results of name lookup into the type of the object 3247 /// expression itself (the class type of x). 3248 NamedDecl *getFirstQualifierFoundInScope() const { 3249 return FirstQualifierFoundInScope; 3250 } 3251 3252 /// \brief Retrieve the name of the member that this expression 3253 /// refers to. 3254 const DeclarationNameInfo &getMemberNameInfo() const { 3255 return MemberNameInfo; 3256 } 3257 3258 /// \brief Retrieve the name of the member that this expression 3259 /// refers to. 3260 DeclarationName getMember() const { return MemberNameInfo.getName(); } 3261 3262 // \brief Retrieve the location of the name of the member that this 3263 // expression refers to. 3264 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 3265 3266 /// \brief Retrieve the location of the template keyword preceding the 3267 /// member name, if any. 3268 SourceLocation getTemplateKeywordLoc() const { 3269 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3270 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 3271 } 3272 3273 /// \brief Retrieve the location of the left angle bracket starting the 3274 /// explicit template argument list following the member name, if any. 3275 SourceLocation getLAngleLoc() const { 3276 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3277 return getTemplateKWAndArgsInfo()->LAngleLoc; 3278 } 3279 3280 /// \brief Retrieve the location of the right angle bracket ending the 3281 /// explicit template argument list following the member name, if any. 3282 SourceLocation getRAngleLoc() const { 3283 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3284 return getTemplateKWAndArgsInfo()->RAngleLoc; 3285 } 3286 3287 /// Determines whether the member name was preceded by the template keyword. 3288 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 3289 3290 /// \brief Determines whether this member expression actually had a C++ 3291 /// template argument list explicitly specified, e.g., x.f<int>. 3292 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 3293 3294 /// \brief Retrieve the explicit template argument list that followed the 3295 /// member template name, if any. 3296 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 3297 assert(hasExplicitTemplateArgs()); 3298 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 3299 } 3300 3301 /// \brief Retrieve the explicit template argument list that followed the 3302 /// member template name, if any. 3303 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 3304 return const_cast<CXXDependentScopeMemberExpr *>(this) 3305 ->getExplicitTemplateArgs(); 3306 } 3307 3308 /// \brief Retrieves the optional explicit template arguments. 3309 /// 3310 /// This points to the same data as getExplicitTemplateArgs(), but 3311 /// returns null if there are no explicit template arguments. 3312 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 3313 if (!hasExplicitTemplateArgs()) return 0; 3314 return &getExplicitTemplateArgs(); 3315 } 3316 3317 /// \brief Copies the template arguments (if present) into the given 3318 /// structure. 3319 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 3320 getExplicitTemplateArgs().copyInto(List); 3321 } 3322 3323 /// \brief Initializes the template arguments using the given structure. 3324 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 3325 getExplicitTemplateArgs().initializeFrom(List); 3326 } 3327 3328 /// \brief Retrieve the template arguments provided as part of this 3329 /// template-id. 3330 const TemplateArgumentLoc *getTemplateArgs() const { 3331 return getExplicitTemplateArgs().getTemplateArgs(); 3332 } 3333 3334 /// \brief Retrieve the number of template arguments provided as part of this 3335 /// template-id. 3336 unsigned getNumTemplateArgs() const { 3337 return getExplicitTemplateArgs().NumTemplateArgs; 3338 } 3339 3340 SourceLocation getLocStart() const LLVM_READONLY { 3341 if (!isImplicitAccess()) 3342 return Base->getLocStart(); 3343 if (getQualifier()) 3344 return getQualifierLoc().getBeginLoc(); 3345 return MemberNameInfo.getBeginLoc(); 3346 3347 } 3348 SourceLocation getLocEnd() const LLVM_READONLY { 3349 if (hasExplicitTemplateArgs()) 3350 return getRAngleLoc(); 3351 return MemberNameInfo.getEndLoc(); 3352 } 3353 3354 static bool classof(const Stmt *T) { 3355 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 3356 } 3357 3358 // Iterators 3359 child_range children() { 3360 if (isImplicitAccess()) return child_range(); 3361 return child_range(&Base, &Base + 1); 3362 } 3363 3364 friend class ASTStmtReader; 3365 friend class ASTStmtWriter; 3366}; 3367 3368/// \brief Represents a C++ member access expression for which lookup 3369/// produced a set of overloaded functions. 3370/// 3371/// The member access may be explicit or implicit: 3372/// \code 3373/// struct A { 3374/// int a, b; 3375/// int explicitAccess() { return this->a + this->A::b; } 3376/// int implicitAccess() { return a + A::b; } 3377/// }; 3378/// \endcode 3379/// 3380/// In the final AST, an explicit access always becomes a MemberExpr. 3381/// An implicit access may become either a MemberExpr or a 3382/// DeclRefExpr, depending on whether the member is static. 3383class UnresolvedMemberExpr : public OverloadExpr { 3384 /// \brief Whether this member expression used the '->' operator or 3385 /// the '.' operator. 3386 bool IsArrow : 1; 3387 3388 /// \brief Whether the lookup results contain an unresolved using 3389 /// declaration. 3390 bool HasUnresolvedUsing : 1; 3391 3392 /// \brief The expression for the base pointer or class reference, 3393 /// e.g., the \c x in x.f. 3394 /// 3395 /// This can be null if this is an 'unbased' member expression. 3396 Stmt *Base; 3397 3398 /// \brief The type of the base expression; never null. 3399 QualType BaseType; 3400 3401 /// \brief The location of the '->' or '.' operator. 3402 SourceLocation OperatorLoc; 3403 3404 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 3405 Expr *Base, QualType BaseType, bool IsArrow, 3406 SourceLocation OperatorLoc, 3407 NestedNameSpecifierLoc QualifierLoc, 3408 SourceLocation TemplateKWLoc, 3409 const DeclarationNameInfo &MemberNameInfo, 3410 const TemplateArgumentListInfo *TemplateArgs, 3411 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3412 3413 UnresolvedMemberExpr(EmptyShell Empty) 3414 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 3415 HasUnresolvedUsing(false), Base(0) { } 3416 3417 friend class ASTStmtReader; 3418 3419public: 3420 static UnresolvedMemberExpr * 3421 Create(ASTContext &C, bool HasUnresolvedUsing, 3422 Expr *Base, QualType BaseType, bool IsArrow, 3423 SourceLocation OperatorLoc, 3424 NestedNameSpecifierLoc QualifierLoc, 3425 SourceLocation TemplateKWLoc, 3426 const DeclarationNameInfo &MemberNameInfo, 3427 const TemplateArgumentListInfo *TemplateArgs, 3428 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3429 3430 static UnresolvedMemberExpr * 3431 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3432 unsigned NumTemplateArgs); 3433 3434 /// \brief True if this is an implicit access, i.e., one in which the 3435 /// member being accessed was not written in the source. 3436 /// 3437 /// The source location of the operator is invalid in this case. 3438 bool isImplicitAccess() const; 3439 3440 /// \brief Retrieve the base object of this member expressions, 3441 /// e.g., the \c x in \c x.m. 3442 Expr *getBase() { 3443 assert(!isImplicitAccess()); 3444 return cast<Expr>(Base); 3445 } 3446 const Expr *getBase() const { 3447 assert(!isImplicitAccess()); 3448 return cast<Expr>(Base); 3449 } 3450 3451 QualType getBaseType() const { return BaseType; } 3452 3453 /// \brief Determine whether the lookup results contain an unresolved using 3454 /// declaration. 3455 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3456 3457 /// \brief Determine whether this member expression used the '->' 3458 /// operator; otherwise, it used the '.' operator. 3459 bool isArrow() const { return IsArrow; } 3460 3461 /// \brief Retrieve the location of the '->' or '.' operator. 3462 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3463 3464 /// \brief Retrieve the naming class of this lookup. 3465 CXXRecordDecl *getNamingClass() const; 3466 3467 /// \brief Retrieve the full name info for the member that this expression 3468 /// refers to. 3469 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 3470 3471 /// \brief Retrieve the name of the member that this expression 3472 /// refers to. 3473 DeclarationName getMemberName() const { return getName(); } 3474 3475 // \brief Retrieve the location of the name of the member that this 3476 // expression refers to. 3477 SourceLocation getMemberLoc() const { return getNameLoc(); } 3478 3479 // \brief Return the preferred location (the member name) for the arrow when 3480 // diagnosing a problem with this expression. 3481 SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); } 3482 3483 SourceLocation getLocStart() const LLVM_READONLY { 3484 if (!isImplicitAccess()) 3485 return Base->getLocStart(); 3486 if (NestedNameSpecifierLoc l = getQualifierLoc()) 3487 return l.getBeginLoc(); 3488 return getMemberNameInfo().getLocStart(); 3489 } 3490 SourceLocation getLocEnd() const LLVM_READONLY { 3491 if (hasExplicitTemplateArgs()) 3492 return getRAngleLoc(); 3493 return getMemberNameInfo().getLocEnd(); 3494 } 3495 3496 static bool classof(const Stmt *T) { 3497 return T->getStmtClass() == UnresolvedMemberExprClass; 3498 } 3499 3500 // Iterators 3501 child_range children() { 3502 if (isImplicitAccess()) return child_range(); 3503 return child_range(&Base, &Base + 1); 3504 } 3505}; 3506 3507/// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]). 3508/// 3509/// The noexcept expression tests whether a given expression might throw. Its 3510/// result is a boolean constant. 3511class CXXNoexceptExpr : public Expr { 3512 bool Value : 1; 3513 Stmt *Operand; 3514 SourceRange Range; 3515 3516 friend class ASTStmtReader; 3517 3518public: 3519 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 3520 SourceLocation Keyword, SourceLocation RParen) 3521 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3522 /*TypeDependent*/false, 3523 /*ValueDependent*/Val == CT_Dependent, 3524 Val == CT_Dependent || Operand->isInstantiationDependent(), 3525 Operand->containsUnexpandedParameterPack()), 3526 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 3527 { } 3528 3529 CXXNoexceptExpr(EmptyShell Empty) 3530 : Expr(CXXNoexceptExprClass, Empty) 3531 { } 3532 3533 Expr *getOperand() const { return static_cast<Expr*>(Operand); } 3534 3535 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 3536 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 3537 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 3538 3539 bool getValue() const { return Value; } 3540 3541 static bool classof(const Stmt *T) { 3542 return T->getStmtClass() == CXXNoexceptExprClass; 3543 } 3544 3545 // Iterators 3546 child_range children() { return child_range(&Operand, &Operand + 1); } 3547}; 3548 3549/// \brief Represents a C++11 pack expansion that produces a sequence of 3550/// expressions. 3551/// 3552/// A pack expansion expression contains a pattern (which itself is an 3553/// expression) followed by an ellipsis. For example: 3554/// 3555/// \code 3556/// template<typename F, typename ...Types> 3557/// void forward(F f, Types &&...args) { 3558/// f(static_cast<Types&&>(args)...); 3559/// } 3560/// \endcode 3561/// 3562/// Here, the argument to the function object \c f is a pack expansion whose 3563/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3564/// template is instantiated, the pack expansion will instantiate to zero or 3565/// or more function arguments to the function object \c f. 3566class PackExpansionExpr : public Expr { 3567 SourceLocation EllipsisLoc; 3568 3569 /// \brief The number of expansions that will be produced by this pack 3570 /// expansion expression, if known. 3571 /// 3572 /// When zero, the number of expansions is not known. Otherwise, this value 3573 /// is the number of expansions + 1. 3574 unsigned NumExpansions; 3575 3576 Stmt *Pattern; 3577 3578 friend class ASTStmtReader; 3579 friend class ASTStmtWriter; 3580 3581public: 3582 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 3583 Optional<unsigned> NumExpansions) 3584 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3585 Pattern->getObjectKind(), /*TypeDependent=*/true, 3586 /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3587 /*ContainsUnexpandedParameterPack=*/false), 3588 EllipsisLoc(EllipsisLoc), 3589 NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3590 Pattern(Pattern) { } 3591 3592 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3593 3594 /// \brief Retrieve the pattern of the pack expansion. 3595 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3596 3597 /// \brief Retrieve the pattern of the pack expansion. 3598 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3599 3600 /// \brief Retrieve the location of the ellipsis that describes this pack 3601 /// expansion. 3602 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3603 3604 /// \brief Determine the number of expansions that will be produced when 3605 /// this pack expansion is instantiated, if already known. 3606 Optional<unsigned> getNumExpansions() const { 3607 if (NumExpansions) 3608 return NumExpansions - 1; 3609 3610 return None; 3611 } 3612 3613 SourceLocation getLocStart() const LLVM_READONLY { 3614 return Pattern->getLocStart(); 3615 } 3616 SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; } 3617 3618 static bool classof(const Stmt *T) { 3619 return T->getStmtClass() == PackExpansionExprClass; 3620 } 3621 3622 // Iterators 3623 child_range children() { 3624 return child_range(&Pattern, &Pattern + 1); 3625 } 3626}; 3627 3628inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3629 if (!HasTemplateKWAndArgsInfo) return 0; 3630 if (isa<UnresolvedLookupExpr>(this)) 3631 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3632 (cast<UnresolvedLookupExpr>(this) + 1); 3633 else 3634 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3635 (cast<UnresolvedMemberExpr>(this) + 1); 3636} 3637 3638/// \brief Represents an expression that computes the length of a parameter 3639/// pack. 3640/// 3641/// \code 3642/// template<typename ...Types> 3643/// struct count { 3644/// static const unsigned value = sizeof...(Types); 3645/// }; 3646/// \endcode 3647class SizeOfPackExpr : public Expr { 3648 /// \brief The location of the \c sizeof keyword. 3649 SourceLocation OperatorLoc; 3650 3651 /// \brief The location of the name of the parameter pack. 3652 SourceLocation PackLoc; 3653 3654 /// \brief The location of the closing parenthesis. 3655 SourceLocation RParenLoc; 3656 3657 /// \brief The length of the parameter pack, if known. 3658 /// 3659 /// When this expression is value-dependent, the length of the parameter pack 3660 /// is unknown. When this expression is not value-dependent, the length is 3661 /// known. 3662 unsigned Length; 3663 3664 /// \brief The parameter pack itself. 3665 NamedDecl *Pack; 3666 3667 friend class ASTStmtReader; 3668 friend class ASTStmtWriter; 3669 3670public: 3671 /// \brief Create a value-dependent expression that computes the length of 3672 /// the given parameter pack. 3673 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3674 SourceLocation PackLoc, SourceLocation RParenLoc) 3675 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3676 /*TypeDependent=*/false, /*ValueDependent=*/true, 3677 /*InstantiationDependent=*/true, 3678 /*ContainsUnexpandedParameterPack=*/false), 3679 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3680 Length(0), Pack(Pack) { } 3681 3682 /// \brief Create an expression that computes the length of 3683 /// the given parameter pack, which is already known. 3684 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3685 SourceLocation PackLoc, SourceLocation RParenLoc, 3686 unsigned Length) 3687 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3688 /*TypeDependent=*/false, /*ValueDependent=*/false, 3689 /*InstantiationDependent=*/false, 3690 /*ContainsUnexpandedParameterPack=*/false), 3691 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3692 Length(Length), Pack(Pack) { } 3693 3694 /// \brief Create an empty expression. 3695 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3696 3697 /// \brief Determine the location of the 'sizeof' keyword. 3698 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3699 3700 /// \brief Determine the location of the parameter pack. 3701 SourceLocation getPackLoc() const { return PackLoc; } 3702 3703 /// \brief Determine the location of the right parenthesis. 3704 SourceLocation getRParenLoc() const { return RParenLoc; } 3705 3706 /// \brief Retrieve the parameter pack. 3707 NamedDecl *getPack() const { return Pack; } 3708 3709 /// \brief Retrieve the length of the parameter pack. 3710 /// 3711 /// This routine may only be invoked when the expression is not 3712 /// value-dependent. 3713 unsigned getPackLength() const { 3714 assert(!isValueDependent() && 3715 "Cannot get the length of a value-dependent pack size expression"); 3716 return Length; 3717 } 3718 3719 SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; } 3720 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 3721 3722 static bool classof(const Stmt *T) { 3723 return T->getStmtClass() == SizeOfPackExprClass; 3724 } 3725 3726 // Iterators 3727 child_range children() { return child_range(); } 3728}; 3729 3730/// \brief Represents a reference to a non-type template parameter 3731/// that has been substituted with a template argument. 3732class SubstNonTypeTemplateParmExpr : public Expr { 3733 /// \brief The replaced parameter. 3734 NonTypeTemplateParmDecl *Param; 3735 3736 /// \brief The replacement expression. 3737 Stmt *Replacement; 3738 3739 /// \brief The location of the non-type template parameter reference. 3740 SourceLocation NameLoc; 3741 3742 friend class ASTReader; 3743 friend class ASTStmtReader; 3744 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 3745 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 3746 3747public: 3748 SubstNonTypeTemplateParmExpr(QualType type, 3749 ExprValueKind valueKind, 3750 SourceLocation loc, 3751 NonTypeTemplateParmDecl *param, 3752 Expr *replacement) 3753 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 3754 replacement->isTypeDependent(), replacement->isValueDependent(), 3755 replacement->isInstantiationDependent(), 3756 replacement->containsUnexpandedParameterPack()), 3757 Param(param), Replacement(replacement), NameLoc(loc) {} 3758 3759 SourceLocation getNameLoc() const { return NameLoc; } 3760 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3761 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3762 3763 Expr *getReplacement() const { return cast<Expr>(Replacement); } 3764 3765 NonTypeTemplateParmDecl *getParameter() const { return Param; } 3766 3767 static bool classof(const Stmt *s) { 3768 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 3769 } 3770 3771 // Iterators 3772 child_range children() { return child_range(&Replacement, &Replacement+1); } 3773}; 3774 3775/// \brief Represents a reference to a non-type template parameter pack that 3776/// has been substituted with a non-template argument pack. 3777/// 3778/// When a pack expansion in the source code contains multiple parameter packs 3779/// and those parameter packs correspond to different levels of template 3780/// parameter lists, this node is used to represent a non-type template 3781/// parameter pack from an outer level, which has already had its argument pack 3782/// substituted but that still lives within a pack expansion that itself 3783/// could not be instantiated. When actually performing a substitution into 3784/// that pack expansion (e.g., when all template parameters have corresponding 3785/// arguments), this type will be replaced with the appropriate underlying 3786/// expression at the current pack substitution index. 3787class SubstNonTypeTemplateParmPackExpr : public Expr { 3788 /// \brief The non-type template parameter pack itself. 3789 NonTypeTemplateParmDecl *Param; 3790 3791 /// \brief A pointer to the set of template arguments that this 3792 /// parameter pack is instantiated with. 3793 const TemplateArgument *Arguments; 3794 3795 /// \brief The number of template arguments in \c Arguments. 3796 unsigned NumArguments; 3797 3798 /// \brief The location of the non-type template parameter pack reference. 3799 SourceLocation NameLoc; 3800 3801 friend class ASTReader; 3802 friend class ASTStmtReader; 3803 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 3804 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3805 3806public: 3807 SubstNonTypeTemplateParmPackExpr(QualType T, 3808 NonTypeTemplateParmDecl *Param, 3809 SourceLocation NameLoc, 3810 const TemplateArgument &ArgPack); 3811 3812 /// \brief Retrieve the non-type template parameter pack being substituted. 3813 NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3814 3815 /// \brief Retrieve the location of the parameter pack name. 3816 SourceLocation getParameterPackLocation() const { return NameLoc; } 3817 3818 /// \brief Retrieve the template argument pack containing the substituted 3819 /// template arguments. 3820 TemplateArgument getArgumentPack() const; 3821 3822 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3823 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3824 3825 static bool classof(const Stmt *T) { 3826 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3827 } 3828 3829 // Iterators 3830 child_range children() { return child_range(); } 3831}; 3832 3833/// \brief Represents a reference to a function parameter pack that has been 3834/// substituted but not yet expanded. 3835/// 3836/// When a pack expansion contains multiple parameter packs at different levels, 3837/// this node is used to represent a function parameter pack at an outer level 3838/// which we have already substituted to refer to expanded parameters, but where 3839/// the containing pack expansion cannot yet be expanded. 3840/// 3841/// \code 3842/// template<typename...Ts> struct S { 3843/// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...)); 3844/// }; 3845/// template struct S<int, int>; 3846/// \endcode 3847class FunctionParmPackExpr : public Expr { 3848 /// \brief The function parameter pack which was referenced. 3849 ParmVarDecl *ParamPack; 3850 3851 /// \brief The location of the function parameter pack reference. 3852 SourceLocation NameLoc; 3853 3854 /// \brief The number of expansions of this pack. 3855 unsigned NumParameters; 3856 3857 FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, 3858 SourceLocation NameLoc, unsigned NumParams, 3859 Decl * const *Params); 3860 3861 friend class ASTReader; 3862 friend class ASTStmtReader; 3863 3864public: 3865 static FunctionParmPackExpr *Create(ASTContext &Context, QualType T, 3866 ParmVarDecl *ParamPack, 3867 SourceLocation NameLoc, 3868 ArrayRef<Decl *> Params); 3869 static FunctionParmPackExpr *CreateEmpty(ASTContext &Context, 3870 unsigned NumParams); 3871 3872 /// \brief Get the parameter pack which this expression refers to. 3873 ParmVarDecl *getParameterPack() const { return ParamPack; } 3874 3875 /// \brief Get the location of the parameter pack. 3876 SourceLocation getParameterPackLocation() const { return NameLoc; } 3877 3878 /// \brief Iterators over the parameters which the parameter pack expanded 3879 /// into. 3880 typedef ParmVarDecl * const *iterator; 3881 iterator begin() const { return reinterpret_cast<iterator>(this+1); } 3882 iterator end() const { return begin() + NumParameters; } 3883 3884 /// \brief Get the number of parameters in this parameter pack. 3885 unsigned getNumExpansions() const { return NumParameters; } 3886 3887 /// \brief Get an expansion of the parameter pack by index. 3888 ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; } 3889 3890 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3891 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3892 3893 static bool classof(const Stmt *T) { 3894 return T->getStmtClass() == FunctionParmPackExprClass; 3895 } 3896 3897 child_range children() { return child_range(); } 3898}; 3899 3900/// \brief Represents a prvalue temporary that is written into memory so that 3901/// a reference can bind to it. 3902/// 3903/// Prvalue expressions are materialized when they need to have an address 3904/// in memory for a reference to bind to. This happens when binding a 3905/// reference to the result of a conversion, e.g., 3906/// 3907/// \code 3908/// const int &r = 1.0; 3909/// \endcode 3910/// 3911/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 3912/// then materialized via a \c MaterializeTemporaryExpr, and the reference 3913/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 3914/// (either an lvalue or an xvalue, depending on the kind of reference binding 3915/// to it), maintaining the invariant that references always bind to glvalues. 3916/// 3917/// Reference binding and copy-elision can both extend the lifetime of a 3918/// temporary. When either happens, the expression will also track the 3919/// declaration which is responsible for the lifetime extension. 3920class MaterializeTemporaryExpr : public Expr { 3921public: 3922 /// \brief The temporary-generating expression whose value will be 3923 /// materialized. 3924 Stmt *Temporary; 3925 3926 /// \brief The declaration which lifetime-extended this reference, if any. 3927 /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl. 3928 const ValueDecl *ExtendingDecl; 3929 3930 friend class ASTStmtReader; 3931 friend class ASTStmtWriter; 3932 3933public: 3934 MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3935 bool BoundToLvalueReference, 3936 const ValueDecl *ExtendedBy) 3937 : Expr(MaterializeTemporaryExprClass, T, 3938 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 3939 Temporary->isTypeDependent(), Temporary->isValueDependent(), 3940 Temporary->isInstantiationDependent(), 3941 Temporary->containsUnexpandedParameterPack()), 3942 Temporary(Temporary), ExtendingDecl(ExtendedBy) { 3943 } 3944 3945 MaterializeTemporaryExpr(EmptyShell Empty) 3946 : Expr(MaterializeTemporaryExprClass, Empty) { } 3947 3948 /// \brief Retrieve the temporary-generating subexpression whose value will 3949 /// be materialized into a glvalue. 3950 Expr *GetTemporaryExpr() const { return static_cast<Expr *>(Temporary); } 3951 3952 /// \brief Retrieve the storage duration for the materialized temporary. 3953 StorageDuration getStorageDuration() const { 3954 if (!ExtendingDecl) 3955 return SD_FullExpression; 3956 // FIXME: This is not necessarily correct for a temporary materialized 3957 // within a default initializer. 3958 if (isa<FieldDecl>(ExtendingDecl)) 3959 return SD_Automatic; 3960 return cast<VarDecl>(ExtendingDecl)->getStorageDuration(); 3961 } 3962 3963 /// \brief Get the declaration which triggered the lifetime-extension of this 3964 /// temporary, if any. 3965 const ValueDecl *getExtendingDecl() const { return ExtendingDecl; } 3966 3967 void setExtendingDecl(const ValueDecl *ExtendedBy) { 3968 ExtendingDecl = ExtendedBy; 3969 } 3970 3971 /// \brief Determine whether this materialized temporary is bound to an 3972 /// lvalue reference; otherwise, it's bound to an rvalue reference. 3973 bool isBoundToLvalueReference() const { 3974 return getValueKind() == VK_LValue; 3975 } 3976 3977 SourceLocation getLocStart() const LLVM_READONLY { 3978 return Temporary->getLocStart(); 3979 } 3980 SourceLocation getLocEnd() const LLVM_READONLY { 3981 return Temporary->getLocEnd(); 3982 } 3983 3984 static bool classof(const Stmt *T) { 3985 return T->getStmtClass() == MaterializeTemporaryExprClass; 3986 } 3987 3988 // Iterators 3989 child_range children() { return child_range(&Temporary, &Temporary + 1); } 3990}; 3991 3992} // end namespace clang 3993 3994#endif 3995