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