ExprCXX.h revision f89e55ab1bfb3ea997f8b02997c611a02254eb2d
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/AST/Expr.h" 19#include "clang/AST/UnresolvedSet.h" 20#include "clang/AST/TemplateBase.h" 21 22namespace clang { 23 24 class CXXConstructorDecl; 25 class CXXDestructorDecl; 26 class CXXMethodDecl; 27 class CXXTemporary; 28 class TemplateArgumentListInfo; 29 30//===--------------------------------------------------------------------===// 31// C++ Expressions. 32//===--------------------------------------------------------------------===// 33 34/// \brief A call to an overloaded operator written using operator 35/// syntax. 36/// 37/// Represents a call to an overloaded operator written using operator 38/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 39/// normal call, this AST node provides better information about the 40/// syntactic representation of the call. 41/// 42/// In a C++ template, this expression node kind will be used whenever 43/// any of the arguments are type-dependent. In this case, the 44/// function itself will be a (possibly empty) set of functions and 45/// function templates that were found by name lookup at template 46/// definition time. 47class CXXOperatorCallExpr : public CallExpr { 48 /// \brief The overloaded operator. 49 OverloadedOperatorKind Operator; 50 51public: 52 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 53 Expr **args, unsigned numargs, QualType t, 54 ExprValueKind VK, SourceLocation operatorloc) 55 : CallExpr(C, CXXOperatorCallExprClass, fn, args, numargs, t, VK, 56 operatorloc), 57 Operator(Op) {} 58 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 59 CallExpr(C, CXXOperatorCallExprClass, Empty) { } 60 61 62 /// getOperator - Returns the kind of overloaded operator that this 63 /// expression refers to. 64 OverloadedOperatorKind getOperator() const { return Operator; } 65 void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; } 66 67 /// getOperatorLoc - Returns the location of the operator symbol in 68 /// the expression. When @c getOperator()==OO_Call, this is the 69 /// location of the right parentheses; when @c 70 /// getOperator()==OO_Subscript, this is the location of the right 71 /// bracket. 72 SourceLocation getOperatorLoc() const { return getRParenLoc(); } 73 74 virtual SourceRange getSourceRange() const; 75 76 static bool classof(const Stmt *T) { 77 return T->getStmtClass() == CXXOperatorCallExprClass; 78 } 79 static bool classof(const CXXOperatorCallExpr *) { return true; } 80}; 81 82/// CXXMemberCallExpr - Represents a call to a member function that 83/// may be written either with member call syntax (e.g., "obj.func()" 84/// or "objptr->func()") or with normal function-call syntax 85/// ("func()") within a member function that ends up calling a member 86/// function. The callee in either case is a MemberExpr that contains 87/// both the object argument and the member function, while the 88/// arguments are the arguments within the parentheses (not including 89/// the object argument). 90class CXXMemberCallExpr : public CallExpr { 91public: 92 CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs, 93 QualType t, ExprValueKind VK, SourceLocation RP) 94 : CallExpr(C, CXXMemberCallExprClass, fn, args, numargs, t, VK, RP) {} 95 96 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty) 97 : CallExpr(C, CXXMemberCallExprClass, Empty) { } 98 99 /// getImplicitObjectArgument - Retrieves the implicit object 100 /// argument for the member call. For example, in "x.f(5)", this 101 /// operation would return "x". 102 Expr *getImplicitObjectArgument(); 103 104 /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of 105 /// the implicit object argument. Note that this is may not be the same 106 /// declaration as that of the class context of the CXXMethodDecl which this 107 /// function is calling. 108 /// FIXME: Returns 0 for member pointer call exprs. 109 CXXRecordDecl *getRecordDecl(); 110 111 virtual SourceRange getSourceRange() const; 112 113 static bool classof(const Stmt *T) { 114 return T->getStmtClass() == CXXMemberCallExprClass; 115 } 116 static bool classof(const CXXMemberCallExpr *) { return true; } 117}; 118 119/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 120/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 121/// const_cast. 122/// 123/// This abstract class is inherited by all of the classes 124/// representing "named" casts, e.g., CXXStaticCastExpr, 125/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 126class CXXNamedCastExpr : public ExplicitCastExpr { 127private: 128 SourceLocation Loc; // the location of the casting op 129 130protected: 131 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 132 CastKind kind, Expr *op, unsigned PathSize, 133 TypeSourceInfo *writtenTy, SourceLocation l) 134 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l) {} 135 136 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 137 : ExplicitCastExpr(SC, Shell, PathSize) { } 138 139public: 140 const char *getCastName() const; 141 142 /// \brief Retrieve the location of the cast operator keyword, e.g., 143 /// "static_cast". 144 SourceLocation getOperatorLoc() const { return Loc; } 145 void setOperatorLoc(SourceLocation L) { Loc = L; } 146 147 virtual SourceRange getSourceRange() const { 148 return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); 149 } 150 static bool classof(const Stmt *T) { 151 switch (T->getStmtClass()) { 152 case CXXStaticCastExprClass: 153 case CXXDynamicCastExprClass: 154 case CXXReinterpretCastExprClass: 155 case CXXConstCastExprClass: 156 return true; 157 default: 158 return false; 159 } 160 } 161 static bool classof(const CXXNamedCastExpr *) { return true; } 162}; 163 164/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]). 165/// 166/// This expression node represents a C++ static cast, e.g., 167/// @c static_cast<int>(1.0). 168class CXXStaticCastExpr : public CXXNamedCastExpr { 169 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, 170 unsigned pathSize, TypeSourceInfo *writtenTy, 171 SourceLocation l) 172 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, 173 writtenTy, l) {} 174 175 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize) 176 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { } 177 178public: 179 static CXXStaticCastExpr *Create(ASTContext &Context, QualType T, 180 ExprValueKind VK, CastKind K, Expr *Op, 181 const CXXCastPath *Path, 182 TypeSourceInfo *Written, SourceLocation L); 183 static CXXStaticCastExpr *CreateEmpty(ASTContext &Context, 184 unsigned PathSize); 185 186 static bool classof(const Stmt *T) { 187 return T->getStmtClass() == CXXStaticCastExprClass; 188 } 189 static bool classof(const CXXStaticCastExpr *) { return true; } 190}; 191 192/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 193/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 194/// determine how to perform the type cast. 195/// 196/// This expression node represents a dynamic cast, e.g., 197/// @c dynamic_cast<Derived*>(BasePtr). 198class CXXDynamicCastExpr : public CXXNamedCastExpr { 199 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, 200 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy, 201 SourceLocation l) 202 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, 203 writtenTy, l) {} 204 205 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) 206 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { } 207 208public: 209 static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T, 210 ExprValueKind VK, CastKind Kind, Expr *Op, 211 const CXXCastPath *Path, 212 TypeSourceInfo *Written, SourceLocation L); 213 214 static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context, 215 unsigned pathSize); 216 217 static bool classof(const Stmt *T) { 218 return T->getStmtClass() == CXXDynamicCastExprClass; 219 } 220 static bool classof(const CXXDynamicCastExpr *) { return true; } 221}; 222 223/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 224/// [expr.reinterpret.cast]), which provides a differently-typed view 225/// of a value but performs no actual work at run time. 226/// 227/// This expression node represents a reinterpret cast, e.g., 228/// @c reinterpret_cast<int>(VoidPtr). 229class CXXReinterpretCastExpr : public CXXNamedCastExpr { 230 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, 231 Expr *op, unsigned pathSize, 232 TypeSourceInfo *writtenTy, SourceLocation l) 233 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, 234 pathSize, writtenTy, l) {} 235 236 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) 237 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { } 238 239public: 240 static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T, 241 ExprValueKind VK, CastKind Kind, 242 Expr *Op, const CXXCastPath *Path, 243 TypeSourceInfo *WrittenTy, SourceLocation L); 244 static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context, 245 unsigned pathSize); 246 247 static bool classof(const Stmt *T) { 248 return T->getStmtClass() == CXXReinterpretCastExprClass; 249 } 250 static bool classof(const CXXReinterpretCastExpr *) { return true; } 251}; 252 253/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 254/// which can remove type qualifiers but does not change the underlying value. 255/// 256/// This expression node represents a const cast, e.g., 257/// @c const_cast<char*>(PtrToConstChar). 258class CXXConstCastExpr : public CXXNamedCastExpr { 259 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, 260 TypeSourceInfo *writtenTy, SourceLocation l) 261 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 262 0, writtenTy, l) {} 263 264 explicit CXXConstCastExpr(EmptyShell Empty) 265 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { } 266 267public: 268 static CXXConstCastExpr *Create(ASTContext &Context, QualType T, 269 ExprValueKind VK, Expr *Op, 270 TypeSourceInfo *WrittenTy, SourceLocation L); 271 static CXXConstCastExpr *CreateEmpty(ASTContext &Context); 272 273 static bool classof(const Stmt *T) { 274 return T->getStmtClass() == CXXConstCastExprClass; 275 } 276 static bool classof(const CXXConstCastExpr *) { return true; } 277}; 278 279/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 280/// 281class CXXBoolLiteralExpr : public Expr { 282 bool Value; 283 SourceLocation Loc; 284public: 285 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 286 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false), 287 Value(val), Loc(l) {} 288 289 explicit CXXBoolLiteralExpr(EmptyShell Empty) 290 : Expr(CXXBoolLiteralExprClass, Empty) { } 291 292 bool getValue() const { return Value; } 293 void setValue(bool V) { Value = V; } 294 295 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 296 297 SourceLocation getLocation() const { return Loc; } 298 void setLocation(SourceLocation L) { Loc = L; } 299 300 static bool classof(const Stmt *T) { 301 return T->getStmtClass() == CXXBoolLiteralExprClass; 302 } 303 static bool classof(const CXXBoolLiteralExpr *) { return true; } 304 305 // Iterators 306 virtual child_iterator child_begin(); 307 virtual child_iterator child_end(); 308}; 309 310/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 311class CXXNullPtrLiteralExpr : public Expr { 312 SourceLocation Loc; 313public: 314 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 315 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false), 316 Loc(l) {} 317 318 explicit CXXNullPtrLiteralExpr(EmptyShell Empty) 319 : Expr(CXXNullPtrLiteralExprClass, Empty) { } 320 321 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 322 323 SourceLocation getLocation() const { return Loc; } 324 void setLocation(SourceLocation L) { Loc = L; } 325 326 static bool classof(const Stmt *T) { 327 return T->getStmtClass() == CXXNullPtrLiteralExprClass; 328 } 329 static bool classof(const CXXNullPtrLiteralExpr *) { return true; } 330 331 virtual child_iterator child_begin(); 332 virtual child_iterator child_end(); 333}; 334 335/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 336/// the type_info that corresponds to the supplied type, or the (possibly 337/// dynamic) type of the supplied expression. 338/// 339/// This represents code like @c typeid(int) or @c typeid(*objPtr) 340class CXXTypeidExpr : public Expr { 341private: 342 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 343 SourceRange Range; 344 345public: 346 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 347 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 348 // typeid is never type-dependent (C++ [temp.dep.expr]p4) 349 false, 350 // typeid is value-dependent if the type or expression are dependent 351 Operand->getType()->isDependentType()), 352 Operand(Operand), Range(R) { } 353 354 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) 355 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 356 // typeid is never type-dependent (C++ [temp.dep.expr]p4) 357 false, 358 // typeid is value-dependent if the type or expression are dependent 359 Operand->isTypeDependent() || Operand->isValueDependent()), 360 Operand(Operand), Range(R) { } 361 362 CXXTypeidExpr(EmptyShell Empty, bool isExpr) 363 : Expr(CXXTypeidExprClass, Empty) { 364 if (isExpr) 365 Operand = (Expr*)0; 366 else 367 Operand = (TypeSourceInfo*)0; 368 } 369 370 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 371 372 /// \brief Retrieves the type operand of this typeid() expression after 373 /// various required adjustments (removing reference types, cv-qualifiers). 374 QualType getTypeOperand() const; 375 376 /// \brief Retrieve source information for the type operand. 377 TypeSourceInfo *getTypeOperandSourceInfo() const { 378 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 379 return Operand.get<TypeSourceInfo *>(); 380 } 381 382 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 383 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 384 Operand = TSI; 385 } 386 387 Expr *getExprOperand() const { 388 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 389 return static_cast<Expr*>(Operand.get<Stmt *>()); 390 } 391 392 void setExprOperand(Expr *E) { 393 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 394 Operand = E; 395 } 396 397 virtual SourceRange getSourceRange() const { return Range; } 398 void setSourceRange(SourceRange R) { Range = R; } 399 400 static bool classof(const Stmt *T) { 401 return T->getStmtClass() == CXXTypeidExprClass; 402 } 403 static bool classof(const CXXTypeidExpr *) { return true; } 404 405 // Iterators 406 virtual child_iterator child_begin(); 407 virtual child_iterator child_end(); 408}; 409 410/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets 411/// the _GUID that corresponds to the supplied type or expression. 412/// 413/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) 414class CXXUuidofExpr : public Expr { 415private: 416 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 417 SourceRange Range; 418 419public: 420 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 421 : Expr(CXXUuidofExprClass, Ty, VK_RValue, OK_Ordinary, 422 false, Operand->getType()->isDependentType()), 423 Operand(Operand), Range(R) { } 424 425 CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R) 426 : Expr(CXXUuidofExprClass, Ty, /*FIXME*/ VK_LValue, OK_Ordinary, 427 false, Operand->isTypeDependent()), 428 Operand(Operand), Range(R) { } 429 430 CXXUuidofExpr(EmptyShell Empty, bool isExpr) 431 : Expr(CXXUuidofExprClass, Empty) { 432 if (isExpr) 433 Operand = (Expr*)0; 434 else 435 Operand = (TypeSourceInfo*)0; 436 } 437 438 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 439 440 /// \brief Retrieves the type operand of this __uuidof() expression after 441 /// various required adjustments (removing reference types, cv-qualifiers). 442 QualType getTypeOperand() const; 443 444 /// \brief Retrieve source information for the type operand. 445 TypeSourceInfo *getTypeOperandSourceInfo() const { 446 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 447 return Operand.get<TypeSourceInfo *>(); 448 } 449 450 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 451 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 452 Operand = TSI; 453 } 454 455 Expr *getExprOperand() const { 456 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 457 return static_cast<Expr*>(Operand.get<Stmt *>()); 458 } 459 460 void setExprOperand(Expr *E) { 461 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 462 Operand = E; 463 } 464 465 virtual SourceRange getSourceRange() const { return Range; } 466 void setSourceRange(SourceRange R) { Range = R; } 467 468 static bool classof(const Stmt *T) { 469 return T->getStmtClass() == CXXUuidofExprClass; 470 } 471 static bool classof(const CXXUuidofExpr *) { return true; } 472 473 // Iterators 474 virtual child_iterator child_begin(); 475 virtual child_iterator child_end(); 476}; 477 478/// CXXThisExpr - Represents the "this" expression in C++, which is a 479/// pointer to the object on which the current member function is 480/// executing (C++ [expr.prim]p3). Example: 481/// 482/// @code 483/// class Foo { 484/// public: 485/// void bar(); 486/// void test() { this->bar(); } 487/// }; 488/// @endcode 489class CXXThisExpr : public Expr { 490 SourceLocation Loc; 491 bool Implicit : 1; 492 493public: 494 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 495 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, 496 // 'this' is type-dependent if the class type of the enclosing 497 // member function is dependent (C++ [temp.dep.expr]p2) 498 Type->isDependentType(), Type->isDependentType()), 499 Loc(L), Implicit(isImplicit) { } 500 501 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} 502 503 SourceLocation getLocation() const { return Loc; } 504 void setLocation(SourceLocation L) { Loc = L; } 505 506 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 507 508 bool isImplicit() const { return Implicit; } 509 void setImplicit(bool I) { Implicit = I; } 510 511 static bool classof(const Stmt *T) { 512 return T->getStmtClass() == CXXThisExprClass; 513 } 514 static bool classof(const CXXThisExpr *) { return true; } 515 516 // Iterators 517 virtual child_iterator child_begin(); 518 virtual child_iterator child_end(); 519}; 520 521/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 522/// 'throw' and 'throw' assignment-expression. When 523/// assignment-expression isn't present, Op will be null. 524/// 525class CXXThrowExpr : public Expr { 526 Stmt *Op; 527 SourceLocation ThrowLoc; 528public: 529 // Ty is the void type which is used as the result type of the 530 // exepression. The l is the location of the throw keyword. expr 531 // can by null, if the optional expression to throw isn't present. 532 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) : 533 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false), 534 Op(expr), ThrowLoc(l) {} 535 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} 536 537 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 538 Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 539 void setSubExpr(Expr *E) { Op = E; } 540 541 SourceLocation getThrowLoc() const { return ThrowLoc; } 542 void setThrowLoc(SourceLocation L) { ThrowLoc = L; } 543 544 virtual SourceRange getSourceRange() const { 545 if (getSubExpr() == 0) 546 return SourceRange(ThrowLoc, ThrowLoc); 547 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 548 } 549 550 static bool classof(const Stmt *T) { 551 return T->getStmtClass() == CXXThrowExprClass; 552 } 553 static bool classof(const CXXThrowExpr *) { return true; } 554 555 // Iterators 556 virtual child_iterator child_begin(); 557 virtual child_iterator child_end(); 558}; 559 560/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 561/// function call argument that was created from the corresponding 562/// parameter's default argument, when the call did not explicitly 563/// supply arguments for all of the parameters. 564class CXXDefaultArgExpr : public Expr { 565 /// \brief The parameter whose default is being used. 566 /// 567 /// When the bit is set, the subexpression is stored after the 568 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 569 /// actual default expression is the subexpression. 570 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 571 572 /// \brief The location where the default argument expression was used. 573 SourceLocation Loc; 574 575 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 576 : Expr(SC, 577 param->hasUnparsedDefaultArg() 578 ? param->getType().getNonReferenceType() 579 : param->getDefaultArg()->getType(), 580 getValueKindForType(param->getType()), OK_Ordinary, false, false), 581 Param(param, false), Loc(Loc) { } 582 583 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 584 Expr *SubExpr) 585 : Expr(SC, SubExpr->getType(), SubExpr->getValueKind(), OK_Ordinary, 586 false, false), Param(param, true), Loc(Loc) { 587 *reinterpret_cast<Expr **>(this + 1) = SubExpr; 588 } 589 590public: 591 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} 592 593 594 // Param is the parameter whose default argument is used by this 595 // expression. 596 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc, 597 ParmVarDecl *Param) { 598 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 599 } 600 601 // Param is the parameter whose default argument is used by this 602 // expression, and SubExpr is the expression that will actually be used. 603 static CXXDefaultArgExpr *Create(ASTContext &C, 604 SourceLocation Loc, 605 ParmVarDecl *Param, 606 Expr *SubExpr); 607 608 // Retrieve the parameter that the argument was created from. 609 const ParmVarDecl *getParam() const { return Param.getPointer(); } 610 ParmVarDecl *getParam() { return Param.getPointer(); } 611 612 // Retrieve the actual argument to the function call. 613 const Expr *getExpr() const { 614 if (Param.getInt()) 615 return *reinterpret_cast<Expr const * const*> (this + 1); 616 return getParam()->getDefaultArg(); 617 } 618 Expr *getExpr() { 619 if (Param.getInt()) 620 return *reinterpret_cast<Expr **> (this + 1); 621 return getParam()->getDefaultArg(); 622 } 623 624 /// \brief Retrieve the location where this default argument was actually 625 /// used. 626 SourceLocation getUsedLocation() const { return Loc; } 627 628 virtual SourceRange getSourceRange() const { 629 // Default argument expressions have no representation in the 630 // source, so they have an empty source range. 631 return SourceRange(); 632 } 633 634 static bool classof(const Stmt *T) { 635 return T->getStmtClass() == CXXDefaultArgExprClass; 636 } 637 static bool classof(const CXXDefaultArgExpr *) { return true; } 638 639 // Iterators 640 virtual child_iterator child_begin(); 641 virtual child_iterator child_end(); 642 643 friend class ASTStmtReader; 644 friend class ASTStmtWriter; 645}; 646 647/// CXXTemporary - Represents a C++ temporary. 648class CXXTemporary { 649 /// Destructor - The destructor that needs to be called. 650 const CXXDestructorDecl *Destructor; 651 652 CXXTemporary(const CXXDestructorDecl *destructor) 653 : Destructor(destructor) { } 654 655public: 656 static CXXTemporary *Create(ASTContext &C, 657 const CXXDestructorDecl *Destructor); 658 659 const CXXDestructorDecl *getDestructor() const { return Destructor; } 660}; 661 662/// \brief Represents binding an expression to a temporary. 663/// 664/// This ensures the destructor is called for the temporary. It should only be 665/// needed for non-POD, non-trivially destructable class types. For example: 666/// 667/// \code 668/// struct S { 669/// S() { } // User defined constructor makes S non-POD. 670/// ~S() { } // User defined destructor makes it non-trivial. 671/// }; 672/// void test() { 673/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 674/// } 675/// \endcode 676class CXXBindTemporaryExpr : public Expr { 677 CXXTemporary *Temp; 678 679 Stmt *SubExpr; 680 681 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr, 682 bool TD=false, bool VD=false) 683 : Expr(CXXBindTemporaryExprClass, subexpr->getType(), 684 VK_RValue, OK_Ordinary, TD, VD), 685 Temp(temp), SubExpr(subexpr) { } 686 687public: 688 CXXBindTemporaryExpr(EmptyShell Empty) 689 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 690 691 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 692 Expr* SubExpr); 693 694 CXXTemporary *getTemporary() { return Temp; } 695 const CXXTemporary *getTemporary() const { return Temp; } 696 void setTemporary(CXXTemporary *T) { Temp = T; } 697 698 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 699 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 700 void setSubExpr(Expr *E) { SubExpr = E; } 701 702 virtual SourceRange getSourceRange() const { 703 return SubExpr->getSourceRange(); 704 } 705 706 // Implement isa/cast/dyncast/etc. 707 static bool classof(const Stmt *T) { 708 return T->getStmtClass() == CXXBindTemporaryExprClass; 709 } 710 static bool classof(const CXXBindTemporaryExpr *) { return true; } 711 712 // Iterators 713 virtual child_iterator child_begin(); 714 virtual child_iterator child_end(); 715}; 716 717/// CXXConstructExpr - Represents a call to a C++ constructor. 718class CXXConstructExpr : public Expr { 719public: 720 enum ConstructionKind { 721 CK_Complete, 722 CK_NonVirtualBase, 723 CK_VirtualBase 724 }; 725 726private: 727 CXXConstructorDecl *Constructor; 728 729 SourceLocation Loc; 730 SourceRange ParenRange; 731 bool Elidable : 1; 732 bool ZeroInitialization : 1; 733 unsigned ConstructKind : 2; 734 Stmt **Args; 735 unsigned NumArgs; 736 737protected: 738 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 739 SourceLocation Loc, 740 CXXConstructorDecl *d, bool elidable, 741 Expr **args, unsigned numargs, 742 bool ZeroInitialization = false, 743 ConstructionKind ConstructKind = CK_Complete, 744 SourceRange ParenRange = SourceRange()); 745 746 /// \brief Construct an empty C++ construction expression. 747 CXXConstructExpr(StmtClass SC, EmptyShell Empty) 748 : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0), 749 ConstructKind(0), Args(0), NumArgs(0) { } 750 751public: 752 /// \brief Construct an empty C++ construction expression. 753 explicit CXXConstructExpr(EmptyShell Empty) 754 : Expr(CXXConstructExprClass, Empty), Constructor(0), 755 Elidable(0), ZeroInitialization(0), 756 ConstructKind(0), Args(0), NumArgs(0) { } 757 758 static CXXConstructExpr *Create(ASTContext &C, QualType T, 759 SourceLocation Loc, 760 CXXConstructorDecl *D, bool Elidable, 761 Expr **Args, unsigned NumArgs, 762 bool ZeroInitialization = false, 763 ConstructionKind ConstructKind = CK_Complete, 764 SourceRange ParenRange = SourceRange()); 765 766 767 CXXConstructorDecl* getConstructor() const { return Constructor; } 768 void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 769 770 SourceLocation getLocation() const { return Loc; } 771 void setLocation(SourceLocation Loc) { this->Loc = Loc; } 772 773 /// \brief Whether this construction is elidable. 774 bool isElidable() const { return Elidable; } 775 void setElidable(bool E) { Elidable = E; } 776 777 /// \brief Whether this construction first requires 778 /// zero-initialization before the initializer is called. 779 bool requiresZeroInitialization() const { return ZeroInitialization; } 780 void setRequiresZeroInitialization(bool ZeroInit) { 781 ZeroInitialization = ZeroInit; 782 } 783 784 /// \brief Determines whether this constructor is actually constructing 785 /// a base class (rather than a complete object). 786 ConstructionKind getConstructionKind() const { 787 return (ConstructionKind)ConstructKind; 788 } 789 void setConstructionKind(ConstructionKind CK) { 790 ConstructKind = CK; 791 } 792 793 typedef ExprIterator arg_iterator; 794 typedef ConstExprIterator const_arg_iterator; 795 796 arg_iterator arg_begin() { return Args; } 797 arg_iterator arg_end() { return Args + NumArgs; } 798 const_arg_iterator arg_begin() const { return Args; } 799 const_arg_iterator arg_end() const { return Args + NumArgs; } 800 801 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 802 unsigned getNumArgs() const { return NumArgs; } 803 804 /// getArg - Return the specified argument. 805 Expr *getArg(unsigned Arg) { 806 assert(Arg < NumArgs && "Arg access out of range!"); 807 return cast<Expr>(Args[Arg]); 808 } 809 const Expr *getArg(unsigned Arg) const { 810 assert(Arg < NumArgs && "Arg access out of range!"); 811 return cast<Expr>(Args[Arg]); 812 } 813 814 /// setArg - Set the specified argument. 815 void setArg(unsigned Arg, Expr *ArgExpr) { 816 assert(Arg < NumArgs && "Arg access out of range!"); 817 Args[Arg] = ArgExpr; 818 } 819 820 virtual SourceRange getSourceRange() const; 821 SourceRange getParenRange() const { return ParenRange; } 822 823 static bool classof(const Stmt *T) { 824 return T->getStmtClass() == CXXConstructExprClass || 825 T->getStmtClass() == CXXTemporaryObjectExprClass; 826 } 827 static bool classof(const CXXConstructExpr *) { return true; } 828 829 // Iterators 830 virtual child_iterator child_begin(); 831 virtual child_iterator child_end(); 832 833 friend class ASTStmtReader; 834}; 835 836/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 837/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 838/// x = int(0.5); 839class CXXFunctionalCastExpr : public ExplicitCastExpr { 840 SourceLocation TyBeginLoc; 841 SourceLocation RParenLoc; 842 843 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 844 TypeSourceInfo *writtenTy, 845 SourceLocation tyBeginLoc, CastKind kind, 846 Expr *castExpr, unsigned pathSize, 847 SourceLocation rParenLoc) 848 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 849 castExpr, pathSize, writtenTy), 850 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 851 852 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 853 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 854 855public: 856 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T, 857 ExprValueKind VK, 858 TypeSourceInfo *Written, 859 SourceLocation TyBeginLoc, 860 CastKind Kind, Expr *Op, 861 const CXXCastPath *Path, 862 SourceLocation RPLoc); 863 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context, 864 unsigned PathSize); 865 866 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 867 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 868 SourceLocation getRParenLoc() const { return RParenLoc; } 869 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 870 871 virtual SourceRange getSourceRange() const { 872 return SourceRange(TyBeginLoc, RParenLoc); 873 } 874 static bool classof(const Stmt *T) { 875 return T->getStmtClass() == CXXFunctionalCastExprClass; 876 } 877 static bool classof(const CXXFunctionalCastExpr *) { return true; } 878}; 879 880/// @brief Represents a C++ functional cast expression that builds a 881/// temporary object. 882/// 883/// This expression type represents a C++ "functional" cast 884/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 885/// constructor to build a temporary object. With N == 1 arguments the 886/// functional cast expression will be represented by CXXFunctionalCastExpr. 887/// Example: 888/// @code 889/// struct X { X(int, float); } 890/// 891/// X create_X() { 892/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 893/// }; 894/// @endcode 895class CXXTemporaryObjectExpr : public CXXConstructExpr { 896 TypeSourceInfo *Type; 897 898public: 899 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 900 TypeSourceInfo *Type, 901 Expr **Args,unsigned NumArgs, 902 SourceRange parenRange, 903 bool ZeroInitialization = false); 904 explicit CXXTemporaryObjectExpr(EmptyShell Empty) 905 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 906 907 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 908 909 virtual SourceRange getSourceRange() const; 910 911 static bool classof(const Stmt *T) { 912 return T->getStmtClass() == CXXTemporaryObjectExprClass; 913 } 914 static bool classof(const CXXTemporaryObjectExpr *) { return true; } 915 916 friend class ASTStmtReader; 917}; 918 919/// CXXScalarValueInitExpr - [C++ 5.2.3p2] 920/// Expression "T()" which creates a value-initialized rvalue of type 921/// T, which is a non-class type. 922/// 923class CXXScalarValueInitExpr : public Expr { 924 SourceLocation RParenLoc; 925 TypeSourceInfo *TypeInfo; 926 927 friend class ASTStmtReader; 928 929public: 930 /// \brief Create an explicitly-written scalar-value initialization 931 /// expression. 932 CXXScalarValueInitExpr(QualType Type, 933 TypeSourceInfo *TypeInfo, 934 SourceLocation rParenLoc ) : 935 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 936 false, false), 937 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 938 939 explicit CXXScalarValueInitExpr(EmptyShell Shell) 940 : Expr(CXXScalarValueInitExprClass, Shell) { } 941 942 TypeSourceInfo *getTypeSourceInfo() const { 943 return TypeInfo; 944 } 945 946 SourceLocation getRParenLoc() const { return RParenLoc; } 947 948 virtual SourceRange getSourceRange() const; 949 950 static bool classof(const Stmt *T) { 951 return T->getStmtClass() == CXXScalarValueInitExprClass; 952 } 953 static bool classof(const CXXScalarValueInitExpr *) { return true; } 954 955 // Iterators 956 virtual child_iterator child_begin(); 957 virtual child_iterator child_end(); 958}; 959 960/// CXXNewExpr - A new expression for memory allocation and constructor calls, 961/// e.g: "new CXXNewExpr(foo)". 962class CXXNewExpr : public Expr { 963 // Was the usage ::new, i.e. is the global new to be used? 964 bool GlobalNew : 1; 965 // Is there an initializer? If not, built-ins are uninitialized, else they're 966 // value-initialized. 967 bool Initializer : 1; 968 // Do we allocate an array? If so, the first SubExpr is the size expression. 969 bool Array : 1; 970 // The number of placement new arguments. 971 unsigned NumPlacementArgs : 15; 972 // The number of constructor arguments. This may be 1 even for non-class 973 // types; use the pseudo copy constructor. 974 unsigned NumConstructorArgs : 14; 975 // Contains an optional array size expression, any number of optional 976 // placement arguments, and any number of optional constructor arguments, 977 // in that order. 978 Stmt **SubExprs; 979 // Points to the allocation function used. 980 FunctionDecl *OperatorNew; 981 // Points to the deallocation function used in case of error. May be null. 982 FunctionDecl *OperatorDelete; 983 // Points to the constructor used. Cannot be null if AllocType is a record; 984 // it would still point at the default constructor (even an implicit one). 985 // Must be null for all other types. 986 CXXConstructorDecl *Constructor; 987 988 /// \brief The allocated type-source information, as written in the source. 989 TypeSourceInfo *AllocatedTypeInfo; 990 991 /// \brief If the allocated type was expressed as a parenthesized type-id, 992 /// the source range covering the parenthesized type-id. 993 SourceRange TypeIdParens; 994 995 SourceLocation StartLoc; 996 SourceLocation EndLoc; 997 SourceLocation ConstructorLParen; 998 SourceLocation ConstructorRParen; 999 1000 friend class ASTStmtReader; 1001public: 1002 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 1003 Expr **placementArgs, unsigned numPlaceArgs, 1004 SourceRange TypeIdParens, 1005 Expr *arraySize, CXXConstructorDecl *constructor, bool initializer, 1006 Expr **constructorArgs, unsigned numConsArgs, 1007 FunctionDecl *operatorDelete, QualType ty, 1008 TypeSourceInfo *AllocatedTypeInfo, 1009 SourceLocation startLoc, SourceLocation endLoc, 1010 SourceLocation constructorLParen, 1011 SourceLocation constructorRParen); 1012 explicit CXXNewExpr(EmptyShell Shell) 1013 : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 1014 1015 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs, 1016 unsigned numConsArgs); 1017 1018 QualType getAllocatedType() const { 1019 assert(getType()->isPointerType()); 1020 return getType()->getAs<PointerType>()->getPointeeType(); 1021 } 1022 1023 TypeSourceInfo *getAllocatedTypeSourceInfo() const { 1024 return AllocatedTypeInfo; 1025 } 1026 1027 FunctionDecl *getOperatorNew() const { return OperatorNew; } 1028 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 1029 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1030 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 1031 CXXConstructorDecl *getConstructor() const { return Constructor; } 1032 void setConstructor(CXXConstructorDecl *D) { Constructor = D; } 1033 1034 bool isArray() const { return Array; } 1035 Expr *getArraySize() { 1036 return Array ? cast<Expr>(SubExprs[0]) : 0; 1037 } 1038 const Expr *getArraySize() const { 1039 return Array ? cast<Expr>(SubExprs[0]) : 0; 1040 } 1041 1042 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1043 Expr *getPlacementArg(unsigned i) { 1044 assert(i < NumPlacementArgs && "Index out of range"); 1045 return cast<Expr>(SubExprs[Array + i]); 1046 } 1047 const Expr *getPlacementArg(unsigned i) const { 1048 assert(i < NumPlacementArgs && "Index out of range"); 1049 return cast<Expr>(SubExprs[Array + i]); 1050 } 1051 1052 bool isParenTypeId() const { return TypeIdParens.isValid(); } 1053 SourceRange getTypeIdParens() const { return TypeIdParens; } 1054 1055 bool isGlobalNew() const { return GlobalNew; } 1056 void setGlobalNew(bool V) { GlobalNew = V; } 1057 bool hasInitializer() const { return Initializer; } 1058 void setHasInitializer(bool V) { Initializer = V; } 1059 1060 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 1061 Expr *getConstructorArg(unsigned i) { 1062 assert(i < NumConstructorArgs && "Index out of range"); 1063 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 1064 } 1065 const Expr *getConstructorArg(unsigned i) const { 1066 assert(i < NumConstructorArgs && "Index out of range"); 1067 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 1068 } 1069 1070 typedef ExprIterator arg_iterator; 1071 typedef ConstExprIterator const_arg_iterator; 1072 1073 arg_iterator placement_arg_begin() { 1074 return SubExprs + Array; 1075 } 1076 arg_iterator placement_arg_end() { 1077 return SubExprs + Array + getNumPlacementArgs(); 1078 } 1079 const_arg_iterator placement_arg_begin() const { 1080 return SubExprs + Array; 1081 } 1082 const_arg_iterator placement_arg_end() const { 1083 return SubExprs + Array + getNumPlacementArgs(); 1084 } 1085 1086 arg_iterator constructor_arg_begin() { 1087 return SubExprs + Array + getNumPlacementArgs(); 1088 } 1089 arg_iterator constructor_arg_end() { 1090 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1091 } 1092 const_arg_iterator constructor_arg_begin() const { 1093 return SubExprs + Array + getNumPlacementArgs(); 1094 } 1095 const_arg_iterator constructor_arg_end() const { 1096 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1097 } 1098 1099 typedef Stmt **raw_arg_iterator; 1100 raw_arg_iterator raw_arg_begin() { return SubExprs; } 1101 raw_arg_iterator raw_arg_end() { 1102 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1103 } 1104 const_arg_iterator raw_arg_begin() const { return SubExprs; } 1105 const_arg_iterator raw_arg_end() const { return constructor_arg_end(); } 1106 1107 SourceLocation getStartLoc() const { return StartLoc; } 1108 SourceLocation getEndLoc() const { return EndLoc; } 1109 1110 SourceLocation getConstructorLParen() const { return ConstructorLParen; } 1111 SourceLocation getConstructorRParen() const { return ConstructorRParen; } 1112 1113 virtual SourceRange getSourceRange() const { 1114 return SourceRange(StartLoc, EndLoc); 1115 } 1116 1117 static bool classof(const Stmt *T) { 1118 return T->getStmtClass() == CXXNewExprClass; 1119 } 1120 static bool classof(const CXXNewExpr *) { return true; } 1121 1122 // Iterators 1123 virtual child_iterator child_begin(); 1124 virtual child_iterator child_end(); 1125}; 1126 1127/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 1128/// calls, e.g. "delete[] pArray". 1129class CXXDeleteExpr : public Expr { 1130 // Is this a forced global delete, i.e. "::delete"? 1131 bool GlobalDelete : 1; 1132 // Is this the array form of delete, i.e. "delete[]"? 1133 bool ArrayForm : 1; 1134 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 1135 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 1136 // will be true). 1137 bool ArrayFormAsWritten : 1; 1138 // Points to the operator delete overload that is used. Could be a member. 1139 FunctionDecl *OperatorDelete; 1140 // The pointer expression to be deleted. 1141 Stmt *Argument; 1142 // Location of the expression. 1143 SourceLocation Loc; 1144public: 1145 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 1146 bool arrayFormAsWritten, FunctionDecl *operatorDelete, 1147 Expr *arg, SourceLocation loc) 1148 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false), 1149 GlobalDelete(globalDelete), 1150 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 1151 OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { } 1152 explicit CXXDeleteExpr(EmptyShell Shell) 1153 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 1154 1155 bool isGlobalDelete() const { return GlobalDelete; } 1156 bool isArrayForm() const { return ArrayForm; } 1157 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 1158 1159 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1160 1161 Expr *getArgument() { return cast<Expr>(Argument); } 1162 const Expr *getArgument() const { return cast<Expr>(Argument); } 1163 1164 /// \brief Retrieve the type being destroyed. If the type being 1165 /// destroyed is a dependent type which may or may not be a pointer, 1166 /// return an invalid type. 1167 QualType getDestroyedType() const; 1168 1169 virtual SourceRange getSourceRange() const { 1170 return SourceRange(Loc, Argument->getLocEnd()); 1171 } 1172 1173 static bool classof(const Stmt *T) { 1174 return T->getStmtClass() == CXXDeleteExprClass; 1175 } 1176 static bool classof(const CXXDeleteExpr *) { return true; } 1177 1178 // Iterators 1179 virtual child_iterator child_begin(); 1180 virtual child_iterator child_end(); 1181 1182 friend class ASTStmtReader; 1183}; 1184 1185/// \brief Structure used to store the type being destroyed by a 1186/// pseudo-destructor expression. 1187class PseudoDestructorTypeStorage { 1188 /// \brief Either the type source information or the name of the type, if 1189 /// it couldn't be resolved due to type-dependence. 1190 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1191 1192 /// \brief The starting source location of the pseudo-destructor type. 1193 SourceLocation Location; 1194 1195public: 1196 PseudoDestructorTypeStorage() { } 1197 1198 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1199 : Type(II), Location(Loc) { } 1200 1201 PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1202 1203 TypeSourceInfo *getTypeSourceInfo() const { 1204 return Type.dyn_cast<TypeSourceInfo *>(); 1205 } 1206 1207 IdentifierInfo *getIdentifier() const { 1208 return Type.dyn_cast<IdentifierInfo *>(); 1209 } 1210 1211 SourceLocation getLocation() const { return Location; } 1212}; 1213 1214/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1215/// 1216/// A pseudo-destructor is an expression that looks like a member access to a 1217/// destructor of a scalar type, except that scalar types don't have 1218/// destructors. For example: 1219/// 1220/// \code 1221/// typedef int T; 1222/// void f(int *p) { 1223/// p->T::~T(); 1224/// } 1225/// \endcode 1226/// 1227/// Pseudo-destructors typically occur when instantiating templates such as: 1228/// 1229/// \code 1230/// template<typename T> 1231/// void destroy(T* ptr) { 1232/// ptr->T::~T(); 1233/// } 1234/// \endcode 1235/// 1236/// for scalar types. A pseudo-destructor expression has no run-time semantics 1237/// beyond evaluating the base expression. 1238class CXXPseudoDestructorExpr : public Expr { 1239 /// \brief The base expression (that is being destroyed). 1240 Stmt *Base; 1241 1242 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1243 /// period ('.'). 1244 bool IsArrow : 1; 1245 1246 /// \brief The location of the '.' or '->' operator. 1247 SourceLocation OperatorLoc; 1248 1249 /// \brief The nested-name-specifier that follows the operator, if present. 1250 NestedNameSpecifier *Qualifier; 1251 1252 /// \brief The source range that covers the nested-name-specifier, if 1253 /// present. 1254 SourceRange QualifierRange; 1255 1256 /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1257 /// expression. 1258 TypeSourceInfo *ScopeType; 1259 1260 /// \brief The location of the '::' in a qualified pseudo-destructor 1261 /// expression. 1262 SourceLocation ColonColonLoc; 1263 1264 /// \brief The location of the '~'. 1265 SourceLocation TildeLoc; 1266 1267 /// \brief The type being destroyed, or its name if we were unable to 1268 /// resolve the name. 1269 PseudoDestructorTypeStorage DestroyedType; 1270 1271public: 1272 CXXPseudoDestructorExpr(ASTContext &Context, 1273 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1274 NestedNameSpecifier *Qualifier, 1275 SourceRange QualifierRange, 1276 TypeSourceInfo *ScopeType, 1277 SourceLocation ColonColonLoc, 1278 SourceLocation TildeLoc, 1279 PseudoDestructorTypeStorage DestroyedType) 1280 : Expr(CXXPseudoDestructorExprClass, 1281 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, 1282 false, 0, false, 1283 false, 0, 0, 1284 FunctionType::ExtInfo())), 1285 VK_RValue, OK_Ordinary, 1286 /*isTypeDependent=*/(Base->isTypeDependent() || 1287 (DestroyedType.getTypeSourceInfo() && 1288 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())), 1289 /*isValueDependent=*/Base->isValueDependent()), 1290 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), 1291 OperatorLoc(OperatorLoc), Qualifier(Qualifier), 1292 QualifierRange(QualifierRange), 1293 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), 1294 DestroyedType(DestroyedType) { } 1295 1296 explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1297 : Expr(CXXPseudoDestructorExprClass, Shell), 1298 Base(0), IsArrow(false), Qualifier(0), ScopeType(0) { } 1299 1300 void setBase(Expr *E) { Base = E; } 1301 Expr *getBase() const { return cast<Expr>(Base); } 1302 1303 /// \brief Determines whether this member expression actually had 1304 /// a C++ nested-name-specifier prior to the name of the member, e.g., 1305 /// x->Base::foo. 1306 bool hasQualifier() const { return Qualifier != 0; } 1307 1308 /// \brief If the member name was qualified, retrieves the source range of 1309 /// the nested-name-specifier that precedes the member name. Otherwise, 1310 /// returns an empty source range. 1311 SourceRange getQualifierRange() const { return QualifierRange; } 1312 void setQualifierRange(SourceRange R) { QualifierRange = R; } 1313 1314 /// \brief If the member name was qualified, retrieves the 1315 /// nested-name-specifier that precedes the member name. Otherwise, returns 1316 /// NULL. 1317 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1318 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1319 1320 /// \brief Determine whether this pseudo-destructor expression was written 1321 /// using an '->' (otherwise, it used a '.'). 1322 bool isArrow() const { return IsArrow; } 1323 void setArrow(bool A) { IsArrow = A; } 1324 1325 /// \brief Retrieve the location of the '.' or '->' operator. 1326 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1327 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1328 1329 /// \brief Retrieve the scope type in a qualified pseudo-destructor 1330 /// expression. 1331 /// 1332 /// Pseudo-destructor expressions can have extra qualification within them 1333 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1334 /// Here, if the object type of the expression is (or may be) a scalar type, 1335 /// \p T may also be a scalar type and, therefore, cannot be part of a 1336 /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1337 /// destructor expression. 1338 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1339 void setScopeTypeInfo(TypeSourceInfo *Info) { ScopeType = Info; } 1340 1341 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1342 /// expression. 1343 SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1344 void setColonColonLoc(SourceLocation L) { ColonColonLoc = L; } 1345 1346 /// \brief Retrieve the location of the '~'. 1347 SourceLocation getTildeLoc() const { return TildeLoc; } 1348 void setTildeLoc(SourceLocation L) { TildeLoc = L; } 1349 1350 /// \brief Retrieve the source location information for the type 1351 /// being destroyed. 1352 /// 1353 /// This type-source information is available for non-dependent 1354 /// pseudo-destructor expressions and some dependent pseudo-destructor 1355 /// expressions. Returns NULL if we only have the identifier for a 1356 /// dependent pseudo-destructor expression. 1357 TypeSourceInfo *getDestroyedTypeInfo() const { 1358 return DestroyedType.getTypeSourceInfo(); 1359 } 1360 1361 /// \brief In a dependent pseudo-destructor expression for which we do not 1362 /// have full type information on the destroyed type, provides the name 1363 /// of the destroyed type. 1364 IdentifierInfo *getDestroyedTypeIdentifier() const { 1365 return DestroyedType.getIdentifier(); 1366 } 1367 1368 /// \brief Retrieve the type being destroyed. 1369 QualType getDestroyedType() const; 1370 1371 /// \brief Retrieve the starting location of the type being destroyed. 1372 SourceLocation getDestroyedTypeLoc() const { 1373 return DestroyedType.getLocation(); 1374 } 1375 1376 /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1377 /// expression. 1378 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1379 DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1380 } 1381 1382 /// \brief Set the destroyed type. 1383 void setDestroyedType(TypeSourceInfo *Info) { 1384 DestroyedType = PseudoDestructorTypeStorage(Info); 1385 } 1386 1387 virtual SourceRange getSourceRange() const; 1388 1389 static bool classof(const Stmt *T) { 1390 return T->getStmtClass() == CXXPseudoDestructorExprClass; 1391 } 1392 static bool classof(const CXXPseudoDestructorExpr *) { return true; } 1393 1394 // Iterators 1395 virtual child_iterator child_begin(); 1396 virtual child_iterator child_end(); 1397}; 1398 1399/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 1400/// implementation of TR1/C++0x type trait templates. 1401/// Example: 1402/// __is_pod(int) == true 1403/// __is_enum(std::string) == false 1404class UnaryTypeTraitExpr : public Expr { 1405 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned. 1406 unsigned UTT : 31; 1407 /// The value of the type trait. Unspecified if dependent. 1408 bool Value : 1; 1409 1410 /// Loc - The location of the type trait keyword. 1411 SourceLocation Loc; 1412 1413 /// RParen - The location of the closing paren. 1414 SourceLocation RParen; 1415 1416 /// The type being queried. 1417 TypeSourceInfo *QueriedType; 1418 1419public: 1420 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 1421 TypeSourceInfo *queried, bool value, 1422 SourceLocation rparen, QualType ty) 1423 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 1424 false, queried->getType()->isDependentType()), 1425 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 1426 1427 explicit UnaryTypeTraitExpr(EmptyShell Empty) 1428 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 1429 QueriedType() { } 1430 1431 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 1432 1433 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 1434 1435 QualType getQueriedType() const { return QueriedType->getType(); } 1436 1437 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 1438 1439 bool getValue() const { return Value; } 1440 1441 static bool classof(const Stmt *T) { 1442 return T->getStmtClass() == UnaryTypeTraitExprClass; 1443 } 1444 static bool classof(const UnaryTypeTraitExpr *) { return true; } 1445 1446 // Iterators 1447 virtual child_iterator child_begin(); 1448 virtual child_iterator child_end(); 1449 1450 friend class ASTStmtReader; 1451}; 1452 1453/// \brief A reference to an overloaded function set, either an 1454/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr. 1455class OverloadExpr : public Expr { 1456 /// The results. These are undesugared, which is to say, they may 1457 /// include UsingShadowDecls. Access is relative to the naming 1458 /// class. 1459 // FIXME: Allocate this data after the OverloadExpr subclass. 1460 DeclAccessPair *Results; 1461 unsigned NumResults; 1462 1463 /// The common name of these declarations. 1464 DeclarationNameInfo NameInfo; 1465 1466 /// The scope specifier, if any. 1467 NestedNameSpecifier *Qualifier; 1468 1469 /// The source range of the scope specifier. 1470 SourceRange QualifierRange; 1471 1472protected: 1473 /// True if the name was a template-id. 1474 bool HasExplicitTemplateArgs; 1475 1476 OverloadExpr(StmtClass K, ASTContext &C, QualType T, bool Dependent, 1477 NestedNameSpecifier *Qualifier, SourceRange QRange, 1478 const DeclarationNameInfo &NameInfo, 1479 bool HasTemplateArgs, 1480 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 1481 1482 OverloadExpr(StmtClass K, EmptyShell Empty) 1483 : Expr(K, Empty), Results(0), NumResults(0), 1484 Qualifier(0), HasExplicitTemplateArgs(false) { } 1485 1486public: 1487 /// Computes whether an unresolved lookup on the given declarations 1488 /// and optional template arguments is type- and value-dependent. 1489 static bool ComputeDependence(UnresolvedSetIterator Begin, 1490 UnresolvedSetIterator End, 1491 const TemplateArgumentListInfo *Args); 1492 1493 struct FindResult { 1494 OverloadExpr *Expression; 1495 bool IsAddressOfOperand; 1496 bool HasFormOfMemberPointer; 1497 }; 1498 1499 /// Finds the overloaded expression in the given expression of 1500 /// OverloadTy. 1501 /// 1502 /// \return the expression (which must be there) and true if it has 1503 /// the particular form of a member pointer expression 1504 static FindResult find(Expr *E) { 1505 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 1506 1507 FindResult Result; 1508 1509 E = E->IgnoreParens(); 1510 if (isa<UnaryOperator>(E)) { 1511 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 1512 E = cast<UnaryOperator>(E)->getSubExpr(); 1513 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 1514 1515 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 1516 Result.IsAddressOfOperand = true; 1517 Result.Expression = Ovl; 1518 } else { 1519 Result.HasFormOfMemberPointer = false; 1520 Result.IsAddressOfOperand = false; 1521 Result.Expression = cast<OverloadExpr>(E); 1522 } 1523 1524 return Result; 1525 } 1526 1527 /// Gets the naming class of this lookup, if any. 1528 CXXRecordDecl *getNamingClass() const; 1529 1530 typedef UnresolvedSetImpl::iterator decls_iterator; 1531 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 1532 decls_iterator decls_end() const { 1533 return UnresolvedSetIterator(Results + NumResults); 1534 } 1535 1536 void initializeResults(ASTContext &C, 1537 UnresolvedSetIterator Begin,UnresolvedSetIterator End); 1538 1539 /// Gets the number of declarations in the unresolved set. 1540 unsigned getNumDecls() const { return NumResults; } 1541 1542 /// Gets the full name info. 1543 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 1544 void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; } 1545 1546 /// Gets the name looked up. 1547 DeclarationName getName() const { return NameInfo.getName(); } 1548 void setName(DeclarationName N) { NameInfo.setName(N); } 1549 1550 /// Gets the location of the name. 1551 SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 1552 void setNameLoc(SourceLocation Loc) { NameInfo.setLoc(Loc); } 1553 1554 /// Fetches the nested-name qualifier, if one was given. 1555 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1556 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1557 1558 /// Fetches the range of the nested-name qualifier. 1559 SourceRange getQualifierRange() const { return QualifierRange; } 1560 void setQualifierRange(SourceRange R) { QualifierRange = R; } 1561 1562 /// \brief Determines whether this expression had an explicit 1563 /// template argument list, e.g. f<int>. 1564 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1565 1566 ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below 1567 1568 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1569 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 1570 } 1571 1572 /// \brief Retrieves the optional explicit template arguments. 1573 /// This points to the same data as getExplicitTemplateArgs(), but 1574 /// returns null if there are no explicit template arguments. 1575 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1576 if (!hasExplicitTemplateArgs()) return 0; 1577 return &getExplicitTemplateArgs(); 1578 } 1579 1580 static bool classof(const Stmt *T) { 1581 return T->getStmtClass() == UnresolvedLookupExprClass || 1582 T->getStmtClass() == UnresolvedMemberExprClass; 1583 } 1584 static bool classof(const OverloadExpr *) { return true; } 1585 1586 friend class ASTStmtReader; 1587 friend class ASTStmtWriter; 1588}; 1589 1590/// \brief A reference to a name which we were able to look up during 1591/// parsing but could not resolve to a specific declaration. This 1592/// arises in several ways: 1593/// * we might be waiting for argument-dependent lookup 1594/// * the name might resolve to an overloaded function 1595/// and eventually: 1596/// * the lookup might have included a function template 1597/// These never include UnresolvedUsingValueDecls, which are always 1598/// class members and therefore appear only in 1599/// UnresolvedMemberLookupExprs. 1600class UnresolvedLookupExpr : public OverloadExpr { 1601 /// True if these lookup results should be extended by 1602 /// argument-dependent lookup if this is the operand of a function 1603 /// call. 1604 bool RequiresADL; 1605 1606 /// True if these lookup results are overloaded. This is pretty 1607 /// trivially rederivable if we urgently need to kill this field. 1608 bool Overloaded; 1609 1610 /// The naming class (C++ [class.access.base]p5) of the lookup, if 1611 /// any. This can generally be recalculated from the context chain, 1612 /// but that can be fairly expensive for unqualified lookups. If we 1613 /// want to improve memory use here, this could go in a union 1614 /// against the qualified-lookup bits. 1615 CXXRecordDecl *NamingClass; 1616 1617 UnresolvedLookupExpr(ASTContext &C, QualType T, bool Dependent, 1618 CXXRecordDecl *NamingClass, 1619 NestedNameSpecifier *Qualifier, SourceRange QRange, 1620 const DeclarationNameInfo &NameInfo, 1621 bool RequiresADL, bool Overloaded, bool HasTemplateArgs, 1622 UnresolvedSetIterator Begin, UnresolvedSetIterator End) 1623 : OverloadExpr(UnresolvedLookupExprClass, C, T, 1624 Dependent, Qualifier, QRange, NameInfo, HasTemplateArgs, 1625 Begin, End), 1626 RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass) 1627 {} 1628 1629 UnresolvedLookupExpr(EmptyShell Empty) 1630 : OverloadExpr(UnresolvedLookupExprClass, Empty), 1631 RequiresADL(false), Overloaded(false), NamingClass(0) 1632 {} 1633 1634public: 1635 static UnresolvedLookupExpr *Create(ASTContext &C, 1636 bool Dependent, 1637 CXXRecordDecl *NamingClass, 1638 NestedNameSpecifier *Qualifier, 1639 SourceRange QualifierRange, 1640 const DeclarationNameInfo &NameInfo, 1641 bool ADL, bool Overloaded, 1642 UnresolvedSetIterator Begin, 1643 UnresolvedSetIterator End) { 1644 return new(C) UnresolvedLookupExpr(C, 1645 Dependent ? C.DependentTy : C.OverloadTy, 1646 Dependent, NamingClass, 1647 Qualifier, QualifierRange, NameInfo, 1648 ADL, Overloaded, false, 1649 Begin, End); 1650 } 1651 1652 static UnresolvedLookupExpr *Create(ASTContext &C, 1653 bool Dependent, 1654 CXXRecordDecl *NamingClass, 1655 NestedNameSpecifier *Qualifier, 1656 SourceRange QualifierRange, 1657 const DeclarationNameInfo &NameInfo, 1658 bool ADL, 1659 const TemplateArgumentListInfo &Args, 1660 UnresolvedSetIterator Begin, 1661 UnresolvedSetIterator End); 1662 1663 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 1664 unsigned NumTemplateArgs); 1665 1666 /// True if this declaration should be extended by 1667 /// argument-dependent lookup. 1668 bool requiresADL() const { return RequiresADL; } 1669 void setRequiresADL(bool V) { RequiresADL = V; } 1670 1671 /// True if this lookup is overloaded. 1672 bool isOverloaded() const { return Overloaded; } 1673 void setOverloaded(bool V) { Overloaded = V; } 1674 1675 /// Gets the 'naming class' (in the sense of C++0x 1676 /// [class.access.base]p5) of the lookup. This is the scope 1677 /// that was looked in to find these results. 1678 CXXRecordDecl *getNamingClass() const { return NamingClass; } 1679 void setNamingClass(CXXRecordDecl *D) { NamingClass = D; } 1680 1681 // Note that, inconsistently with the explicit-template-argument AST 1682 // nodes, users are *forbidden* from calling these methods on objects 1683 // without explicit template arguments. 1684 1685 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1686 assert(hasExplicitTemplateArgs()); 1687 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1); 1688 } 1689 1690 /// Gets a reference to the explicit template argument list. 1691 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1692 assert(hasExplicitTemplateArgs()); 1693 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1694 } 1695 1696 /// \brief Retrieves the optional explicit template arguments. 1697 /// This points to the same data as getExplicitTemplateArgs(), but 1698 /// returns null if there are no explicit template arguments. 1699 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1700 if (!hasExplicitTemplateArgs()) return 0; 1701 return &getExplicitTemplateArgs(); 1702 } 1703 1704 /// \brief Copies the template arguments (if present) into the given 1705 /// structure. 1706 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1707 getExplicitTemplateArgs().copyInto(List); 1708 } 1709 1710 SourceLocation getLAngleLoc() const { 1711 return getExplicitTemplateArgs().LAngleLoc; 1712 } 1713 1714 SourceLocation getRAngleLoc() const { 1715 return getExplicitTemplateArgs().RAngleLoc; 1716 } 1717 1718 TemplateArgumentLoc const *getTemplateArgs() const { 1719 return getExplicitTemplateArgs().getTemplateArgs(); 1720 } 1721 1722 unsigned getNumTemplateArgs() const { 1723 return getExplicitTemplateArgs().NumTemplateArgs; 1724 } 1725 1726 virtual SourceRange getSourceRange() const { 1727 SourceRange Range(getNameInfo().getSourceRange()); 1728 if (getQualifier()) Range.setBegin(getQualifierRange().getBegin()); 1729 if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc()); 1730 return Range; 1731 } 1732 1733 virtual StmtIterator child_begin(); 1734 virtual StmtIterator child_end(); 1735 1736 static bool classof(const Stmt *T) { 1737 return T->getStmtClass() == UnresolvedLookupExprClass; 1738 } 1739 static bool classof(const UnresolvedLookupExpr *) { return true; } 1740}; 1741 1742/// \brief A qualified reference to a name whose declaration cannot 1743/// yet be resolved. 1744/// 1745/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 1746/// it expresses a reference to a declaration such as 1747/// X<T>::value. The difference, however, is that an 1748/// DependentScopeDeclRefExpr node is used only within C++ templates when 1749/// the qualification (e.g., X<T>::) refers to a dependent type. In 1750/// this case, X<T>::value cannot resolve to a declaration because the 1751/// declaration will differ from on instantiation of X<T> to the 1752/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 1753/// qualifier (X<T>::) and the name of the entity being referenced 1754/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 1755/// declaration can be found. 1756class DependentScopeDeclRefExpr : public Expr { 1757 /// The name of the entity we will be referencing. 1758 DeclarationNameInfo NameInfo; 1759 1760 /// QualifierRange - The source range that covers the 1761 /// nested-name-specifier. 1762 SourceRange QualifierRange; 1763 1764 /// \brief The nested-name-specifier that qualifies this unresolved 1765 /// declaration name. 1766 NestedNameSpecifier *Qualifier; 1767 1768 /// \brief Whether the name includes explicit template arguments. 1769 bool HasExplicitTemplateArgs; 1770 1771 DependentScopeDeclRefExpr(QualType T, 1772 NestedNameSpecifier *Qualifier, 1773 SourceRange QualifierRange, 1774 const DeclarationNameInfo &NameInfo, 1775 bool HasExplicitTemplateArgs) 1776 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary, 1777 true, true), 1778 NameInfo(NameInfo), QualifierRange(QualifierRange), Qualifier(Qualifier), 1779 HasExplicitTemplateArgs(HasExplicitTemplateArgs) 1780 {} 1781 1782public: 1783 static DependentScopeDeclRefExpr *Create(ASTContext &C, 1784 NestedNameSpecifier *Qualifier, 1785 SourceRange QualifierRange, 1786 const DeclarationNameInfo &NameInfo, 1787 const TemplateArgumentListInfo *TemplateArgs = 0); 1788 1789 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 1790 unsigned NumTemplateArgs); 1791 1792 /// \brief Retrieve the name that this expression refers to. 1793 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 1794 void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; } 1795 1796 /// \brief Retrieve the name that this expression refers to. 1797 DeclarationName getDeclName() const { return NameInfo.getName(); } 1798 void setDeclName(DeclarationName N) { NameInfo.setName(N); } 1799 1800 /// \brief Retrieve the location of the name within the expression. 1801 SourceLocation getLocation() const { return NameInfo.getLoc(); } 1802 void setLocation(SourceLocation L) { NameInfo.setLoc(L); } 1803 1804 /// \brief Retrieve the source range of the nested-name-specifier. 1805 SourceRange getQualifierRange() const { return QualifierRange; } 1806 void setQualifierRange(SourceRange R) { QualifierRange = R; } 1807 1808 /// \brief Retrieve the nested-name-specifier that qualifies this 1809 /// declaration. 1810 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1811 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1812 1813 /// Determines whether this lookup had explicit template arguments. 1814 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1815 1816 // Note that, inconsistently with the explicit-template-argument AST 1817 // nodes, users are *forbidden* from calling these methods on objects 1818 // without explicit template arguments. 1819 1820 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1821 assert(hasExplicitTemplateArgs()); 1822 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1); 1823 } 1824 1825 /// Gets a reference to the explicit template argument list. 1826 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1827 assert(hasExplicitTemplateArgs()); 1828 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1829 } 1830 1831 /// \brief Retrieves the optional explicit template arguments. 1832 /// This points to the same data as getExplicitTemplateArgs(), but 1833 /// returns null if there are no explicit template arguments. 1834 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1835 if (!hasExplicitTemplateArgs()) return 0; 1836 return &getExplicitTemplateArgs(); 1837 } 1838 1839 /// \brief Copies the template arguments (if present) into the given 1840 /// structure. 1841 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1842 getExplicitTemplateArgs().copyInto(List); 1843 } 1844 1845 SourceLocation getLAngleLoc() const { 1846 return getExplicitTemplateArgs().LAngleLoc; 1847 } 1848 1849 SourceLocation getRAngleLoc() const { 1850 return getExplicitTemplateArgs().RAngleLoc; 1851 } 1852 1853 TemplateArgumentLoc const *getTemplateArgs() const { 1854 return getExplicitTemplateArgs().getTemplateArgs(); 1855 } 1856 1857 unsigned getNumTemplateArgs() const { 1858 return getExplicitTemplateArgs().NumTemplateArgs; 1859 } 1860 1861 virtual SourceRange getSourceRange() const { 1862 SourceRange Range(QualifierRange.getBegin(), getLocation()); 1863 if (hasExplicitTemplateArgs()) 1864 Range.setEnd(getRAngleLoc()); 1865 return Range; 1866 } 1867 1868 static bool classof(const Stmt *T) { 1869 return T->getStmtClass() == DependentScopeDeclRefExprClass; 1870 } 1871 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 1872 1873 virtual StmtIterator child_begin(); 1874 virtual StmtIterator child_end(); 1875 1876 friend class ASTStmtReader; 1877 friend class ASTStmtWriter; 1878}; 1879 1880class CXXExprWithTemporaries : public Expr { 1881 Stmt *SubExpr; 1882 1883 CXXTemporary **Temps; 1884 unsigned NumTemps; 1885 1886 CXXExprWithTemporaries(ASTContext &C, Expr *SubExpr, CXXTemporary **Temps, 1887 unsigned NumTemps); 1888 1889public: 1890 CXXExprWithTemporaries(EmptyShell Empty) 1891 : Expr(CXXExprWithTemporariesClass, Empty), 1892 SubExpr(0), Temps(0), NumTemps(0) {} 1893 1894 static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr, 1895 CXXTemporary **Temps, 1896 unsigned NumTemps); 1897 1898 unsigned getNumTemporaries() const { return NumTemps; } 1899 void setNumTemporaries(ASTContext &C, unsigned N); 1900 1901 CXXTemporary *getTemporary(unsigned i) { 1902 assert(i < NumTemps && "Index out of range"); 1903 return Temps[i]; 1904 } 1905 const CXXTemporary *getTemporary(unsigned i) const { 1906 return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i); 1907 } 1908 void setTemporary(unsigned i, CXXTemporary *T) { 1909 assert(i < NumTemps && "Index out of range"); 1910 Temps[i] = T; 1911 } 1912 1913 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1914 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1915 void setSubExpr(Expr *E) { SubExpr = E; } 1916 1917 virtual SourceRange getSourceRange() const { 1918 return SubExpr->getSourceRange(); 1919 } 1920 1921 // Implement isa/cast/dyncast/etc. 1922 static bool classof(const Stmt *T) { 1923 return T->getStmtClass() == CXXExprWithTemporariesClass; 1924 } 1925 static bool classof(const CXXExprWithTemporaries *) { return true; } 1926 1927 // Iterators 1928 virtual child_iterator child_begin(); 1929 virtual child_iterator child_end(); 1930}; 1931 1932/// \brief Describes an explicit type conversion that uses functional 1933/// notion but could not be resolved because one or more arguments are 1934/// type-dependent. 1935/// 1936/// The explicit type conversions expressed by 1937/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 1938/// where \c T is some type and \c a1, a2, ..., aN are values, and 1939/// either \C T is a dependent type or one or more of the \c a's is 1940/// type-dependent. For example, this would occur in a template such 1941/// as: 1942/// 1943/// \code 1944/// template<typename T, typename A1> 1945/// inline T make_a(const A1& a1) { 1946/// return T(a1); 1947/// } 1948/// \endcode 1949/// 1950/// When the returned expression is instantiated, it may resolve to a 1951/// constructor call, conversion function call, or some kind of type 1952/// conversion. 1953class CXXUnresolvedConstructExpr : public Expr { 1954 /// \brief The type being constructed. 1955 TypeSourceInfo *Type; 1956 1957 /// \brief The location of the left parentheses ('('). 1958 SourceLocation LParenLoc; 1959 1960 /// \brief The location of the right parentheses (')'). 1961 SourceLocation RParenLoc; 1962 1963 /// \brief The number of arguments used to construct the type. 1964 unsigned NumArgs; 1965 1966 CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 1967 SourceLocation LParenLoc, 1968 Expr **Args, 1969 unsigned NumArgs, 1970 SourceLocation RParenLoc); 1971 1972 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 1973 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 1974 1975 friend class ASTStmtReader; 1976 1977public: 1978 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 1979 TypeSourceInfo *Type, 1980 SourceLocation LParenLoc, 1981 Expr **Args, 1982 unsigned NumArgs, 1983 SourceLocation RParenLoc); 1984 1985 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 1986 unsigned NumArgs); 1987 1988 /// \brief Retrieve the type that is being constructed, as specified 1989 /// in the source code. 1990 QualType getTypeAsWritten() const { return Type->getType(); } 1991 1992 /// \brief Retrieve the type source information for the type being 1993 /// constructed. 1994 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1995 1996 /// \brief Retrieve the location of the left parentheses ('(') that 1997 /// precedes the argument list. 1998 SourceLocation getLParenLoc() const { return LParenLoc; } 1999 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2000 2001 /// \brief Retrieve the location of the right parentheses (')') that 2002 /// follows the argument list. 2003 SourceLocation getRParenLoc() const { return RParenLoc; } 2004 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2005 2006 /// \brief Retrieve the number of arguments. 2007 unsigned arg_size() const { return NumArgs; } 2008 2009 typedef Expr** arg_iterator; 2010 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2011 arg_iterator arg_end() { return arg_begin() + NumArgs; } 2012 2013 typedef const Expr* const * const_arg_iterator; 2014 const_arg_iterator arg_begin() const { 2015 return reinterpret_cast<const Expr* const *>(this + 1); 2016 } 2017 const_arg_iterator arg_end() const { 2018 return arg_begin() + NumArgs; 2019 } 2020 2021 Expr *getArg(unsigned I) { 2022 assert(I < NumArgs && "Argument index out-of-range"); 2023 return *(arg_begin() + I); 2024 } 2025 2026 const Expr *getArg(unsigned I) const { 2027 assert(I < NumArgs && "Argument index out-of-range"); 2028 return *(arg_begin() + I); 2029 } 2030 2031 void setArg(unsigned I, Expr *E) { 2032 assert(I < NumArgs && "Argument index out-of-range"); 2033 *(arg_begin() + I) = E; 2034 } 2035 2036 virtual SourceRange getSourceRange() const; 2037 2038 static bool classof(const Stmt *T) { 2039 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2040 } 2041 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 2042 2043 // Iterators 2044 virtual child_iterator child_begin(); 2045 virtual child_iterator child_end(); 2046}; 2047 2048/// \brief Represents a C++ member access expression where the actual 2049/// member referenced could not be resolved because the base 2050/// expression or the member name was dependent. 2051/// 2052/// Like UnresolvedMemberExprs, these can be either implicit or 2053/// explicit accesses. It is only possible to get one of these with 2054/// an implicit access if a qualifier is provided. 2055class CXXDependentScopeMemberExpr : public Expr { 2056 /// \brief The expression for the base pointer or class reference, 2057 /// e.g., the \c x in x.f. Can be null in implicit accesses. 2058 Stmt *Base; 2059 2060 /// \brief The type of the base expression. Never null, even for 2061 /// implicit accesses. 2062 QualType BaseType; 2063 2064 /// \brief Whether this member expression used the '->' operator or 2065 /// the '.' operator. 2066 bool IsArrow : 1; 2067 2068 /// \brief Whether this member expression has explicitly-specified template 2069 /// arguments. 2070 bool HasExplicitTemplateArgs : 1; 2071 2072 /// \brief The location of the '->' or '.' operator. 2073 SourceLocation OperatorLoc; 2074 2075 /// \brief The nested-name-specifier that precedes the member name, if any. 2076 NestedNameSpecifier *Qualifier; 2077 2078 /// \brief The source range covering the nested name specifier. 2079 SourceRange QualifierRange; 2080 2081 /// \brief In a qualified member access expression such as t->Base::f, this 2082 /// member stores the resolves of name lookup in the context of the member 2083 /// access expression, to be used at instantiation time. 2084 /// 2085 /// FIXME: This member, along with the Qualifier and QualifierRange, could 2086 /// be stuck into a structure that is optionally allocated at the end of 2087 /// the CXXDependentScopeMemberExpr, to save space in the common case. 2088 NamedDecl *FirstQualifierFoundInScope; 2089 2090 /// \brief The member to which this member expression refers, which 2091 /// can be name, overloaded operator, or destructor. 2092 /// FIXME: could also be a template-id 2093 DeclarationNameInfo MemberNameInfo; 2094 2095 CXXDependentScopeMemberExpr(ASTContext &C, 2096 Expr *Base, QualType BaseType, bool IsArrow, 2097 SourceLocation OperatorLoc, 2098 NestedNameSpecifier *Qualifier, 2099 SourceRange QualifierRange, 2100 NamedDecl *FirstQualifierFoundInScope, 2101 DeclarationNameInfo MemberNameInfo, 2102 const TemplateArgumentListInfo *TemplateArgs); 2103 2104public: 2105 CXXDependentScopeMemberExpr(ASTContext &C, 2106 Expr *Base, QualType BaseType, 2107 bool IsArrow, 2108 SourceLocation OperatorLoc, 2109 NestedNameSpecifier *Qualifier, 2110 SourceRange QualifierRange, 2111 NamedDecl *FirstQualifierFoundInScope, 2112 DeclarationNameInfo MemberNameInfo) 2113 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, 2114 VK_LValue, OK_Ordinary, true, true), 2115 Base(Base), BaseType(BaseType), IsArrow(IsArrow), 2116 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc), 2117 Qualifier(Qualifier), QualifierRange(QualifierRange), 2118 FirstQualifierFoundInScope(FirstQualifierFoundInScope), 2119 MemberNameInfo(MemberNameInfo) { } 2120 2121 static CXXDependentScopeMemberExpr * 2122 Create(ASTContext &C, 2123 Expr *Base, QualType BaseType, bool IsArrow, 2124 SourceLocation OperatorLoc, 2125 NestedNameSpecifier *Qualifier, 2126 SourceRange QualifierRange, 2127 NamedDecl *FirstQualifierFoundInScope, 2128 DeclarationNameInfo MemberNameInfo, 2129 const TemplateArgumentListInfo *TemplateArgs); 2130 2131 static CXXDependentScopeMemberExpr * 2132 CreateEmpty(ASTContext &C, unsigned NumTemplateArgs); 2133 2134 /// \brief True if this is an implicit access, i.e. one in which the 2135 /// member being accessed was not written in the source. The source 2136 /// location of the operator is invalid in this case. 2137 bool isImplicitAccess() const { return Base == 0; } 2138 2139 /// \brief Retrieve the base object of this member expressions, 2140 /// e.g., the \c x in \c x.m. 2141 Expr *getBase() const { 2142 assert(!isImplicitAccess()); 2143 return cast<Expr>(Base); 2144 } 2145 void setBase(Expr *E) { Base = E; } 2146 2147 QualType getBaseType() const { return BaseType; } 2148 void setBaseType(QualType T) { BaseType = T; } 2149 2150 /// \brief Determine whether this member expression used the '->' 2151 /// operator; otherwise, it used the '.' operator. 2152 bool isArrow() const { return IsArrow; } 2153 void setArrow(bool A) { IsArrow = A; } 2154 2155 /// \brief Retrieve the location of the '->' or '.' operator. 2156 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2157 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 2158 2159 /// \brief Retrieve the nested-name-specifier that qualifies the member 2160 /// name. 2161 NestedNameSpecifier *getQualifier() const { return Qualifier; } 2162 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 2163 2164 /// \brief Retrieve the source range covering the nested-name-specifier 2165 /// that qualifies the member name. 2166 SourceRange getQualifierRange() const { return QualifierRange; } 2167 void setQualifierRange(SourceRange R) { QualifierRange = R; } 2168 2169 /// \brief Retrieve the first part of the nested-name-specifier that was 2170 /// found in the scope of the member access expression when the member access 2171 /// was initially parsed. 2172 /// 2173 /// This function only returns a useful result when member access expression 2174 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 2175 /// returned by this function describes what was found by unqualified name 2176 /// lookup for the identifier "Base" within the scope of the member access 2177 /// expression itself. At template instantiation time, this information is 2178 /// combined with the results of name lookup into the type of the object 2179 /// expression itself (the class type of x). 2180 NamedDecl *getFirstQualifierFoundInScope() const { 2181 return FirstQualifierFoundInScope; 2182 } 2183 void setFirstQualifierFoundInScope(NamedDecl *D) { 2184 FirstQualifierFoundInScope = D; 2185 } 2186 2187 /// \brief Retrieve the name of the member that this expression 2188 /// refers to. 2189 const DeclarationNameInfo &getMemberNameInfo() const { 2190 return MemberNameInfo; 2191 } 2192 void setMemberNameInfo(const DeclarationNameInfo &N) { MemberNameInfo = N; } 2193 2194 /// \brief Retrieve the name of the member that this expression 2195 /// refers to. 2196 DeclarationName getMember() const { return MemberNameInfo.getName(); } 2197 void setMember(DeclarationName N) { MemberNameInfo.setName(N); } 2198 2199 // \brief Retrieve the location of the name of the member that this 2200 // expression refers to. 2201 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 2202 void setMemberLoc(SourceLocation L) { MemberNameInfo.setLoc(L); } 2203 2204 /// \brief Determines whether this member expression actually had a C++ 2205 /// template argument list explicitly specified, e.g., x.f<int>. 2206 bool hasExplicitTemplateArgs() const { 2207 return HasExplicitTemplateArgs; 2208 } 2209 2210 /// \brief Retrieve the explicit template argument list that followed the 2211 /// member template name, if any. 2212 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2213 assert(HasExplicitTemplateArgs); 2214 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2215 } 2216 2217 /// \brief Retrieve the explicit template argument list that followed the 2218 /// member template name, if any. 2219 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2220 return const_cast<CXXDependentScopeMemberExpr *>(this) 2221 ->getExplicitTemplateArgs(); 2222 } 2223 2224 /// \brief Retrieves the optional explicit template arguments. 2225 /// This points to the same data as getExplicitTemplateArgs(), but 2226 /// returns null if there are no explicit template arguments. 2227 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 2228 if (!hasExplicitTemplateArgs()) return 0; 2229 return &getExplicitTemplateArgs(); 2230 } 2231 2232 /// \brief Copies the template arguments (if present) into the given 2233 /// structure. 2234 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2235 getExplicitTemplateArgs().copyInto(List); 2236 } 2237 2238 /// \brief Initializes the template arguments using the given structure. 2239 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 2240 getExplicitTemplateArgs().initializeFrom(List); 2241 } 2242 2243 /// \brief Retrieve the location of the left angle bracket following the 2244 /// member name ('<'), if any. 2245 SourceLocation getLAngleLoc() const { 2246 return getExplicitTemplateArgs().LAngleLoc; 2247 } 2248 2249 /// \brief Retrieve the template arguments provided as part of this 2250 /// template-id. 2251 const TemplateArgumentLoc *getTemplateArgs() const { 2252 return getExplicitTemplateArgs().getTemplateArgs(); 2253 } 2254 2255 /// \brief Retrieve the number of template arguments provided as part of this 2256 /// template-id. 2257 unsigned getNumTemplateArgs() const { 2258 return getExplicitTemplateArgs().NumTemplateArgs; 2259 } 2260 2261 /// \brief Retrieve the location of the right angle bracket following the 2262 /// template arguments ('>'). 2263 SourceLocation getRAngleLoc() const { 2264 return getExplicitTemplateArgs().RAngleLoc; 2265 } 2266 2267 virtual SourceRange getSourceRange() const { 2268 SourceRange Range; 2269 if (!isImplicitAccess()) 2270 Range.setBegin(Base->getSourceRange().getBegin()); 2271 else if (getQualifier()) 2272 Range.setBegin(getQualifierRange().getBegin()); 2273 else 2274 Range.setBegin(MemberNameInfo.getBeginLoc()); 2275 2276 if (hasExplicitTemplateArgs()) 2277 Range.setEnd(getRAngleLoc()); 2278 else 2279 Range.setEnd(MemberNameInfo.getEndLoc()); 2280 return Range; 2281 } 2282 2283 static bool classof(const Stmt *T) { 2284 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 2285 } 2286 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 2287 2288 // Iterators 2289 virtual child_iterator child_begin(); 2290 virtual child_iterator child_end(); 2291 2292 friend class ASTStmtReader; 2293 friend class ASTStmtWriter; 2294}; 2295 2296/// \brief Represents a C++ member access expression for which lookup 2297/// produced a set of overloaded functions. 2298/// 2299/// The member access may be explicit or implicit: 2300/// struct A { 2301/// int a, b; 2302/// int explicitAccess() { return this->a + this->A::b; } 2303/// int implicitAccess() { return a + A::b; } 2304/// }; 2305/// 2306/// In the final AST, an explicit access always becomes a MemberExpr. 2307/// An implicit access may become either a MemberExpr or a 2308/// DeclRefExpr, depending on whether the member is static. 2309class UnresolvedMemberExpr : public OverloadExpr { 2310 /// \brief Whether this member expression used the '->' operator or 2311 /// the '.' operator. 2312 bool IsArrow : 1; 2313 2314 /// \brief Whether the lookup results contain an unresolved using 2315 /// declaration. 2316 bool HasUnresolvedUsing : 1; 2317 2318 /// \brief The expression for the base pointer or class reference, 2319 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 2320 /// member expression 2321 Stmt *Base; 2322 2323 /// \brief The type of the base expression; never null. 2324 QualType BaseType; 2325 2326 /// \brief The location of the '->' or '.' operator. 2327 SourceLocation OperatorLoc; 2328 2329 UnresolvedMemberExpr(ASTContext &C, QualType T, bool Dependent, 2330 bool HasUnresolvedUsing, 2331 Expr *Base, QualType BaseType, bool IsArrow, 2332 SourceLocation OperatorLoc, 2333 NestedNameSpecifier *Qualifier, 2334 SourceRange QualifierRange, 2335 const DeclarationNameInfo &MemberNameInfo, 2336 const TemplateArgumentListInfo *TemplateArgs, 2337 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2338 2339 UnresolvedMemberExpr(EmptyShell Empty) 2340 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 2341 HasUnresolvedUsing(false), Base(0) { } 2342 2343public: 2344 static UnresolvedMemberExpr * 2345 Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing, 2346 Expr *Base, QualType BaseType, bool IsArrow, 2347 SourceLocation OperatorLoc, 2348 NestedNameSpecifier *Qualifier, 2349 SourceRange QualifierRange, 2350 const DeclarationNameInfo &MemberNameInfo, 2351 const TemplateArgumentListInfo *TemplateArgs, 2352 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2353 2354 static UnresolvedMemberExpr * 2355 CreateEmpty(ASTContext &C, unsigned NumTemplateArgs); 2356 2357 /// \brief True if this is an implicit access, i.e. one in which the 2358 /// member being accessed was not written in the source. The source 2359 /// location of the operator is invalid in this case. 2360 bool isImplicitAccess() const { return Base == 0; } 2361 2362 /// \brief Retrieve the base object of this member expressions, 2363 /// e.g., the \c x in \c x.m. 2364 Expr *getBase() { 2365 assert(!isImplicitAccess()); 2366 return cast<Expr>(Base); 2367 } 2368 const Expr *getBase() const { 2369 assert(!isImplicitAccess()); 2370 return cast<Expr>(Base); 2371 } 2372 void setBase(Expr *E) { Base = E; } 2373 2374 QualType getBaseType() const { return BaseType; } 2375 void setBaseType(QualType T) { BaseType = T; } 2376 2377 /// \brief Determine whether the lookup results contain an unresolved using 2378 /// declaration. 2379 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 2380 void setHasUnresolvedUsing(bool V) { HasUnresolvedUsing = V; } 2381 2382 /// \brief Determine whether this member expression used the '->' 2383 /// operator; otherwise, it used the '.' operator. 2384 bool isArrow() const { return IsArrow; } 2385 void setArrow(bool A) { IsArrow = A; } 2386 2387 /// \brief Retrieve the location of the '->' or '.' operator. 2388 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2389 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 2390 2391 /// \brief Retrieves the naming class of this lookup. 2392 CXXRecordDecl *getNamingClass() const; 2393 2394 /// \brief Retrieve the full name info for the member that this expression 2395 /// refers to. 2396 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 2397 void setMemberNameInfo(const DeclarationNameInfo &N) { setNameInfo(N); } 2398 2399 /// \brief Retrieve the name of the member that this expression 2400 /// refers to. 2401 DeclarationName getMemberName() const { return getName(); } 2402 void setMemberName(DeclarationName N) { setName(N); } 2403 2404 // \brief Retrieve the location of the name of the member that this 2405 // expression refers to. 2406 SourceLocation getMemberLoc() const { return getNameLoc(); } 2407 void setMemberLoc(SourceLocation L) { setNameLoc(L); } 2408 2409 /// \brief Retrieve the explicit template argument list that followed the 2410 /// member template name. 2411 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2412 assert(hasExplicitTemplateArgs()); 2413 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2414 } 2415 2416 /// \brief Retrieve the explicit template argument list that followed the 2417 /// member template name, if any. 2418 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2419 assert(hasExplicitTemplateArgs()); 2420 return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1); 2421 } 2422 2423 /// \brief Retrieves the optional explicit template arguments. 2424 /// This points to the same data as getExplicitTemplateArgs(), but 2425 /// returns null if there are no explicit template arguments. 2426 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 2427 if (!hasExplicitTemplateArgs()) return 0; 2428 return &getExplicitTemplateArgs(); 2429 } 2430 2431 /// \brief Copies the template arguments into the given structure. 2432 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2433 getExplicitTemplateArgs().copyInto(List); 2434 } 2435 2436 /// \brief Retrieve the location of the left angle bracket following 2437 /// the member name ('<'). 2438 SourceLocation getLAngleLoc() const { 2439 return getExplicitTemplateArgs().LAngleLoc; 2440 } 2441 2442 /// \brief Retrieve the template arguments provided as part of this 2443 /// template-id. 2444 const TemplateArgumentLoc *getTemplateArgs() const { 2445 return getExplicitTemplateArgs().getTemplateArgs(); 2446 } 2447 2448 /// \brief Retrieve the number of template arguments provided as 2449 /// part of this template-id. 2450 unsigned getNumTemplateArgs() const { 2451 return getExplicitTemplateArgs().NumTemplateArgs; 2452 } 2453 2454 /// \brief Retrieve the location of the right angle bracket 2455 /// following the template arguments ('>'). 2456 SourceLocation getRAngleLoc() const { 2457 return getExplicitTemplateArgs().RAngleLoc; 2458 } 2459 2460 virtual SourceRange getSourceRange() const { 2461 SourceRange Range = getMemberNameInfo().getSourceRange(); 2462 if (!isImplicitAccess()) 2463 Range.setBegin(Base->getSourceRange().getBegin()); 2464 else if (getQualifier()) 2465 Range.setBegin(getQualifierRange().getBegin()); 2466 2467 if (hasExplicitTemplateArgs()) 2468 Range.setEnd(getRAngleLoc()); 2469 return Range; 2470 } 2471 2472 static bool classof(const Stmt *T) { 2473 return T->getStmtClass() == UnresolvedMemberExprClass; 2474 } 2475 static bool classof(const UnresolvedMemberExpr *) { return true; } 2476 2477 // Iterators 2478 virtual child_iterator child_begin(); 2479 virtual child_iterator child_end(); 2480}; 2481 2482/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 2483/// 2484/// The noexcept expression tests whether a given expression might throw. Its 2485/// result is a boolean constant. 2486class CXXNoexceptExpr : public Expr { 2487 bool Value : 1; 2488 Stmt *Operand; 2489 SourceRange Range; 2490 2491 friend class ASTStmtReader; 2492 2493public: 2494 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 2495 SourceLocation Keyword, SourceLocation RParen) 2496 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 2497 /*TypeDependent*/false, 2498 /*ValueDependent*/Val == CT_Dependent), 2499 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 2500 { } 2501 2502 CXXNoexceptExpr(EmptyShell Empty) 2503 : Expr(CXXNoexceptExprClass, Empty) 2504 { } 2505 2506 Expr *getOperand() const { return static_cast<Expr*>(Operand); } 2507 2508 virtual SourceRange getSourceRange() const { return Range; } 2509 2510 bool getValue() const { return Value; } 2511 2512 static bool classof(const Stmt *T) { 2513 return T->getStmtClass() == CXXNoexceptExprClass; 2514 } 2515 static bool classof(const CXXNoexceptExpr *) { return true; } 2516 2517 // Iterators 2518 virtual child_iterator child_begin(); 2519 virtual child_iterator child_end(); 2520}; 2521 2522inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() { 2523 if (isa<UnresolvedLookupExpr>(this)) 2524 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs(); 2525 else 2526 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs(); 2527} 2528 2529} // end namespace clang 2530 2531#endif 2532