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