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