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