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