clang API Documentation
00001 //===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the Expr interface and subclasses for C++ expressions. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_AST_EXPRCXX_H 00015 #define LLVM_CLANG_AST_EXPRCXX_H 00016 00017 #include "clang/Basic/TypeTraits.h" 00018 #include "clang/AST/Expr.h" 00019 #include "clang/AST/UnresolvedSet.h" 00020 #include "clang/AST/TemplateBase.h" 00021 00022 namespace clang { 00023 00024 class CXXConstructorDecl; 00025 class CXXDestructorDecl; 00026 class CXXMethodDecl; 00027 class CXXTemporary; 00028 class TemplateArgumentListInfo; 00029 00030 //===--------------------------------------------------------------------===// 00031 // C++ Expressions. 00032 //===--------------------------------------------------------------------===// 00033 00034 /// \brief A call to an overloaded operator written using operator 00035 /// syntax. 00036 /// 00037 /// Represents a call to an overloaded operator written using operator 00038 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 00039 /// normal call, this AST node provides better information about the 00040 /// syntactic representation of the call. 00041 /// 00042 /// In a C++ template, this expression node kind will be used whenever 00043 /// any of the arguments are type-dependent. In this case, the 00044 /// function itself will be a (possibly empty) set of functions and 00045 /// function templates that were found by name lookup at template 00046 /// definition time. 00047 class CXXOperatorCallExpr : public CallExpr { 00048 /// \brief The overloaded operator. 00049 OverloadedOperatorKind Operator; 00050 00051 public: 00052 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 00053 Expr **args, unsigned numargs, QualType t, 00054 SourceLocation operatorloc) 00055 : CallExpr(C, CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc), 00056 Operator(Op) {} 00057 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 00058 CallExpr(C, CXXOperatorCallExprClass, Empty) { } 00059 00060 00061 /// getOperator - Returns the kind of overloaded operator that this 00062 /// expression refers to. 00063 OverloadedOperatorKind getOperator() const { return Operator; } 00064 void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; } 00065 00066 /// getOperatorLoc - Returns the location of the operator symbol in 00067 /// the expression. When @c getOperator()==OO_Call, this is the 00068 /// location of the right parentheses; when @c 00069 /// getOperator()==OO_Subscript, this is the location of the right 00070 /// bracket. 00071 SourceLocation getOperatorLoc() const { return getRParenLoc(); } 00072 00073 virtual SourceRange getSourceRange() const; 00074 00075 static bool classof(const Stmt *T) { 00076 return T->getStmtClass() == CXXOperatorCallExprClass; 00077 } 00078 static bool classof(const CXXOperatorCallExpr *) { return true; } 00079 }; 00080 00081 /// CXXMemberCallExpr - Represents a call to a member function that 00082 /// may be written either with member call syntax (e.g., "obj.func()" 00083 /// or "objptr->func()") or with normal function-call syntax 00084 /// ("func()") within a member function that ends up calling a member 00085 /// function. The callee in either case is a MemberExpr that contains 00086 /// both the object argument and the member function, while the 00087 /// arguments are the arguments within the parentheses (not including 00088 /// the object argument). 00089 class CXXMemberCallExpr : public CallExpr { 00090 public: 00091 CXXMemberCallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 00092 QualType t, SourceLocation rparenloc) 00093 : CallExpr(C, CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) {} 00094 00095 /// getImplicitObjectArgument - Retrieves the implicit object 00096 /// argument for the member call. For example, in "x.f(5)", this 00097 /// operation would return "x". 00098 Expr *getImplicitObjectArgument(); 00099 00100 virtual SourceRange getSourceRange() const; 00101 00102 static bool classof(const Stmt *T) { 00103 return T->getStmtClass() == CXXMemberCallExprClass; 00104 } 00105 static bool classof(const CXXMemberCallExpr *) { return true; } 00106 }; 00107 00108 /// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 00109 /// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 00110 /// const_cast. 00111 /// 00112 /// This abstract class is inherited by all of the classes 00113 /// representing "named" casts, e.g., CXXStaticCastExpr, 00114 /// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 00115 class CXXNamedCastExpr : public ExplicitCastExpr { 00116 private: 00117 SourceLocation Loc; // the location of the casting op 00118 00119 protected: 00120 CXXNamedCastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op, 00121 TypeSourceInfo *writtenTy, SourceLocation l) 00122 : ExplicitCastExpr(SC, ty, kind, op, writtenTy), Loc(l) {} 00123 00124 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell) 00125 : ExplicitCastExpr(SC, Shell) { } 00126 00127 public: 00128 const char *getCastName() const; 00129 00130 /// \brief Retrieve the location of the cast operator keyword, e.g., 00131 /// "static_cast". 00132 SourceLocation getOperatorLoc() const { return Loc; } 00133 void setOperatorLoc(SourceLocation L) { Loc = L; } 00134 00135 virtual SourceRange getSourceRange() const { 00136 return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); 00137 } 00138 static bool classof(const Stmt *T) { 00139 switch (T->getStmtClass()) { 00140 case CXXNamedCastExprClass: 00141 case CXXStaticCastExprClass: 00142 case CXXDynamicCastExprClass: 00143 case CXXReinterpretCastExprClass: 00144 case CXXConstCastExprClass: 00145 return true; 00146 default: 00147 return false; 00148 } 00149 } 00150 static bool classof(const CXXNamedCastExpr *) { return true; } 00151 }; 00152 00153 /// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]). 00154 /// 00155 /// This expression node represents a C++ static cast, e.g., 00156 /// @c static_cast<int>(1.0). 00157 class CXXStaticCastExpr : public CXXNamedCastExpr { 00158 public: 00159 CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op, 00160 TypeSourceInfo *writtenTy, SourceLocation l) 00161 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, writtenTy, l) {} 00162 00163 explicit CXXStaticCastExpr(EmptyShell Empty) 00164 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty) { } 00165 00166 static bool classof(const Stmt *T) { 00167 return T->getStmtClass() == CXXStaticCastExprClass; 00168 } 00169 static bool classof(const CXXStaticCastExpr *) { return true; } 00170 }; 00171 00172 /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 00173 /// (C++ [expr.dynamic.cast]), which may perform a run-time check to 00174 /// determine how to perform the type cast. 00175 /// 00176 /// This expression node represents a dynamic cast, e.g., 00177 /// @c dynamic_cast<Derived*>(BasePtr). 00178 class CXXDynamicCastExpr : public CXXNamedCastExpr { 00179 public: 00180 CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op, 00181 TypeSourceInfo *writtenTy, SourceLocation l) 00182 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, writtenTy, l) {} 00183 00184 explicit CXXDynamicCastExpr(EmptyShell Empty) 00185 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty) { } 00186 00187 static bool classof(const Stmt *T) { 00188 return T->getStmtClass() == CXXDynamicCastExprClass; 00189 } 00190 static bool classof(const CXXDynamicCastExpr *) { return true; } 00191 }; 00192 00193 /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 00194 /// [expr.reinterpret.cast]), which provides a differently-typed view 00195 /// of a value but performs no actual work at run time. 00196 /// 00197 /// This expression node represents a reinterpret cast, e.g., 00198 /// @c reinterpret_cast<int>(VoidPtr). 00199 class CXXReinterpretCastExpr : public CXXNamedCastExpr { 00200 public: 00201 CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op, 00202 TypeSourceInfo *writtenTy, SourceLocation l) 00203 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op, 00204 writtenTy, l) {} 00205 00206 explicit CXXReinterpretCastExpr(EmptyShell Empty) 00207 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty) { } 00208 00209 static bool classof(const Stmt *T) { 00210 return T->getStmtClass() == CXXReinterpretCastExprClass; 00211 } 00212 static bool classof(const CXXReinterpretCastExpr *) { return true; } 00213 }; 00214 00215 /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 00216 /// which can remove type qualifiers but does not change the underlying value. 00217 /// 00218 /// This expression node represents a const cast, e.g., 00219 /// @c const_cast<char*>(PtrToConstChar). 00220 class CXXConstCastExpr : public CXXNamedCastExpr { 00221 public: 00222 CXXConstCastExpr(QualType ty, Expr *op, TypeSourceInfo *writtenTy, 00223 SourceLocation l) 00224 : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op, writtenTy, l) {} 00225 00226 explicit CXXConstCastExpr(EmptyShell Empty) 00227 : CXXNamedCastExpr(CXXConstCastExprClass, Empty) { } 00228 00229 static bool classof(const Stmt *T) { 00230 return T->getStmtClass() == CXXConstCastExprClass; 00231 } 00232 static bool classof(const CXXConstCastExpr *) { return true; } 00233 }; 00234 00235 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 00236 /// 00237 class CXXBoolLiteralExpr : public Expr { 00238 bool Value; 00239 SourceLocation Loc; 00240 public: 00241 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 00242 Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {} 00243 00244 explicit CXXBoolLiteralExpr(EmptyShell Empty) 00245 : Expr(CXXBoolLiteralExprClass, Empty) { } 00246 00247 bool getValue() const { return Value; } 00248 void setValue(bool V) { Value = V; } 00249 00250 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 00251 00252 SourceLocation getLocation() const { return Loc; } 00253 void setLocation(SourceLocation L) { Loc = L; } 00254 00255 static bool classof(const Stmt *T) { 00256 return T->getStmtClass() == CXXBoolLiteralExprClass; 00257 } 00258 static bool classof(const CXXBoolLiteralExpr *) { return true; } 00259 00260 // Iterators 00261 virtual child_iterator child_begin(); 00262 virtual child_iterator child_end(); 00263 }; 00264 00265 /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 00266 class CXXNullPtrLiteralExpr : public Expr { 00267 SourceLocation Loc; 00268 public: 00269 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 00270 Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {} 00271 00272 explicit CXXNullPtrLiteralExpr(EmptyShell Empty) 00273 : Expr(CXXNullPtrLiteralExprClass, Empty) { } 00274 00275 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 00276 00277 SourceLocation getLocation() const { return Loc; } 00278 void setLocation(SourceLocation L) { Loc = L; } 00279 00280 static bool classof(const Stmt *T) { 00281 return T->getStmtClass() == CXXNullPtrLiteralExprClass; 00282 } 00283 static bool classof(const CXXNullPtrLiteralExpr *) { return true; } 00284 00285 virtual child_iterator child_begin(); 00286 virtual child_iterator child_end(); 00287 }; 00288 00289 /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 00290 /// the type_info that corresponds to the supplied type, or the (possibly 00291 /// dynamic) type of the supplied expression. 00292 /// 00293 /// This represents code like @c typeid(int) or @c typeid(*objPtr) 00294 class CXXTypeidExpr : public Expr { 00295 private: 00296 bool isTypeOp : 1; 00297 union { 00298 void *Ty; 00299 Stmt *Ex; 00300 } Operand; 00301 SourceRange Range; 00302 00303 public: 00304 CXXTypeidExpr(bool isTypeOp, void *op, QualType Ty, const SourceRange r) : 00305 Expr(CXXTypeidExprClass, Ty, 00306 // typeid is never type-dependent (C++ [temp.dep.expr]p4) 00307 false, 00308 // typeid is value-dependent if the type or expression are dependent 00309 (isTypeOp ? QualType::getFromOpaquePtr(op)->isDependentType() 00310 : static_cast<Expr*>(op)->isValueDependent())), 00311 isTypeOp(isTypeOp), Range(r) { 00312 if (isTypeOp) 00313 Operand.Ty = op; 00314 else 00315 // op was an Expr*, so cast it back to that to be safe 00316 Operand.Ex = static_cast<Expr*>(op); 00317 } 00318 00319 bool isTypeOperand() const { return isTypeOp; } 00320 QualType getTypeOperand() const { 00321 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 00322 return QualType::getFromOpaquePtr(Operand.Ty); 00323 } 00324 Expr* getExprOperand() const { 00325 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 00326 return static_cast<Expr*>(Operand.Ex); 00327 } 00328 00329 virtual SourceRange getSourceRange() const { 00330 return Range; 00331 } 00332 static bool classof(const Stmt *T) { 00333 return T->getStmtClass() == CXXTypeidExprClass; 00334 } 00335 static bool classof(const CXXTypeidExpr *) { return true; } 00336 00337 // Iterators 00338 virtual child_iterator child_begin(); 00339 virtual child_iterator child_end(); 00340 }; 00341 00342 /// CXXThisExpr - Represents the "this" expression in C++, which is a 00343 /// pointer to the object on which the current member function is 00344 /// executing (C++ [expr.prim]p3). Example: 00345 /// 00346 /// @code 00347 /// class Foo { 00348 /// public: 00349 /// void bar(); 00350 /// void test() { this->bar(); } 00351 /// }; 00352 /// @endcode 00353 class CXXThisExpr : public Expr { 00354 SourceLocation Loc; 00355 bool Implicit : 1; 00356 00357 public: 00358 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 00359 : Expr(CXXThisExprClass, Type, 00360 // 'this' is type-dependent if the class type of the enclosing 00361 // member function is dependent (C++ [temp.dep.expr]p2) 00362 Type->isDependentType(), Type->isDependentType()), 00363 Loc(L), Implicit(isImplicit) { } 00364 00365 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 00366 00367 bool isImplicit() const { return Implicit; } 00368 void setImplicit(bool I) { Implicit = I; } 00369 00370 static bool classof(const Stmt *T) { 00371 return T->getStmtClass() == CXXThisExprClass; 00372 } 00373 static bool classof(const CXXThisExpr *) { return true; } 00374 00375 // Iterators 00376 virtual child_iterator child_begin(); 00377 virtual child_iterator child_end(); 00378 }; 00379 00380 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 00381 /// 'throw' and 'throw' assignment-expression. When 00382 /// assignment-expression isn't present, Op will be null. 00383 /// 00384 class CXXThrowExpr : public Expr { 00385 Stmt *Op; 00386 SourceLocation ThrowLoc; 00387 public: 00388 // Ty is the void type which is used as the result type of the 00389 // exepression. The l is the location of the throw keyword. expr 00390 // can by null, if the optional expression to throw isn't present. 00391 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) : 00392 Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {} 00393 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 00394 Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 00395 void setSubExpr(Expr *E) { Op = E; } 00396 00397 SourceLocation getThrowLoc() const { return ThrowLoc; } 00398 void setThrowLoc(SourceLocation L) { ThrowLoc = L; } 00399 00400 virtual SourceRange getSourceRange() const { 00401 if (getSubExpr() == 0) 00402 return SourceRange(ThrowLoc, ThrowLoc); 00403 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 00404 } 00405 00406 static bool classof(const Stmt *T) { 00407 return T->getStmtClass() == CXXThrowExprClass; 00408 } 00409 static bool classof(const CXXThrowExpr *) { return true; } 00410 00411 // Iterators 00412 virtual child_iterator child_begin(); 00413 virtual child_iterator child_end(); 00414 }; 00415 00416 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 00417 /// function call argument that was created from the corresponding 00418 /// parameter's default argument, when the call did not explicitly 00419 /// supply arguments for all of the parameters. 00420 class CXXDefaultArgExpr : public Expr { 00421 /// \brief The parameter whose default is being used. 00422 /// 00423 /// When the bit is set, the subexpression is stored after the 00424 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 00425 /// actual default expression is the subexpression. 00426 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 00427 00428 /// \brief The location where the default argument expression was used. 00429 SourceLocation Loc; 00430 00431 protected: 00432 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 00433 : Expr(SC, 00434 param->hasUnparsedDefaultArg() 00435 ? param->getType().getNonReferenceType() 00436 : param->getDefaultArg()->getType(), 00437 false, false), 00438 Param(param, false), Loc(Loc) { } 00439 00440 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 00441 Expr *SubExpr) 00442 : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc) 00443 { 00444 *reinterpret_cast<Expr **>(this + 1) = SubExpr; 00445 } 00446 00447 protected: 00448 virtual void DoDestroy(ASTContext &C); 00449 00450 public: 00451 // Param is the parameter whose default argument is used by this 00452 // expression. 00453 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc, 00454 ParmVarDecl *Param) { 00455 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 00456 } 00457 00458 // Param is the parameter whose default argument is used by this 00459 // expression, and SubExpr is the expression that will actually be used. 00460 static CXXDefaultArgExpr *Create(ASTContext &C, 00461 SourceLocation Loc, 00462 ParmVarDecl *Param, 00463 Expr *SubExpr); 00464 00465 // Retrieve the parameter that the argument was created from. 00466 const ParmVarDecl *getParam() const { return Param.getPointer(); } 00467 ParmVarDecl *getParam() { return Param.getPointer(); } 00468 00469 // Retrieve the actual argument to the function call. 00470 const Expr *getExpr() const { 00471 if (Param.getInt()) 00472 return *reinterpret_cast<Expr const * const*> (this + 1); 00473 return getParam()->getDefaultArg(); 00474 } 00475 Expr *getExpr() { 00476 if (Param.getInt()) 00477 return *reinterpret_cast<Expr **> (this + 1); 00478 return getParam()->getDefaultArg(); 00479 } 00480 00481 /// \brief Retrieve the location where this default argument was actually 00482 /// used. 00483 SourceLocation getUsedLocation() const { return Loc; } 00484 00485 virtual SourceRange getSourceRange() const { 00486 // Default argument expressions have no representation in the 00487 // source, so they have an empty source range. 00488 return SourceRange(); 00489 } 00490 00491 static bool classof(const Stmt *T) { 00492 return T->getStmtClass() == CXXDefaultArgExprClass; 00493 } 00494 static bool classof(const CXXDefaultArgExpr *) { return true; } 00495 00496 // Iterators 00497 virtual child_iterator child_begin(); 00498 virtual child_iterator child_end(); 00499 }; 00500 00501 /// CXXTemporary - Represents a C++ temporary. 00502 class CXXTemporary { 00503 /// Destructor - The destructor that needs to be called. 00504 const CXXDestructorDecl *Destructor; 00505 00506 CXXTemporary(const CXXDestructorDecl *destructor) 00507 : Destructor(destructor) { } 00508 ~CXXTemporary() { } 00509 00510 public: 00511 static CXXTemporary *Create(ASTContext &C, 00512 const CXXDestructorDecl *Destructor); 00513 00514 void Destroy(ASTContext &Ctx); 00515 00516 const CXXDestructorDecl *getDestructor() const { return Destructor; } 00517 }; 00518 00519 /// CXXBindTemporaryExpr - Represents binding an expression to a temporary, 00520 /// so its destructor can be called later. 00521 class CXXBindTemporaryExpr : public Expr { 00522 CXXTemporary *Temp; 00523 00524 Stmt *SubExpr; 00525 00526 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr) 00527 : Expr(CXXBindTemporaryExprClass, subexpr->getType(), false, false), 00528 Temp(temp), SubExpr(subexpr) { } 00529 ~CXXBindTemporaryExpr() { } 00530 00531 protected: 00532 virtual void DoDestroy(ASTContext &C); 00533 00534 public: 00535 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 00536 Expr* SubExpr); 00537 00538 CXXTemporary *getTemporary() { return Temp; } 00539 const CXXTemporary *getTemporary() const { return Temp; } 00540 00541 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 00542 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 00543 void setSubExpr(Expr *E) { SubExpr = E; } 00544 00545 virtual SourceRange getSourceRange() const { 00546 return SubExpr->getSourceRange(); 00547 } 00548 00549 // Implement isa/cast/dyncast/etc. 00550 static bool classof(const Stmt *T) { 00551 return T->getStmtClass() == CXXBindTemporaryExprClass; 00552 } 00553 static bool classof(const CXXBindTemporaryExpr *) { return true; } 00554 00555 // Iterators 00556 virtual child_iterator child_begin(); 00557 virtual child_iterator child_end(); 00558 }; 00559 00560 /// CXXBindReferenceExpr - Represents binding an expression to a reference. 00561 /// In the example: 00562 /// 00563 /// const int &i = 10; 00564 /// 00565 /// a bind reference expression is inserted to indicate that 10 is bound to 00566 /// a reference. (Ans also that a temporary needs to be created to hold the 00567 /// value). 00568 class CXXBindReferenceExpr : public Expr { 00569 // SubExpr - The expression being bound. 00570 Stmt *SubExpr; 00571 00572 // ExtendsLifetime - Whether binding this reference extends the lifetime of 00573 // the expression being bound. FIXME: Add C++ reference. 00574 bool ExtendsLifetime; 00575 00576 /// RequiresTemporaryCopy - Whether binding the subexpression requires a 00577 /// temporary copy. 00578 bool RequiresTemporaryCopy; 00579 00580 CXXBindReferenceExpr(Expr *subexpr, bool ExtendsLifetime, 00581 bool RequiresTemporaryCopy) 00582 : Expr(CXXBindReferenceExprClass, subexpr->getType(), false, false), 00583 SubExpr(subexpr), ExtendsLifetime(ExtendsLifetime), 00584 RequiresTemporaryCopy(RequiresTemporaryCopy) { } 00585 ~CXXBindReferenceExpr() { } 00586 00587 protected: 00588 virtual void DoDestroy(ASTContext &C); 00589 00590 public: 00591 static CXXBindReferenceExpr *Create(ASTContext &C, Expr *SubExpr, 00592 bool ExtendsLifetime, 00593 bool RequiresTemporaryCopy); 00594 00595 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 00596 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 00597 void setSubExpr(Expr *E) { SubExpr = E; } 00598 00599 virtual SourceRange getSourceRange() const { 00600 return SubExpr->getSourceRange(); 00601 } 00602 00603 /// requiresTemporaryCopy - Whether binding the subexpression requires a 00604 /// temporary copy. 00605 bool requiresTemporaryCopy() const { return RequiresTemporaryCopy; } 00606 00607 // extendsLifetime - Whether binding this reference extends the lifetime of 00608 // the expression being bound. FIXME: Add C++ reference. 00609 bool extendsLifetime() { return ExtendsLifetime; } 00610 00611 // Implement isa/cast/dyncast/etc. 00612 static bool classof(const Stmt *T) { 00613 return T->getStmtClass() == CXXBindReferenceExprClass; 00614 } 00615 static bool classof(const CXXBindReferenceExpr *) { return true; } 00616 00617 // Iterators 00618 virtual child_iterator child_begin(); 00619 virtual child_iterator child_end(); 00620 }; 00621 00622 /// CXXConstructExpr - Represents a call to a C++ constructor. 00623 class CXXConstructExpr : public Expr { 00624 CXXConstructorDecl *Constructor; 00625 00626 SourceLocation Loc; 00627 bool Elidable : 1; 00628 bool ZeroInitialization : 1; 00629 bool BaseInitialization : 1; 00630 Stmt **Args; 00631 unsigned NumArgs; 00632 00633 protected: 00634 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 00635 SourceLocation Loc, 00636 CXXConstructorDecl *d, bool elidable, 00637 Expr **args, unsigned numargs, 00638 bool ZeroInitialization = false, 00639 bool BaseInitialization = false); 00640 ~CXXConstructExpr() { } 00641 00642 virtual void DoDestroy(ASTContext &C); 00643 00644 public: 00645 /// \brief Construct an empty C++ construction expression that will store 00646 /// \p numargs arguments. 00647 CXXConstructExpr(EmptyShell Empty, ASTContext &C, unsigned numargs); 00648 00649 static CXXConstructExpr *Create(ASTContext &C, QualType T, 00650 SourceLocation Loc, 00651 CXXConstructorDecl *D, bool Elidable, 00652 Expr **Args, unsigned NumArgs, 00653 bool ZeroInitialization = false, 00654 bool BaseInitialization = false); 00655 00656 00657 CXXConstructorDecl* getConstructor() const { return Constructor; } 00658 void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 00659 00660 SourceLocation getLocation() const { return Loc; } 00661 void setLocation(SourceLocation Loc) { this->Loc = Loc; } 00662 00663 /// \brief Whether this construction is elidable. 00664 bool isElidable() const { return Elidable; } 00665 void setElidable(bool E) { Elidable = E; } 00666 00667 /// \brief Whether this construction first requires 00668 /// zero-initialization before the initializer is called. 00669 bool requiresZeroInitialization() const { return ZeroInitialization; } 00670 void setRequiresZeroInitialization(bool ZeroInit) { 00671 ZeroInitialization = ZeroInit; 00672 } 00673 00674 /// \brief Determines whether this constructor is actually constructing 00675 /// a base class (rather than a complete object). 00676 bool isBaseInitialization() const { return BaseInitialization; } 00677 void setBaseInitialization(bool BI) { BaseInitialization = BI; } 00678 00679 typedef ExprIterator arg_iterator; 00680 typedef ConstExprIterator const_arg_iterator; 00681 00682 arg_iterator arg_begin() { return Args; } 00683 arg_iterator arg_end() { return Args + NumArgs; } 00684 const_arg_iterator arg_begin() const { return Args; } 00685 const_arg_iterator arg_end() const { return Args + NumArgs; } 00686 00687 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 00688 unsigned getNumArgs() const { return NumArgs; } 00689 00690 /// getArg - Return the specified argument. 00691 Expr *getArg(unsigned Arg) { 00692 assert(Arg < NumArgs && "Arg access out of range!"); 00693 return cast<Expr>(Args[Arg]); 00694 } 00695 const Expr *getArg(unsigned Arg) const { 00696 assert(Arg < NumArgs && "Arg access out of range!"); 00697 return cast<Expr>(Args[Arg]); 00698 } 00699 00700 /// setArg - Set the specified argument. 00701 void setArg(unsigned Arg, Expr *ArgExpr) { 00702 assert(Arg < NumArgs && "Arg access out of range!"); 00703 Args[Arg] = ArgExpr; 00704 } 00705 00706 virtual SourceRange getSourceRange() const; 00707 00708 static bool classof(const Stmt *T) { 00709 return T->getStmtClass() == CXXConstructExprClass || 00710 T->getStmtClass() == CXXTemporaryObjectExprClass; 00711 } 00712 static bool classof(const CXXConstructExpr *) { return true; } 00713 00714 // Iterators 00715 virtual child_iterator child_begin(); 00716 virtual child_iterator child_end(); 00717 }; 00718 00719 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 00720 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 00721 /// x = int(0.5); 00722 class CXXFunctionalCastExpr : public ExplicitCastExpr { 00723 SourceLocation TyBeginLoc; 00724 SourceLocation RParenLoc; 00725 public: 00726 CXXFunctionalCastExpr(QualType ty, TypeSourceInfo *writtenTy, 00727 SourceLocation tyBeginLoc, CastKind kind, 00728 Expr *castExpr, SourceLocation rParenLoc) 00729 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr, 00730 writtenTy), 00731 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 00732 00733 explicit CXXFunctionalCastExpr(EmptyShell Shell) 00734 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell) { } 00735 00736 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 00737 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 00738 SourceLocation getRParenLoc() const { return RParenLoc; } 00739 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 00740 00741 virtual SourceRange getSourceRange() const { 00742 return SourceRange(TyBeginLoc, RParenLoc); 00743 } 00744 static bool classof(const Stmt *T) { 00745 return T->getStmtClass() == CXXFunctionalCastExprClass; 00746 } 00747 static bool classof(const CXXFunctionalCastExpr *) { return true; } 00748 }; 00749 00750 /// @brief Represents a C++ functional cast expression that builds a 00751 /// temporary object. 00752 /// 00753 /// This expression type represents a C++ "functional" cast 00754 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a 00755 /// constructor to build a temporary object. If N == 0 but no 00756 /// constructor will be called (because the functional cast is 00757 /// performing a value-initialized an object whose class type has no 00758 /// user-declared constructors), CXXZeroInitValueExpr will represent 00759 /// the functional cast. Finally, with N == 1 arguments the functional 00760 /// cast expression will be represented by CXXFunctionalCastExpr. 00761 /// Example: 00762 /// @code 00763 /// struct X { X(int, float); } 00764 /// 00765 /// X create_X() { 00766 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 00767 /// }; 00768 /// @endcode 00769 class CXXTemporaryObjectExpr : public CXXConstructExpr { 00770 SourceLocation TyBeginLoc; 00771 SourceLocation RParenLoc; 00772 00773 public: 00774 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 00775 QualType writtenTy, SourceLocation tyBeginLoc, 00776 Expr **Args,unsigned NumArgs, 00777 SourceLocation rParenLoc); 00778 00779 ~CXXTemporaryObjectExpr() { } 00780 00781 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 00782 SourceLocation getRParenLoc() const { return RParenLoc; } 00783 00784 virtual SourceRange getSourceRange() const { 00785 return SourceRange(TyBeginLoc, RParenLoc); 00786 } 00787 static bool classof(const Stmt *T) { 00788 return T->getStmtClass() == CXXTemporaryObjectExprClass; 00789 } 00790 static bool classof(const CXXTemporaryObjectExpr *) { return true; } 00791 }; 00792 00793 /// CXXZeroInitValueExpr - [C++ 5.2.3p2] 00794 /// Expression "T()" which creates a value-initialized rvalue of type 00795 /// T, which is either a non-class type or a class type without any 00796 /// user-defined constructors. 00797 /// 00798 class CXXZeroInitValueExpr : public Expr { 00799 SourceLocation TyBeginLoc; 00800 SourceLocation RParenLoc; 00801 00802 public: 00803 CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc, 00804 SourceLocation rParenLoc ) : 00805 Expr(CXXZeroInitValueExprClass, ty, false, false), 00806 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 00807 00808 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 00809 SourceLocation getRParenLoc() const { return RParenLoc; } 00810 00811 /// @brief Whether this initialization expression was 00812 /// implicitly-generated. 00813 bool isImplicit() const { 00814 return TyBeginLoc.isInvalid() && RParenLoc.isInvalid(); 00815 } 00816 00817 virtual SourceRange getSourceRange() const { 00818 return SourceRange(TyBeginLoc, RParenLoc); 00819 } 00820 00821 static bool classof(const Stmt *T) { 00822 return T->getStmtClass() == CXXZeroInitValueExprClass; 00823 } 00824 static bool classof(const CXXZeroInitValueExpr *) { return true; } 00825 00826 // Iterators 00827 virtual child_iterator child_begin(); 00828 virtual child_iterator child_end(); 00829 }; 00830 00831 /// CXXNewExpr - A new expression for memory allocation and constructor calls, 00832 /// e.g: "new CXXNewExpr(foo)". 00833 class CXXNewExpr : public Expr { 00834 // Was the usage ::new, i.e. is the global new to be used? 00835 bool GlobalNew : 1; 00836 // Was the form (type-id) used? Otherwise, it was new-type-id. 00837 bool ParenTypeId : 1; 00838 // Is there an initializer? If not, built-ins are uninitialized, else they're 00839 // value-initialized. 00840 bool Initializer : 1; 00841 // Do we allocate an array? If so, the first SubExpr is the size expression. 00842 bool Array : 1; 00843 // The number of placement new arguments. 00844 unsigned NumPlacementArgs : 14; 00845 // The number of constructor arguments. This may be 1 even for non-class 00846 // types; use the pseudo copy constructor. 00847 unsigned NumConstructorArgs : 14; 00848 // Contains an optional array size expression, any number of optional 00849 // placement arguments, and any number of optional constructor arguments, 00850 // in that order. 00851 Stmt **SubExprs; 00852 // Points to the allocation function used. 00853 FunctionDecl *OperatorNew; 00854 // Points to the deallocation function used in case of error. May be null. 00855 FunctionDecl *OperatorDelete; 00856 // Points to the constructor used. Cannot be null if AllocType is a record; 00857 // it would still point at the default constructor (even an implicit one). 00858 // Must be null for all other types. 00859 CXXConstructorDecl *Constructor; 00860 00861 SourceLocation StartLoc; 00862 SourceLocation EndLoc; 00863 00864 public: 00865 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 00866 Expr **placementArgs, unsigned numPlaceArgs, bool ParenTypeId, 00867 Expr *arraySize, CXXConstructorDecl *constructor, bool initializer, 00868 Expr **constructorArgs, unsigned numConsArgs, 00869 FunctionDecl *operatorDelete, QualType ty, 00870 SourceLocation startLoc, SourceLocation endLoc); 00871 00872 virtual void DoDestroy(ASTContext &C); 00873 00874 QualType getAllocatedType() const { 00875 assert(getType()->isPointerType()); 00876 return getType()->getAs<PointerType>()->getPointeeType(); 00877 } 00878 00879 FunctionDecl *getOperatorNew() const { return OperatorNew; } 00880 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 00881 CXXConstructorDecl *getConstructor() const { return Constructor; } 00882 00883 bool isArray() const { return Array; } 00884 Expr *getArraySize() { 00885 return Array ? cast<Expr>(SubExprs[0]) : 0; 00886 } 00887 const Expr *getArraySize() const { 00888 return Array ? cast<Expr>(SubExprs[0]) : 0; 00889 } 00890 00891 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 00892 Expr *getPlacementArg(unsigned i) { 00893 assert(i < NumPlacementArgs && "Index out of range"); 00894 return cast<Expr>(SubExprs[Array + i]); 00895 } 00896 const Expr *getPlacementArg(unsigned i) const { 00897 assert(i < NumPlacementArgs && "Index out of range"); 00898 return cast<Expr>(SubExprs[Array + i]); 00899 } 00900 00901 bool isGlobalNew() const { return GlobalNew; } 00902 bool isParenTypeId() const { return ParenTypeId; } 00903 bool hasInitializer() const { return Initializer; } 00904 00905 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 00906 Expr *getConstructorArg(unsigned i) { 00907 assert(i < NumConstructorArgs && "Index out of range"); 00908 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 00909 } 00910 const Expr *getConstructorArg(unsigned i) const { 00911 assert(i < NumConstructorArgs && "Index out of range"); 00912 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 00913 } 00914 00915 typedef ExprIterator arg_iterator; 00916 typedef ConstExprIterator const_arg_iterator; 00917 00918 arg_iterator placement_arg_begin() { 00919 return SubExprs + Array; 00920 } 00921 arg_iterator placement_arg_end() { 00922 return SubExprs + Array + getNumPlacementArgs(); 00923 } 00924 const_arg_iterator placement_arg_begin() const { 00925 return SubExprs + Array; 00926 } 00927 const_arg_iterator placement_arg_end() const { 00928 return SubExprs + Array + getNumPlacementArgs(); 00929 } 00930 00931 arg_iterator constructor_arg_begin() { 00932 return SubExprs + Array + getNumPlacementArgs(); 00933 } 00934 arg_iterator constructor_arg_end() { 00935 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 00936 } 00937 const_arg_iterator constructor_arg_begin() const { 00938 return SubExprs + Array + getNumPlacementArgs(); 00939 } 00940 const_arg_iterator constructor_arg_end() const { 00941 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 00942 } 00943 00944 virtual SourceRange getSourceRange() const { 00945 return SourceRange(StartLoc, EndLoc); 00946 } 00947 00948 static bool classof(const Stmt *T) { 00949 return T->getStmtClass() == CXXNewExprClass; 00950 } 00951 static bool classof(const CXXNewExpr *) { return true; } 00952 00953 // Iterators 00954 virtual child_iterator child_begin(); 00955 virtual child_iterator child_end(); 00956 }; 00957 00958 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor 00959 /// calls, e.g. "delete[] pArray". 00960 class CXXDeleteExpr : public Expr { 00961 // Is this a forced global delete, i.e. "::delete"? 00962 bool GlobalDelete : 1; 00963 // Is this the array form of delete, i.e. "delete[]"? 00964 bool ArrayForm : 1; 00965 // Points to the operator delete overload that is used. Could be a member. 00966 FunctionDecl *OperatorDelete; 00967 // The pointer expression to be deleted. 00968 Stmt *Argument; 00969 // Location of the expression. 00970 SourceLocation Loc; 00971 public: 00972 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 00973 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 00974 : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete), 00975 ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg), 00976 Loc(loc) { } 00977 00978 bool isGlobalDelete() const { return GlobalDelete; } 00979 bool isArrayForm() const { return ArrayForm; } 00980 00981 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 00982 00983 Expr *getArgument() { return cast<Expr>(Argument); } 00984 const Expr *getArgument() const { return cast<Expr>(Argument); } 00985 00986 virtual SourceRange getSourceRange() const { 00987 return SourceRange(Loc, Argument->getLocEnd()); 00988 } 00989 00990 static bool classof(const Stmt *T) { 00991 return T->getStmtClass() == CXXDeleteExprClass; 00992 } 00993 static bool classof(const CXXDeleteExpr *) { return true; } 00994 00995 // Iterators 00996 virtual child_iterator child_begin(); 00997 virtual child_iterator child_end(); 00998 }; 00999 01000 /// \brief Structure used to store the type being destroyed by a 01001 /// pseudo-destructor expression. 01002 class PseudoDestructorTypeStorage { 01003 /// \brief Either the type source information or the name of the type, if 01004 /// it couldn't be resolved due to type-dependence. 01005 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 01006 01007 /// \brief The starting source location of the pseudo-destructor type. 01008 SourceLocation Location; 01009 01010 public: 01011 PseudoDestructorTypeStorage() { } 01012 01013 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 01014 : Type(II), Location(Loc) { } 01015 01016 PseudoDestructorTypeStorage(TypeSourceInfo *Info); 01017 01018 TypeSourceInfo *getTypeSourceInfo() const { 01019 return Type.dyn_cast<TypeSourceInfo *>(); 01020 } 01021 01022 IdentifierInfo *getIdentifier() const { 01023 return Type.dyn_cast<IdentifierInfo *>(); 01024 } 01025 01026 SourceLocation getLocation() const { return Location; } 01027 }; 01028 01029 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 01030 /// 01031 /// A pseudo-destructor is an expression that looks like a member access to a 01032 /// destructor of a scalar type, except that scalar types don't have 01033 /// destructors. For example: 01034 /// 01035 /// \code 01036 /// typedef int T; 01037 /// void f(int *p) { 01038 /// p->T::~T(); 01039 /// } 01040 /// \endcode 01041 /// 01042 /// Pseudo-destructors typically occur when instantiating templates such as: 01043 /// 01044 /// \code 01045 /// template<typename T> 01046 /// void destroy(T* ptr) { 01047 /// ptr->T::~T(); 01048 /// } 01049 /// \endcode 01050 /// 01051 /// for scalar types. A pseudo-destructor expression has no run-time semantics 01052 /// beyond evaluating the base expression. 01053 class CXXPseudoDestructorExpr : public Expr { 01054 /// \brief The base expression (that is being destroyed). 01055 Stmt *Base; 01056 01057 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 01058 /// period ('.'). 01059 bool IsArrow : 1; 01060 01061 /// \brief The location of the '.' or '->' operator. 01062 SourceLocation OperatorLoc; 01063 01064 /// \brief The nested-name-specifier that follows the operator, if present. 01065 NestedNameSpecifier *Qualifier; 01066 01067 /// \brief The source range that covers the nested-name-specifier, if 01068 /// present. 01069 SourceRange QualifierRange; 01070 01071 /// \brief The type that precedes the '::' in a qualified pseudo-destructor 01072 /// expression. 01073 TypeSourceInfo *ScopeType; 01074 01075 /// \brief The location of the '::' in a qualified pseudo-destructor 01076 /// expression. 01077 SourceLocation ColonColonLoc; 01078 01079 /// \brief The location of the '~'. 01080 SourceLocation TildeLoc; 01081 01082 /// \brief The type being destroyed, or its name if we were unable to 01083 /// resolve the name. 01084 PseudoDestructorTypeStorage DestroyedType; 01085 01086 public: 01087 CXXPseudoDestructorExpr(ASTContext &Context, 01088 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 01089 NestedNameSpecifier *Qualifier, 01090 SourceRange QualifierRange, 01091 TypeSourceInfo *ScopeType, 01092 SourceLocation ColonColonLoc, 01093 SourceLocation TildeLoc, 01094 PseudoDestructorTypeStorage DestroyedType) 01095 : Expr(CXXPseudoDestructorExprClass, 01096 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, 01097 false, 0, false, 01098 false, 0, 0, false, 01099 CC_Default)), 01100 /*isTypeDependent=*/(Base->isTypeDependent() || 01101 (DestroyedType.getTypeSourceInfo() && 01102 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())), 01103 /*isValueDependent=*/Base->isValueDependent()), 01104 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), 01105 OperatorLoc(OperatorLoc), Qualifier(Qualifier), 01106 QualifierRange(QualifierRange), 01107 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), 01108 DestroyedType(DestroyedType) { } 01109 01110 void setBase(Expr *E) { Base = E; } 01111 Expr *getBase() const { return cast<Expr>(Base); } 01112 01113 /// \brief Determines whether this member expression actually had 01114 /// a C++ nested-name-specifier prior to the name of the member, e.g., 01115 /// x->Base::foo. 01116 bool hasQualifier() const { return Qualifier != 0; } 01117 01118 /// \brief If the member name was qualified, retrieves the source range of 01119 /// the nested-name-specifier that precedes the member name. Otherwise, 01120 /// returns an empty source range. 01121 SourceRange getQualifierRange() const { return QualifierRange; } 01122 01123 /// \brief If the member name was qualified, retrieves the 01124 /// nested-name-specifier that precedes the member name. Otherwise, returns 01125 /// NULL. 01126 NestedNameSpecifier *getQualifier() const { return Qualifier; } 01127 01128 /// \brief Determine whether this pseudo-destructor expression was written 01129 /// using an '->' (otherwise, it used a '.'). 01130 bool isArrow() const { return IsArrow; } 01131 void setArrow(bool A) { IsArrow = A; } 01132 01133 /// \brief Retrieve the location of the '.' or '->' operator. 01134 SourceLocation getOperatorLoc() const { return OperatorLoc; } 01135 01136 /// \brief Retrieve the scope type in a qualified pseudo-destructor 01137 /// expression. 01138 /// 01139 /// Pseudo-destructor expressions can have extra qualification within them 01140 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 01141 /// Here, if the object type of the expression is (or may be) a scalar type, 01142 /// \p T may also be a scalar type and, therefore, cannot be part of a 01143 /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 01144 /// destructor expression. 01145 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 01146 01147 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 01148 /// expression. 01149 SourceLocation getColonColonLoc() const { return ColonColonLoc; } 01150 01151 /// \brief Retrieve the location of the '~'. 01152 SourceLocation getTildeLoc() const { return TildeLoc; } 01153 01154 /// \brief Retrieve the source location information for the type 01155 /// being destroyed. 01156 /// 01157 /// This type-source information is available for non-dependent 01158 /// pseudo-destructor expressions and some dependent pseudo-destructor 01159 /// expressions. Returns NULL if we only have the identifier for a 01160 /// dependent pseudo-destructor expression. 01161 TypeSourceInfo *getDestroyedTypeInfo() const { 01162 return DestroyedType.getTypeSourceInfo(); 01163 } 01164 01165 /// \brief In a dependent pseudo-destructor expression for which we do not 01166 /// have full type information on the destroyed type, provides the name 01167 /// of the destroyed type. 01168 IdentifierInfo *getDestroyedTypeIdentifier() const { 01169 return DestroyedType.getIdentifier(); 01170 } 01171 01172 /// \brief Retrieve the type being destroyed. 01173 QualType getDestroyedType() const; 01174 01175 /// \brief Retrieve the starting location of the type being destroyed. 01176 SourceLocation getDestroyedTypeLoc() const { 01177 return DestroyedType.getLocation(); 01178 } 01179 01180 virtual SourceRange getSourceRange() const; 01181 01182 static bool classof(const Stmt *T) { 01183 return T->getStmtClass() == CXXPseudoDestructorExprClass; 01184 } 01185 static bool classof(const CXXPseudoDestructorExpr *) { return true; } 01186 01187 // Iterators 01188 virtual child_iterator child_begin(); 01189 virtual child_iterator child_end(); 01190 }; 01191 01192 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 01193 /// implementation of TR1/C++0x type trait templates. 01194 /// Example: 01195 /// __is_pod(int) == true 01196 /// __is_enum(std::string) == false 01197 class UnaryTypeTraitExpr : public Expr { 01198 /// UTT - The trait. 01199 UnaryTypeTrait UTT; 01200 01201 /// Loc - The location of the type trait keyword. 01202 SourceLocation Loc; 01203 01204 /// RParen - The location of the closing paren. 01205 SourceLocation RParen; 01206 01207 /// QueriedType - The type we're testing. 01208 QualType QueriedType; 01209 01210 public: 01211 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried, 01212 SourceLocation rparen, QualType ty) 01213 : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()), 01214 UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { } 01215 01216 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 01217 01218 UnaryTypeTrait getTrait() const { return UTT; } 01219 01220 QualType getQueriedType() const { return QueriedType; } 01221 01222 bool EvaluateTrait(ASTContext&) const; 01223 01224 static bool classof(const Stmt *T) { 01225 return T->getStmtClass() == UnaryTypeTraitExprClass; 01226 } 01227 static bool classof(const UnaryTypeTraitExpr *) { return true; } 01228 01229 // Iterators 01230 virtual child_iterator child_begin(); 01231 virtual child_iterator child_end(); 01232 }; 01233 01234 /// \brief A reference to an overloaded function set, either an 01235 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr. 01236 class OverloadExpr : public Expr { 01237 /// The results. These are undesugared, which is to say, they may 01238 /// include UsingShadowDecls. Access is relative to the naming 01239 /// class. 01240 UnresolvedSet<4> Results; 01241 01242 /// The common name of these declarations. 01243 DeclarationName Name; 01244 01245 /// The scope specifier, if any. 01246 NestedNameSpecifier *Qualifier; 01247 01248 /// The source range of the scope specifier. 01249 SourceRange QualifierRange; 01250 01251 /// The location of the name. 01252 SourceLocation NameLoc; 01253 01254 /// True if the name was a template-id. 01255 bool HasExplicitTemplateArgs; 01256 01257 protected: 01258 OverloadExpr(StmtClass K, QualType T, bool Dependent, 01259 NestedNameSpecifier *Qualifier, SourceRange QRange, 01260 DeclarationName Name, SourceLocation NameLoc, 01261 bool HasTemplateArgs) 01262 : Expr(K, T, Dependent, Dependent), 01263 Name(Name), Qualifier(Qualifier), QualifierRange(QRange), 01264 NameLoc(NameLoc), HasExplicitTemplateArgs(HasTemplateArgs) 01265 {} 01266 01267 public: 01268 /// Computes whether an unresolved lookup on the given declarations 01269 /// and optional template arguments is type- and value-dependent. 01270 static bool ComputeDependence(UnresolvedSetIterator Begin, 01271 UnresolvedSetIterator End, 01272 const TemplateArgumentListInfo *Args); 01273 01274 /// Finds the overloaded expression in the given expression of 01275 /// OverloadTy. 01276 /// 01277 /// \return the expression (which must be there) and true if it is 01278 /// within an address-of operator. 01279 static llvm::PointerIntPair<OverloadExpr*,1> find(Expr *E) { 01280 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 01281 01282 bool op = false; 01283 E = E->IgnoreParens(); 01284 if (isa<UnaryOperator>(E)) 01285 op = true, E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens(); 01286 return llvm::PointerIntPair<OverloadExpr*,1>(cast<OverloadExpr>(E), op); 01287 } 01288 01289 void addDecls(UnresolvedSetIterator Begin, UnresolvedSetIterator End) { 01290 Results.append(Begin, End); 01291 } 01292 01293 typedef UnresolvedSetImpl::iterator decls_iterator; 01294 decls_iterator decls_begin() const { return Results.begin(); } 01295 decls_iterator decls_end() const { return Results.end(); } 01296 01297 /// Gets the decls as an unresolved set. 01298 const UnresolvedSetImpl &getDecls() { return Results; } 01299 01300 /// Gets the number of declarations in the unresolved set. 01301 unsigned getNumDecls() const { return Results.size(); } 01302 01303 /// Gets the name looked up. 01304 DeclarationName getName() const { return Name; } 01305 void setName(DeclarationName N) { Name = N; } 01306 01307 /// Gets the location of the name. 01308 SourceLocation getNameLoc() const { return NameLoc; } 01309 void setNameLoc(SourceLocation Loc) { NameLoc = Loc; } 01310 01311 /// Fetches the nested-name qualifier, if one was given. 01312 NestedNameSpecifier *getQualifier() const { return Qualifier; } 01313 01314 /// Fetches the range of the nested-name qualifier. 01315 SourceRange getQualifierRange() const { return QualifierRange; } 01316 01317 /// \brief Determines whether this expression had an explicit 01318 /// template argument list, e.g. f<int>. 01319 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 01320 01321 ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below 01322 01323 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 01324 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 01325 } 01326 01327 ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 01328 if (hasExplicitTemplateArgs()) 01329 return &getExplicitTemplateArgs(); 01330 return 0; 01331 } 01332 01333 static bool classof(const Stmt *T) { 01334 return T->getStmtClass() == UnresolvedLookupExprClass || 01335 T->getStmtClass() == UnresolvedMemberExprClass; 01336 } 01337 static bool classof(const OverloadExpr *) { return true; } 01338 }; 01339 01340 /// \brief A reference to a name which we were able to look up during 01341 /// parsing but could not resolve to a specific declaration. This 01342 /// arises in several ways: 01343 /// * we might be waiting for argument-dependent lookup 01344 /// * the name might resolve to an overloaded function 01345 /// and eventually: 01346 /// * the lookup might have included a function template 01347 /// These never include UnresolvedUsingValueDecls, which are always 01348 /// class members and therefore appear only in 01349 /// UnresolvedMemberLookupExprs. 01350 class UnresolvedLookupExpr : public OverloadExpr { 01351 /// True if these lookup results should be extended by 01352 /// argument-dependent lookup if this is the operand of a function 01353 /// call. 01354 bool RequiresADL; 01355 01356 /// True if these lookup results are overloaded. This is pretty 01357 /// trivially rederivable if we urgently need to kill this field. 01358 bool Overloaded; 01359 01360 /// The naming class (C++ [class.access.base]p5) of the lookup, if 01361 /// any. This can generally be recalculated from the context chain, 01362 /// but that can be fairly expensive for unqualified lookups. If we 01363 /// want to improve memory use here, this could go in a union 01364 /// against the qualified-lookup bits. 01365 CXXRecordDecl *NamingClass; 01366 01367 UnresolvedLookupExpr(QualType T, bool Dependent, CXXRecordDecl *NamingClass, 01368 NestedNameSpecifier *Qualifier, SourceRange QRange, 01369 DeclarationName Name, SourceLocation NameLoc, 01370 bool RequiresADL, bool Overloaded, bool HasTemplateArgs) 01371 : OverloadExpr(UnresolvedLookupExprClass, T, Dependent, Qualifier, QRange, 01372 Name, NameLoc, HasTemplateArgs), 01373 RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass) 01374 {} 01375 01376 public: 01377 static UnresolvedLookupExpr *Create(ASTContext &C, 01378 bool Dependent, 01379 CXXRecordDecl *NamingClass, 01380 NestedNameSpecifier *Qualifier, 01381 SourceRange QualifierRange, 01382 DeclarationName Name, 01383 SourceLocation NameLoc, 01384 bool ADL, bool Overloaded) { 01385 return new(C) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy, 01386 Dependent, NamingClass, 01387 Qualifier, QualifierRange, 01388 Name, NameLoc, ADL, Overloaded, false); 01389 } 01390 01391 static UnresolvedLookupExpr *Create(ASTContext &C, 01392 bool Dependent, 01393 CXXRecordDecl *NamingClass, 01394 NestedNameSpecifier *Qualifier, 01395 SourceRange QualifierRange, 01396 DeclarationName Name, 01397 SourceLocation NameLoc, 01398 bool ADL, 01399 const TemplateArgumentListInfo &Args); 01400 01401 /// True if this declaration should be extended by 01402 /// argument-dependent lookup. 01403 bool requiresADL() const { return RequiresADL; } 01404 01405 /// True if this lookup is overloaded. 01406 bool isOverloaded() const { return Overloaded; } 01407 01408 /// Gets the 'naming class' (in the sense of C++0x 01409 /// [class.access.base]p5) of the lookup. This is the scope 01410 /// that was looked in to find these results. 01411 CXXRecordDecl *getNamingClass() const { return NamingClass; } 01412 01413 // Note that, inconsistently with the explicit-template-argument AST 01414 // nodes, users are *forbidden* from calling these methods on objects 01415 // without explicit template arguments. 01416 01417 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 01418 assert(hasExplicitTemplateArgs()); 01419 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1); 01420 } 01421 01422 /// Gets a reference to the explicit template argument list. 01423 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 01424 assert(hasExplicitTemplateArgs()); 01425 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 01426 } 01427 01428 /// \brief Copies the template arguments (if present) into the given 01429 /// structure. 01430 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 01431 getExplicitTemplateArgs().copyInto(List); 01432 } 01433 01434 SourceLocation getLAngleLoc() const { 01435 return getExplicitTemplateArgs().LAngleLoc; 01436 } 01437 01438 SourceLocation getRAngleLoc() const { 01439 return getExplicitTemplateArgs().RAngleLoc; 01440 } 01441 01442 TemplateArgumentLoc const *getTemplateArgs() const { 01443 return getExplicitTemplateArgs().getTemplateArgs(); 01444 } 01445 01446 unsigned getNumTemplateArgs() const { 01447 return getExplicitTemplateArgs().NumTemplateArgs; 01448 } 01449 01450 virtual SourceRange getSourceRange() const { 01451 SourceRange Range(getNameLoc()); 01452 if (getQualifier()) Range.setBegin(getQualifierRange().getBegin()); 01453 if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc()); 01454 return Range; 01455 } 01456 01457 virtual StmtIterator child_begin(); 01458 virtual StmtIterator child_end(); 01459 01460 static bool classof(const Stmt *T) { 01461 return T->getStmtClass() == UnresolvedLookupExprClass; 01462 } 01463 static bool classof(const UnresolvedLookupExpr *) { return true; } 01464 }; 01465 01466 /// \brief A qualified reference to a name whose declaration cannot 01467 /// yet be resolved. 01468 /// 01469 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 01470 /// it expresses a reference to a declaration such as 01471 /// X<T>::value. The difference, however, is that an 01472 /// DependentScopeDeclRefExpr node is used only within C++ templates when 01473 /// the qualification (e.g., X<T>::) refers to a dependent type. In 01474 /// this case, X<T>::value cannot resolve to a declaration because the 01475 /// declaration will differ from on instantiation of X<T> to the 01476 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the 01477 /// qualifier (X<T>::) and the name of the entity being referenced 01478 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the 01479 /// declaration can be found. 01480 class DependentScopeDeclRefExpr : public Expr { 01481 /// The name of the entity we will be referencing. 01482 DeclarationName Name; 01483 01484 /// Location of the name of the declaration we're referencing. 01485 SourceLocation Loc; 01486 01487 /// QualifierRange - The source range that covers the 01488 /// nested-name-specifier. 01489 SourceRange QualifierRange; 01490 01491 /// \brief The nested-name-specifier that qualifies this unresolved 01492 /// declaration name. 01493 NestedNameSpecifier *Qualifier; 01494 01495 /// \brief Whether the name includes explicit template arguments. 01496 bool HasExplicitTemplateArgs; 01497 01498 DependentScopeDeclRefExpr(QualType T, 01499 NestedNameSpecifier *Qualifier, 01500 SourceRange QualifierRange, 01501 DeclarationName Name, 01502 SourceLocation NameLoc, 01503 bool HasExplicitTemplateArgs) 01504 : Expr(DependentScopeDeclRefExprClass, T, true, true), 01505 Name(Name), Loc(NameLoc), 01506 QualifierRange(QualifierRange), Qualifier(Qualifier), 01507 HasExplicitTemplateArgs(HasExplicitTemplateArgs) 01508 {} 01509 01510 public: 01511 static DependentScopeDeclRefExpr *Create(ASTContext &C, 01512 NestedNameSpecifier *Qualifier, 01513 SourceRange QualifierRange, 01514 DeclarationName Name, 01515 SourceLocation NameLoc, 01516 const TemplateArgumentListInfo *TemplateArgs = 0); 01517 01518 /// \brief Retrieve the name that this expression refers to. 01519 DeclarationName getDeclName() const { return Name; } 01520 01521 /// \brief Retrieve the location of the name within the expression. 01522 SourceLocation getLocation() const { return Loc; } 01523 01524 /// \brief Retrieve the source range of the nested-name-specifier. 01525 SourceRange getQualifierRange() const { return QualifierRange; } 01526 01527 /// \brief Retrieve the nested-name-specifier that qualifies this 01528 /// declaration. 01529 NestedNameSpecifier *getQualifier() const { return Qualifier; } 01530 01531 /// Determines whether this lookup had explicit template arguments. 01532 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 01533 01534 // Note that, inconsistently with the explicit-template-argument AST 01535 // nodes, users are *forbidden* from calling these methods on objects 01536 // without explicit template arguments. 01537 01538 /// Gets a reference to the explicit template argument list. 01539 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 01540 assert(hasExplicitTemplateArgs()); 01541 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 01542 } 01543 01544 /// \brief Copies the template arguments (if present) into the given 01545 /// structure. 01546 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 01547 getExplicitTemplateArgs().copyInto(List); 01548 } 01549 01550 SourceLocation getLAngleLoc() const { 01551 return getExplicitTemplateArgs().LAngleLoc; 01552 } 01553 01554 SourceLocation getRAngleLoc() const { 01555 return getExplicitTemplateArgs().RAngleLoc; 01556 } 01557 01558 TemplateArgumentLoc const *getTemplateArgs() const { 01559 return getExplicitTemplateArgs().getTemplateArgs(); 01560 } 01561 01562 unsigned getNumTemplateArgs() const { 01563 return getExplicitTemplateArgs().NumTemplateArgs; 01564 } 01565 01566 virtual SourceRange getSourceRange() const { 01567 SourceRange Range(QualifierRange.getBegin(), getLocation()); 01568 if (hasExplicitTemplateArgs()) 01569 Range.setEnd(getRAngleLoc()); 01570 return Range; 01571 } 01572 01573 static bool classof(const Stmt *T) { 01574 return T->getStmtClass() == DependentScopeDeclRefExprClass; 01575 } 01576 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 01577 01578 virtual StmtIterator child_begin(); 01579 virtual StmtIterator child_end(); 01580 }; 01581 01582 class CXXExprWithTemporaries : public Expr { 01583 Stmt *SubExpr; 01584 01585 CXXTemporary **Temps; 01586 unsigned NumTemps; 01587 01588 CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps, 01589 unsigned NumTemps); 01590 ~CXXExprWithTemporaries(); 01591 01592 protected: 01593 virtual void DoDestroy(ASTContext &C); 01594 01595 public: 01596 static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr, 01597 CXXTemporary **Temps, 01598 unsigned NumTemps); 01599 01600 unsigned getNumTemporaries() const { return NumTemps; } 01601 CXXTemporary *getTemporary(unsigned i) { 01602 assert(i < NumTemps && "Index out of range"); 01603 return Temps[i]; 01604 } 01605 const CXXTemporary *getTemporary(unsigned i) const { 01606 return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i); 01607 } 01608 01609 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 01610 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 01611 void setSubExpr(Expr *E) { SubExpr = E; } 01612 01613 virtual SourceRange getSourceRange() const { 01614 return SubExpr->getSourceRange(); 01615 } 01616 01617 // Implement isa/cast/dyncast/etc. 01618 static bool classof(const Stmt *T) { 01619 return T->getStmtClass() == CXXExprWithTemporariesClass; 01620 } 01621 static bool classof(const CXXExprWithTemporaries *) { return true; } 01622 01623 // Iterators 01624 virtual child_iterator child_begin(); 01625 virtual child_iterator child_end(); 01626 }; 01627 01628 /// \brief Describes an explicit type conversion that uses functional 01629 /// notion but could not be resolved because one or more arguments are 01630 /// type-dependent. 01631 /// 01632 /// The explicit type conversions expressed by 01633 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 01634 /// where \c T is some type and \c a1, a2, ..., aN are values, and 01635 /// either \C T is a dependent type or one or more of the \c a's is 01636 /// type-dependent. For example, this would occur in a template such 01637 /// as: 01638 /// 01639 /// \code 01640 /// template<typename T, typename A1> 01641 /// inline T make_a(const A1& a1) { 01642 /// return T(a1); 01643 /// } 01644 /// \endcode 01645 /// 01646 /// When the returned expression is instantiated, it may resolve to a 01647 /// constructor call, conversion function call, or some kind of type 01648 /// conversion. 01649 class CXXUnresolvedConstructExpr : public Expr { 01650 /// \brief The starting location of the type 01651 SourceLocation TyBeginLoc; 01652 01653 /// \brief The type being constructed. 01654 QualType Type; 01655 01656 /// \brief The location of the left parentheses ('('). 01657 SourceLocation LParenLoc; 01658 01659 /// \brief The location of the right parentheses (')'). 01660 SourceLocation RParenLoc; 01661 01662 /// \brief The number of arguments used to construct the type. 01663 unsigned NumArgs; 01664 01665 CXXUnresolvedConstructExpr(SourceLocation TyBegin, 01666 QualType T, 01667 SourceLocation LParenLoc, 01668 Expr **Args, 01669 unsigned NumArgs, 01670 SourceLocation RParenLoc); 01671 01672 public: 01673 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 01674 SourceLocation TyBegin, 01675 QualType T, 01676 SourceLocation LParenLoc, 01677 Expr **Args, 01678 unsigned NumArgs, 01679 SourceLocation RParenLoc); 01680 01681 /// \brief Retrieve the source location where the type begins. 01682 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 01683 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 01684 01685 /// \brief Retrieve the type that is being constructed, as specified 01686 /// in the source code. 01687 QualType getTypeAsWritten() const { return Type; } 01688 void setTypeAsWritten(QualType T) { Type = T; } 01689 01690 /// \brief Retrieve the location of the left parentheses ('(') that 01691 /// precedes the argument list. 01692 SourceLocation getLParenLoc() const { return LParenLoc; } 01693 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 01694 01695 /// \brief Retrieve the location of the right parentheses (')') that 01696 /// follows the argument list. 01697 SourceLocation getRParenLoc() const { return RParenLoc; } 01698 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 01699 01700 /// \brief Retrieve the number of arguments. 01701 unsigned arg_size() const { return NumArgs; } 01702 01703 typedef Expr** arg_iterator; 01704 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 01705 arg_iterator arg_end() { return arg_begin() + NumArgs; } 01706 01707 typedef const Expr* const * const_arg_iterator; 01708 const_arg_iterator arg_begin() const { 01709 return reinterpret_cast<const Expr* const *>(this + 1); 01710 } 01711 const_arg_iterator arg_end() const { 01712 return arg_begin() + NumArgs; 01713 } 01714 01715 Expr *getArg(unsigned I) { 01716 assert(I < NumArgs && "Argument index out-of-range"); 01717 return *(arg_begin() + I); 01718 } 01719 01720 const Expr *getArg(unsigned I) const { 01721 assert(I < NumArgs && "Argument index out-of-range"); 01722 return *(arg_begin() + I); 01723 } 01724 01725 virtual SourceRange getSourceRange() const { 01726 return SourceRange(TyBeginLoc, RParenLoc); 01727 } 01728 static bool classof(const Stmt *T) { 01729 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 01730 } 01731 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 01732 01733 // Iterators 01734 virtual child_iterator child_begin(); 01735 virtual child_iterator child_end(); 01736 }; 01737 01738 /// \brief Represents a C++ member access expression where the actual 01739 /// member referenced could not be resolved because the base 01740 /// expression or the member name was dependent. 01741 /// 01742 /// Like UnresolvedMemberExprs, these can be either implicit or 01743 /// explicit accesses. It is only possible to get one of these with 01744 /// an implicit access if a qualifier is provided. 01745 class CXXDependentScopeMemberExpr : public Expr { 01746 /// \brief The expression for the base pointer or class reference, 01747 /// e.g., the \c x in x.f. Can be null in implicit accesses. 01748 Stmt *Base; 01749 01750 /// \brief The type of the base expression. Never null, even for 01751 /// implicit accesses. 01752 QualType BaseType; 01753 01754 /// \brief Whether this member expression used the '->' operator or 01755 /// the '.' operator. 01756 bool IsArrow : 1; 01757 01758 /// \brief Whether this member expression has explicitly-specified template 01759 /// arguments. 01760 bool HasExplicitTemplateArgs : 1; 01761 01762 /// \brief The location of the '->' or '.' operator. 01763 SourceLocation OperatorLoc; 01764 01765 /// \brief The nested-name-specifier that precedes the member name, if any. 01766 NestedNameSpecifier *Qualifier; 01767 01768 /// \brief The source range covering the nested name specifier. 01769 SourceRange QualifierRange; 01770 01771 /// \brief In a qualified member access expression such as t->Base::f, this 01772 /// member stores the resolves of name lookup in the context of the member 01773 /// access expression, to be used at instantiation time. 01774 /// 01775 /// FIXME: This member, along with the Qualifier and QualifierRange, could 01776 /// be stuck into a structure that is optionally allocated at the end of 01777 /// the CXXDependentScopeMemberExpr, to save space in the common case. 01778 NamedDecl *FirstQualifierFoundInScope; 01779 01780 /// \brief The member to which this member expression refers, which 01781 /// can be name, overloaded operator, or destructor. 01782 /// FIXME: could also be a template-id 01783 DeclarationName Member; 01784 01785 /// \brief The location of the member name. 01786 SourceLocation MemberLoc; 01787 01788 /// \brief Retrieve the explicit template argument list that followed the 01789 /// member template name, if any. 01790 ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 01791 assert(HasExplicitTemplateArgs); 01792 return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 01793 } 01794 01795 /// \brief Retrieve the explicit template argument list that followed the 01796 /// member template name, if any. 01797 const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 01798 return const_cast<CXXDependentScopeMemberExpr *>(this) 01799 ->getExplicitTemplateArgumentList(); 01800 } 01801 01802 CXXDependentScopeMemberExpr(ASTContext &C, 01803 Expr *Base, QualType BaseType, bool IsArrow, 01804 SourceLocation OperatorLoc, 01805 NestedNameSpecifier *Qualifier, 01806 SourceRange QualifierRange, 01807 NamedDecl *FirstQualifierFoundInScope, 01808 DeclarationName Member, 01809 SourceLocation MemberLoc, 01810 const TemplateArgumentListInfo *TemplateArgs); 01811 01812 public: 01813 CXXDependentScopeMemberExpr(ASTContext &C, 01814 Expr *Base, QualType BaseType, 01815 bool IsArrow, 01816 SourceLocation OperatorLoc, 01817 NestedNameSpecifier *Qualifier, 01818 SourceRange QualifierRange, 01819 NamedDecl *FirstQualifierFoundInScope, 01820 DeclarationName Member, 01821 SourceLocation MemberLoc) 01822 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true), 01823 Base(Base), BaseType(BaseType), IsArrow(IsArrow), 01824 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc), 01825 Qualifier(Qualifier), QualifierRange(QualifierRange), 01826 FirstQualifierFoundInScope(FirstQualifierFoundInScope), 01827 Member(Member), MemberLoc(MemberLoc) { } 01828 01829 static CXXDependentScopeMemberExpr * 01830 Create(ASTContext &C, 01831 Expr *Base, QualType BaseType, bool IsArrow, 01832 SourceLocation OperatorLoc, 01833 NestedNameSpecifier *Qualifier, 01834 SourceRange QualifierRange, 01835 NamedDecl *FirstQualifierFoundInScope, 01836 DeclarationName Member, 01837 SourceLocation MemberLoc, 01838 const TemplateArgumentListInfo *TemplateArgs); 01839 01840 /// \brief True if this is an implicit access, i.e. one in which the 01841 /// member being accessed was not written in the source. The source 01842 /// location of the operator is invalid in this case. 01843 bool isImplicitAccess() const { return Base == 0; } 01844 01845 /// \brief Retrieve the base object of this member expressions, 01846 /// e.g., the \c x in \c x.m. 01847 Expr *getBase() const { 01848 assert(!isImplicitAccess()); 01849 return cast<Expr>(Base); 01850 } 01851 void setBase(Expr *E) { Base = E; } 01852 01853 QualType getBaseType() const { return BaseType; } 01854 01855 /// \brief Determine whether this member expression used the '->' 01856 /// operator; otherwise, it used the '.' operator. 01857 bool isArrow() const { return IsArrow; } 01858 void setArrow(bool A) { IsArrow = A; } 01859 01860 /// \brief Retrieve the location of the '->' or '.' operator. 01861 SourceLocation getOperatorLoc() const { return OperatorLoc; } 01862 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 01863 01864 /// \brief Retrieve the nested-name-specifier that qualifies the member 01865 /// name. 01866 NestedNameSpecifier *getQualifier() const { return Qualifier; } 01867 01868 /// \brief Retrieve the source range covering the nested-name-specifier 01869 /// that qualifies the member name. 01870 SourceRange getQualifierRange() const { return QualifierRange; } 01871 01872 /// \brief Retrieve the first part of the nested-name-specifier that was 01873 /// found in the scope of the member access expression when the member access 01874 /// was initially parsed. 01875 /// 01876 /// This function only returns a useful result when member access expression 01877 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 01878 /// returned by this function describes what was found by unqualified name 01879 /// lookup for the identifier "Base" within the scope of the member access 01880 /// expression itself. At template instantiation time, this information is 01881 /// combined with the results of name lookup into the type of the object 01882 /// expression itself (the class type of x). 01883 NamedDecl *getFirstQualifierFoundInScope() const { 01884 return FirstQualifierFoundInScope; 01885 } 01886 01887 /// \brief Retrieve the name of the member that this expression 01888 /// refers to. 01889 DeclarationName getMember() const { return Member; } 01890 void setMember(DeclarationName N) { Member = N; } 01891 01892 // \brief Retrieve the location of the name of the member that this 01893 // expression refers to. 01894 SourceLocation getMemberLoc() const { return MemberLoc; } 01895 void setMemberLoc(SourceLocation L) { MemberLoc = L; } 01896 01897 /// \brief Determines whether this member expression actually had a C++ 01898 /// template argument list explicitly specified, e.g., x.f<int>. 01899 bool hasExplicitTemplateArgs() const { 01900 return HasExplicitTemplateArgs; 01901 } 01902 01903 /// \brief Copies the template arguments (if present) into the given 01904 /// structure. 01905 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 01906 assert(HasExplicitTemplateArgs); 01907 getExplicitTemplateArgumentList()->copyInto(List); 01908 } 01909 01910 /// \brief Retrieve the location of the left angle bracket following the 01911 /// member name ('<'), if any. 01912 SourceLocation getLAngleLoc() const { 01913 assert(HasExplicitTemplateArgs); 01914 return getExplicitTemplateArgumentList()->LAngleLoc; 01915 } 01916 01917 /// \brief Retrieve the template arguments provided as part of this 01918 /// template-id. 01919 const TemplateArgumentLoc *getTemplateArgs() const { 01920 assert(HasExplicitTemplateArgs); 01921 return getExplicitTemplateArgumentList()->getTemplateArgs(); 01922 } 01923 01924 /// \brief Retrieve the number of template arguments provided as part of this 01925 /// template-id. 01926 unsigned getNumTemplateArgs() const { 01927 assert(HasExplicitTemplateArgs); 01928 return getExplicitTemplateArgumentList()->NumTemplateArgs; 01929 } 01930 01931 /// \brief Retrieve the location of the right angle bracket following the 01932 /// template arguments ('>'). 01933 SourceLocation getRAngleLoc() const { 01934 assert(HasExplicitTemplateArgs); 01935 return getExplicitTemplateArgumentList()->RAngleLoc; 01936 } 01937 01938 virtual SourceRange getSourceRange() const { 01939 SourceRange Range; 01940 if (!isImplicitAccess()) 01941 Range.setBegin(Base->getSourceRange().getBegin()); 01942 else if (getQualifier()) 01943 Range.setBegin(getQualifierRange().getBegin()); 01944 else 01945 Range.setBegin(MemberLoc); 01946 01947 if (hasExplicitTemplateArgs()) 01948 Range.setEnd(getRAngleLoc()); 01949 else 01950 Range.setEnd(MemberLoc); 01951 return Range; 01952 } 01953 01954 static bool classof(const Stmt *T) { 01955 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 01956 } 01957 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 01958 01959 // Iterators 01960 virtual child_iterator child_begin(); 01961 virtual child_iterator child_end(); 01962 }; 01963 01964 /// \brief Represents a C++ member access expression for which lookup 01965 /// produced a set of overloaded functions. 01966 /// 01967 /// The member access may be explicit or implicit: 01968 /// struct A { 01969 /// int a, b; 01970 /// int explicitAccess() { return this->a + this->A::b; } 01971 /// int implicitAccess() { return a + A::b; } 01972 /// }; 01973 /// 01974 /// In the final AST, an explicit access always becomes a MemberExpr. 01975 /// An implicit access may become either a MemberExpr or a 01976 /// DeclRefExpr, depending on whether the member is static. 01977 class UnresolvedMemberExpr : public OverloadExpr { 01978 /// \brief Whether this member expression used the '->' operator or 01979 /// the '.' operator. 01980 bool IsArrow : 1; 01981 01982 /// \brief Whether the lookup results contain an unresolved using 01983 /// declaration. 01984 bool HasUnresolvedUsing : 1; 01985 01986 /// \brief The expression for the base pointer or class reference, 01987 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 01988 /// member expression 01989 Stmt *Base; 01990 01991 /// \brief The type of the base expression; never null. 01992 QualType BaseType; 01993 01994 /// \brief The location of the '->' or '.' operator. 01995 SourceLocation OperatorLoc; 01996 01997 UnresolvedMemberExpr(QualType T, bool Dependent, 01998 bool HasUnresolvedUsing, 01999 Expr *Base, QualType BaseType, bool IsArrow, 02000 SourceLocation OperatorLoc, 02001 NestedNameSpecifier *Qualifier, 02002 SourceRange QualifierRange, 02003 DeclarationName Member, 02004 SourceLocation MemberLoc, 02005 const TemplateArgumentListInfo *TemplateArgs); 02006 02007 public: 02008 static UnresolvedMemberExpr * 02009 Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing, 02010 Expr *Base, QualType BaseType, bool IsArrow, 02011 SourceLocation OperatorLoc, 02012 NestedNameSpecifier *Qualifier, 02013 SourceRange QualifierRange, 02014 DeclarationName Member, 02015 SourceLocation MemberLoc, 02016 const TemplateArgumentListInfo *TemplateArgs); 02017 02018 /// \brief True if this is an implicit access, i.e. one in which the 02019 /// member being accessed was not written in the source. The source 02020 /// location of the operator is invalid in this case. 02021 bool isImplicitAccess() const { return Base == 0; } 02022 02023 /// \brief Retrieve the base object of this member expressions, 02024 /// e.g., the \c x in \c x.m. 02025 Expr *getBase() { 02026 assert(!isImplicitAccess()); 02027 return cast<Expr>(Base); 02028 } 02029 const Expr *getBase() const { 02030 assert(!isImplicitAccess()); 02031 return cast<Expr>(Base); 02032 } 02033 void setBase(Expr *E) { Base = E; } 02034 02035 QualType getBaseType() const { return BaseType; } 02036 02037 /// \brief Determine whether this member expression used the '->' 02038 /// operator; otherwise, it used the '.' operator. 02039 bool isArrow() const { return IsArrow; } 02040 void setArrow(bool A) { IsArrow = A; } 02041 02042 /// \brief Retrieve the location of the '->' or '.' operator. 02043 SourceLocation getOperatorLoc() const { return OperatorLoc; } 02044 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 02045 02046 /// \brief Retrieves the naming class of this lookup. 02047 CXXRecordDecl *getNamingClass() const; 02048 02049 /// \brief Retrieve the name of the member that this expression 02050 /// refers to. 02051 DeclarationName getMemberName() const { return getName(); } 02052 void setMemberName(DeclarationName N) { setName(N); } 02053 02054 // \brief Retrieve the location of the name of the member that this 02055 // expression refers to. 02056 SourceLocation getMemberLoc() const { return getNameLoc(); } 02057 void setMemberLoc(SourceLocation L) { setNameLoc(L); } 02058 02059 /// \brief Retrieve the explicit template argument list that followed the 02060 /// member template name. 02061 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 02062 assert(hasExplicitTemplateArgs()); 02063 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 02064 } 02065 02066 /// \brief Retrieve the explicit template argument list that followed the 02067 /// member template name, if any. 02068 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 02069 assert(hasExplicitTemplateArgs()); 02070 return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1); 02071 } 02072 02073 /// \brief Copies the template arguments into the given structure. 02074 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 02075 getExplicitTemplateArgs().copyInto(List); 02076 } 02077 02078 /// \brief Retrieve the location of the left angle bracket following 02079 /// the member name ('<'). 02080 SourceLocation getLAngleLoc() const { 02081 return getExplicitTemplateArgs().LAngleLoc; 02082 } 02083 02084 /// \brief Retrieve the template arguments provided as part of this 02085 /// template-id. 02086 const TemplateArgumentLoc *getTemplateArgs() const { 02087 return getExplicitTemplateArgs().getTemplateArgs(); 02088 } 02089 02090 /// \brief Retrieve the number of template arguments provided as 02091 /// part of this template-id. 02092 unsigned getNumTemplateArgs() const { 02093 return getExplicitTemplateArgs().NumTemplateArgs; 02094 } 02095 02096 /// \brief Retrieve the location of the right angle bracket 02097 /// following the template arguments ('>'). 02098 SourceLocation getRAngleLoc() const { 02099 return getExplicitTemplateArgs().RAngleLoc; 02100 } 02101 02102 virtual SourceRange getSourceRange() const { 02103 SourceRange Range; 02104 if (!isImplicitAccess()) 02105 Range.setBegin(Base->getSourceRange().getBegin()); 02106 else if (getQualifier()) 02107 Range.setBegin(getQualifierRange().getBegin()); 02108 else 02109 Range.setBegin(getMemberLoc()); 02110 02111 if (hasExplicitTemplateArgs()) 02112 Range.setEnd(getRAngleLoc()); 02113 else 02114 Range.setEnd(getMemberLoc()); 02115 return Range; 02116 } 02117 02118 static bool classof(const Stmt *T) { 02119 return T->getStmtClass() == UnresolvedMemberExprClass; 02120 } 02121 static bool classof(const UnresolvedMemberExpr *) { return true; } 02122 02123 // Iterators 02124 virtual child_iterator child_begin(); 02125 virtual child_iterator child_end(); 02126 }; 02127 02128 inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() { 02129 if (isa<UnresolvedLookupExpr>(this)) 02130 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs(); 02131 else 02132 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs(); 02133 } 02134 02135 } // end namespace clang 02136 02137 #endif