ExprCXX.h revision 0ece491d8f62ce67f047491a6703fac0d3bd4ff4
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The LLVM Compiler Infrastructure 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// License. See LICENSE.TXT for details. 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file defines the Expr interface and subclasses for C++ expressions. 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef LLVM_CLANG_AST_EXPRCXX_H 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define LLVM_CLANG_AST_EXPRCXX_H 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/Basic/TypeTraits.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Expr.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Decl.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/TemplateBase.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace clang { 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class CXXConstructorDecl; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class CXXDestructorDecl; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class CXXMethodDecl; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class CXXTemporary; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class TemplateArgumentListInfo; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===--------------------------------------------------------------------===// 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// C++ Expressions. 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===--------------------------------------------------------------------===// 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// \brief A call to an overloaded operator written using operator 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// syntax. 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Represents a call to an overloaded operator written using operator 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// normal call, this AST node provides better information about the 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// syntactic representation of the call. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// In a C++ template, this expression node kind will be used whenever 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// any of the arguments are type-dependent. In this case, the 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// function itself will be a (possibly empty) set of functions and 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// function templates that were found by name lookup at template 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// definition time. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CXXOperatorCallExpr : public CallExpr { 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief The overloaded operator. 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OverloadedOperatorKind Operator; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr **args, unsigned numargs, QualType t, 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation operatorloc) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : CallExpr(C, CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc), 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Operator(Op) {} 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CallExpr(C, CXXOperatorCallExprClass, Empty) { } 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getOperator - Returns the kind of overloaded operator that this 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// expression refers to. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OverloadedOperatorKind getOperator() const { return Operator; } 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; } 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getOperatorLoc - Returns the location of the operator symbol in 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// the expression. When @c getOperator()==OO_Call, this is the 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// location of the right parentheses; when @c 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getOperator()==OO_Subscript, this is the location of the right 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// bracket. 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getOperatorLoc() const { return getRParenLoc(); } 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceRange getSourceRange() const; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == CXXOperatorCallExprClass; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const CXXOperatorCallExpr *) { return true; } 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// CXXMemberCallExpr - Represents a call to a member function that 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// may be written either with member call syntax (e.g., "obj.func()" 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// or "objptr->func()") or with normal function-call syntax 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ("func()") within a member function that ends up calling a member 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// function. The callee in either case is a MemberExpr that contains 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// both the object argument and the member function, while the 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// arguments are the arguments within the parentheses (not including 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// the object argument). 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CXXMemberCallExpr : public CallExpr { 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CXXMemberCallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType t, SourceLocation rparenloc) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : CallExpr(C, CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) {} 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getImplicitObjectArgument - Retrieves the implicit object 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// argument for the member call. For example, in "x.f(5)", this 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// operation would return "x". 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *getImplicitObjectArgument(); 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceRange getSourceRange() const; 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == CXXMemberCallExprClass; 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const CXXMemberCallExpr *) { return true; } 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// const_cast. 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// This abstract class is inherited by all of the classes 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// representing "named" casts, e.g., CXXStaticCastExpr, 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CXXNamedCastExpr : public ExplicitCastExpr { 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)private: 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation Loc; // the location of the casting op 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)protected: 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CXXNamedCastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op, 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType writtenTy, SourceLocation l) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : ExplicitCastExpr(SC, ty, kind, op, writtenTy), Loc(l) {} 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *getCastName() const; 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief Retrieve the location of the cast operator keyword, e.g., 128 /// "static_cast". 129 SourceLocation getOperatorLoc() const { return Loc; } 130 void setOperatorLoc(SourceLocation L) { Loc = L; } 131 132 virtual SourceRange getSourceRange() const { 133 return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); 134 } 135 static bool classof(const Stmt *T) { 136 switch (T->getStmtClass()) { 137 case CXXNamedCastExprClass: 138 case CXXStaticCastExprClass: 139 case CXXDynamicCastExprClass: 140 case CXXReinterpretCastExprClass: 141 case CXXConstCastExprClass: 142 return true; 143 default: 144 return false; 145 } 146 } 147 static bool classof(const CXXNamedCastExpr *) { return true; } 148}; 149 150/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]). 151/// 152/// This expression node represents a C++ static cast, e.g., 153/// @c static_cast<int>(1.0). 154class CXXStaticCastExpr : public CXXNamedCastExpr { 155public: 156 CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op, 157 QualType writtenTy, SourceLocation l) 158 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, writtenTy, l) {} 159 160 static bool classof(const Stmt *T) { 161 return T->getStmtClass() == CXXStaticCastExprClass; 162 } 163 static bool classof(const CXXStaticCastExpr *) { return true; } 164}; 165 166/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 167/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 168/// determine how to perform the type cast. 169/// 170/// This expression node represents a dynamic cast, e.g., 171/// @c dynamic_cast<Derived*>(BasePtr). 172class CXXDynamicCastExpr : public CXXNamedCastExpr { 173public: 174 CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op, QualType writtenTy, 175 SourceLocation l) 176 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, writtenTy, l) {} 177 178 static bool classof(const Stmt *T) { 179 return T->getStmtClass() == CXXDynamicCastExprClass; 180 } 181 static bool classof(const CXXDynamicCastExpr *) { return true; } 182}; 183 184/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 185/// [expr.reinterpret.cast]), which provides a differently-typed view 186/// of a value but performs no actual work at run time. 187/// 188/// This expression node represents a reinterpret cast, e.g., 189/// @c reinterpret_cast<int>(VoidPtr). 190class CXXReinterpretCastExpr : public CXXNamedCastExpr { 191public: 192 CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op, 193 QualType writtenTy, SourceLocation l) 194 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op, 195 writtenTy, l) {} 196 197 static bool classof(const Stmt *T) { 198 return T->getStmtClass() == CXXReinterpretCastExprClass; 199 } 200 static bool classof(const CXXReinterpretCastExpr *) { return true; } 201}; 202 203/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 204/// which can remove type qualifiers but does not change the underlying value. 205/// 206/// This expression node represents a const cast, e.g., 207/// @c const_cast<char*>(PtrToConstChar). 208class CXXConstCastExpr : public CXXNamedCastExpr { 209public: 210 CXXConstCastExpr(QualType ty, Expr *op, QualType writtenTy, 211 SourceLocation l) 212 : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op, writtenTy, l) {} 213 214 static bool classof(const Stmt *T) { 215 return T->getStmtClass() == CXXConstCastExprClass; 216 } 217 static bool classof(const CXXConstCastExpr *) { return true; } 218}; 219 220/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 221/// 222class CXXBoolLiteralExpr : public Expr { 223 bool Value; 224 SourceLocation Loc; 225public: 226 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 227 Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {} 228 229 bool getValue() const { return Value; } 230 231 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 232 233 static bool classof(const Stmt *T) { 234 return T->getStmtClass() == CXXBoolLiteralExprClass; 235 } 236 static bool classof(const CXXBoolLiteralExpr *) { return true; } 237 238 // Iterators 239 virtual child_iterator child_begin(); 240 virtual child_iterator child_end(); 241}; 242 243/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 244class CXXNullPtrLiteralExpr : public Expr { 245 SourceLocation Loc; 246public: 247 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 248 Expr(CXXNullPtrLiteralExprClass, Ty), Loc(l) {} 249 250 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 251 252 static bool classof(const Stmt *T) { 253 return T->getStmtClass() == CXXNullPtrLiteralExprClass; 254 } 255 static bool classof(const CXXNullPtrLiteralExpr *) { return true; } 256 257 virtual child_iterator child_begin(); 258 virtual child_iterator child_end(); 259}; 260 261/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 262/// the type_info that corresponds to the supplied type, or the (possibly 263/// dynamic) type of the supplied expression. 264/// 265/// This represents code like @c typeid(int) or @c typeid(*objPtr) 266class CXXTypeidExpr : public Expr { 267private: 268 bool isTypeOp : 1; 269 union { 270 void *Ty; 271 Stmt *Ex; 272 } Operand; 273 SourceRange Range; 274 275public: 276 CXXTypeidExpr(bool isTypeOp, void *op, QualType Ty, const SourceRange r) : 277 Expr(CXXTypeidExprClass, Ty, 278 // typeid is never type-dependent (C++ [temp.dep.expr]p4) 279 false, 280 // typeid is value-dependent if the type or expression are dependent 281 (isTypeOp ? QualType::getFromOpaquePtr(op)->isDependentType() 282 : static_cast<Expr*>(op)->isValueDependent())), 283 isTypeOp(isTypeOp), Range(r) { 284 if (isTypeOp) 285 Operand.Ty = op; 286 else 287 // op was an Expr*, so cast it back to that to be safe 288 Operand.Ex = static_cast<Expr*>(op); 289 } 290 291 bool isTypeOperand() const { return isTypeOp; } 292 QualType getTypeOperand() const { 293 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 294 return QualType::getFromOpaquePtr(Operand.Ty); 295 } 296 Expr* getExprOperand() const { 297 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 298 return static_cast<Expr*>(Operand.Ex); 299 } 300 301 virtual SourceRange getSourceRange() const { 302 return Range; 303 } 304 static bool classof(const Stmt *T) { 305 return T->getStmtClass() == CXXTypeidExprClass; 306 } 307 static bool classof(const CXXTypeidExpr *) { return true; } 308 309 // Iterators 310 virtual child_iterator child_begin(); 311 virtual child_iterator child_end(); 312}; 313 314/// CXXThisExpr - Represents the "this" expression in C++, which is a 315/// pointer to the object on which the current member function is 316/// executing (C++ [expr.prim]p3). Example: 317/// 318/// @code 319/// class Foo { 320/// public: 321/// void bar(); 322/// void test() { this->bar(); } 323/// }; 324/// @endcode 325class CXXThisExpr : public Expr { 326 SourceLocation Loc; 327 328public: 329 CXXThisExpr(SourceLocation L, QualType Type) 330 : Expr(CXXThisExprClass, Type, 331 // 'this' is type-dependent if the class type of the enclosing 332 // member function is dependent (C++ [temp.dep.expr]p2) 333 Type->isDependentType(), Type->isDependentType()), 334 Loc(L) { } 335 336 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 337 338 static bool classof(const Stmt *T) { 339 return T->getStmtClass() == CXXThisExprClass; 340 } 341 static bool classof(const CXXThisExpr *) { return true; } 342 343 // Iterators 344 virtual child_iterator child_begin(); 345 virtual child_iterator child_end(); 346}; 347 348/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 349/// 'throw' and 'throw' assignment-expression. When 350/// assignment-expression isn't present, Op will be null. 351/// 352class CXXThrowExpr : public Expr { 353 Stmt *Op; 354 SourceLocation ThrowLoc; 355public: 356 // Ty is the void type which is used as the result type of the 357 // exepression. The l is the location of the throw keyword. expr 358 // can by null, if the optional expression to throw isn't present. 359 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) : 360 Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {} 361 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 362 Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 363 void setSubExpr(Expr *E) { Op = E; } 364 365 SourceLocation getThrowLoc() const { return ThrowLoc; } 366 void setThrowLoc(SourceLocation L) { ThrowLoc = L; } 367 368 virtual SourceRange getSourceRange() const { 369 if (getSubExpr() == 0) 370 return SourceRange(ThrowLoc, ThrowLoc); 371 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 372 } 373 374 static bool classof(const Stmt *T) { 375 return T->getStmtClass() == CXXThrowExprClass; 376 } 377 static bool classof(const CXXThrowExpr *) { return true; } 378 379 // Iterators 380 virtual child_iterator child_begin(); 381 virtual child_iterator child_end(); 382}; 383 384/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 385/// function call argument that was created from the corresponding 386/// parameter's default argument, when the call did not explicitly 387/// supply arguments for all of the parameters. 388class CXXDefaultArgExpr : public Expr { 389 ParmVarDecl *Param; 390 391protected: 392 CXXDefaultArgExpr(StmtClass SC, ParmVarDecl *param) 393 : Expr(SC, param->hasUnparsedDefaultArg() ? 394 param->getType().getNonReferenceType() 395 : param->getDefaultArg()->getType()), 396 Param(param) { } 397 398public: 399 // Param is the parameter whose default argument is used by this 400 // expression. 401 static CXXDefaultArgExpr *Create(ASTContext &C, ParmVarDecl *Param) { 402 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Param); 403 } 404 405 // Retrieve the parameter that the argument was created from. 406 const ParmVarDecl *getParam() const { return Param; } 407 ParmVarDecl *getParam() { return Param; } 408 409 // Retrieve the actual argument to the function call. 410 const Expr *getExpr() const { return Param->getDefaultArg(); } 411 Expr *getExpr() { return Param->getDefaultArg(); } 412 413 virtual SourceRange getSourceRange() const { 414 // Default argument expressions have no representation in the 415 // source, so they have an empty source range. 416 return SourceRange(); 417 } 418 419 static bool classof(const Stmt *T) { 420 return T->getStmtClass() == CXXDefaultArgExprClass; 421 } 422 static bool classof(const CXXDefaultArgExpr *) { return true; } 423 424 // Iterators 425 virtual child_iterator child_begin(); 426 virtual child_iterator child_end(); 427}; 428 429/// CXXTemporary - Represents a C++ temporary. 430class CXXTemporary { 431 /// Destructor - The destructor that needs to be called. 432 const CXXDestructorDecl *Destructor; 433 434 CXXTemporary(const CXXDestructorDecl *destructor) 435 : Destructor(destructor) { } 436 ~CXXTemporary() { } 437 438public: 439 static CXXTemporary *Create(ASTContext &C, 440 const CXXDestructorDecl *Destructor); 441 442 void Destroy(ASTContext &Ctx); 443 444 const CXXDestructorDecl *getDestructor() const { return Destructor; } 445}; 446 447/// CXXBindTemporaryExpr - Represents binding an expression to a temporary, 448/// so its destructor can be called later. 449class CXXBindTemporaryExpr : public Expr { 450 CXXTemporary *Temp; 451 452 Stmt *SubExpr; 453 454 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr) 455 : Expr(CXXBindTemporaryExprClass, 456 subexpr->getType()), Temp(temp), SubExpr(subexpr) { } 457 ~CXXBindTemporaryExpr() { } 458 459protected: 460 virtual void DoDestroy(ASTContext &C); 461 462public: 463 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 464 Expr* SubExpr); 465 466 CXXTemporary *getTemporary() { return Temp; } 467 const CXXTemporary *getTemporary() const { return Temp; } 468 469 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 470 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 471 void setSubExpr(Expr *E) { SubExpr = E; } 472 473 virtual SourceRange getSourceRange() const { 474 return SubExpr->getSourceRange(); 475 } 476 477 // Implement isa/cast/dyncast/etc. 478 static bool classof(const Stmt *T) { 479 return T->getStmtClass() == CXXBindTemporaryExprClass; 480 } 481 static bool classof(const CXXBindTemporaryExpr *) { return true; } 482 483 // Iterators 484 virtual child_iterator child_begin(); 485 virtual child_iterator child_end(); 486}; 487 488/// CXXConstructExpr - Represents a call to a C++ constructor. 489class CXXConstructExpr : public Expr { 490 CXXConstructorDecl *Constructor; 491 492 bool Elidable; 493 494 Stmt **Args; 495 unsigned NumArgs; 496 497protected: 498 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 499 CXXConstructorDecl *d, bool elidable, 500 Expr **args, unsigned numargs); 501 ~CXXConstructExpr() { } 502 503 virtual void DoDestroy(ASTContext &C); 504 505public: 506 /// \brief Construct an empty C++ construction expression that will store 507 /// \p numargs arguments. 508 CXXConstructExpr(EmptyShell Empty, ASTContext &C, unsigned numargs); 509 510 static CXXConstructExpr *Create(ASTContext &C, QualType T, 511 CXXConstructorDecl *D, bool Elidable, 512 Expr **Args, unsigned NumArgs); 513 514 515 CXXConstructorDecl* getConstructor() const { return Constructor; } 516 void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 517 518 /// \brief Whether this construction is elidable. 519 bool isElidable() const { return Elidable; } 520 void setElidable(bool E) { Elidable = E; } 521 522 typedef ExprIterator arg_iterator; 523 typedef ConstExprIterator const_arg_iterator; 524 525 arg_iterator arg_begin() { return Args; } 526 arg_iterator arg_end() { return Args + NumArgs; } 527 const_arg_iterator arg_begin() const { return Args; } 528 const_arg_iterator arg_end() const { return Args + NumArgs; } 529 530 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 531 unsigned getNumArgs() const { return NumArgs; } 532 533 /// getArg - Return the specified argument. 534 Expr *getArg(unsigned Arg) { 535 assert(Arg < NumArgs && "Arg access out of range!"); 536 return cast<Expr>(Args[Arg]); 537 } 538 const Expr *getArg(unsigned Arg) const { 539 assert(Arg < NumArgs && "Arg access out of range!"); 540 return cast<Expr>(Args[Arg]); 541 } 542 543 /// setArg - Set the specified argument. 544 void setArg(unsigned Arg, Expr *ArgExpr) { 545 assert(Arg < NumArgs && "Arg access out of range!"); 546 Args[Arg] = ArgExpr; 547 } 548 549 virtual SourceRange getSourceRange() const { 550 // FIXME: Should we know where the parentheses are, if there are any? 551 if (NumArgs == 0) 552 return SourceRange(); 553 554 return SourceRange(Args[0]->getLocStart(), Args[NumArgs - 1]->getLocEnd()); 555 } 556 557 static bool classof(const Stmt *T) { 558 return T->getStmtClass() == CXXConstructExprClass || 559 T->getStmtClass() == CXXTemporaryObjectExprClass; 560 } 561 static bool classof(const CXXConstructExpr *) { return true; } 562 563 // Iterators 564 virtual child_iterator child_begin(); 565 virtual child_iterator child_end(); 566}; 567 568/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 569/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 570/// x = int(0.5); 571class CXXFunctionalCastExpr : public ExplicitCastExpr { 572 SourceLocation TyBeginLoc; 573 SourceLocation RParenLoc; 574public: 575 CXXFunctionalCastExpr(QualType ty, QualType writtenTy, 576 SourceLocation tyBeginLoc, CastKind kind, 577 Expr *castExpr, SourceLocation rParenLoc) 578 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr, 579 writtenTy), 580 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 581 582 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 583 SourceLocation getRParenLoc() const { return RParenLoc; } 584 585 virtual SourceRange getSourceRange() const { 586 return SourceRange(TyBeginLoc, RParenLoc); 587 } 588 static bool classof(const Stmt *T) { 589 return T->getStmtClass() == CXXFunctionalCastExprClass; 590 } 591 static bool classof(const CXXFunctionalCastExpr *) { return true; } 592}; 593 594/// @brief Represents a C++ functional cast expression that builds a 595/// temporary object. 596/// 597/// This expression type represents a C++ "functional" cast 598/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 599/// constructor to build a temporary object. If N == 0 but no 600/// constructor will be called (because the functional cast is 601/// performing a value-initialized an object whose class type has no 602/// user-declared constructors), CXXZeroInitValueExpr will represent 603/// the functional cast. Finally, with N == 1 arguments the functional 604/// cast expression will be represented by CXXFunctionalCastExpr. 605/// Example: 606/// @code 607/// struct X { X(int, float); } 608/// 609/// X create_X() { 610/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 611/// }; 612/// @endcode 613class CXXTemporaryObjectExpr : public CXXConstructExpr { 614 SourceLocation TyBeginLoc; 615 SourceLocation RParenLoc; 616 617public: 618 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 619 QualType writtenTy, SourceLocation tyBeginLoc, 620 Expr **Args,unsigned NumArgs, 621 SourceLocation rParenLoc); 622 623 ~CXXTemporaryObjectExpr() { } 624 625 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 626 SourceLocation getRParenLoc() const { return RParenLoc; } 627 628 virtual SourceRange getSourceRange() const { 629 return SourceRange(TyBeginLoc, RParenLoc); 630 } 631 static bool classof(const Stmt *T) { 632 return T->getStmtClass() == CXXTemporaryObjectExprClass; 633 } 634 static bool classof(const CXXTemporaryObjectExpr *) { return true; } 635}; 636 637/// CXXZeroInitValueExpr - [C++ 5.2.3p2] 638/// Expression "T()" which creates a value-initialized rvalue of type 639/// T, which is either a non-class type or a class type without any 640/// user-defined constructors. 641/// 642class CXXZeroInitValueExpr : public Expr { 643 SourceLocation TyBeginLoc; 644 SourceLocation RParenLoc; 645 646public: 647 CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc, 648 SourceLocation rParenLoc ) : 649 Expr(CXXZeroInitValueExprClass, ty, false, false), 650 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 651 652 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 653 SourceLocation getRParenLoc() const { return RParenLoc; } 654 655 /// @brief Whether this initialization expression was 656 /// implicitly-generated. 657 bool isImplicit() const { 658 return TyBeginLoc.isInvalid() && RParenLoc.isInvalid(); 659 } 660 661 virtual SourceRange getSourceRange() const { 662 return SourceRange(TyBeginLoc, RParenLoc); 663 } 664 665 static bool classof(const Stmt *T) { 666 return T->getStmtClass() == CXXZeroInitValueExprClass; 667 } 668 static bool classof(const CXXZeroInitValueExpr *) { return true; } 669 670 // Iterators 671 virtual child_iterator child_begin(); 672 virtual child_iterator child_end(); 673}; 674 675/// CXXNewExpr - A new expression for memory allocation and constructor calls, 676/// e.g: "new CXXNewExpr(foo)". 677class CXXNewExpr : public Expr { 678 // Was the usage ::new, i.e. is the global new to be used? 679 bool GlobalNew : 1; 680 // Was the form (type-id) used? Otherwise, it was new-type-id. 681 bool ParenTypeId : 1; 682 // Is there an initializer? If not, built-ins are uninitialized, else they're 683 // value-initialized. 684 bool Initializer : 1; 685 // Do we allocate an array? If so, the first SubExpr is the size expression. 686 bool Array : 1; 687 // The number of placement new arguments. 688 unsigned NumPlacementArgs : 14; 689 // The number of constructor arguments. This may be 1 even for non-class 690 // types; use the pseudo copy constructor. 691 unsigned NumConstructorArgs : 14; 692 // Contains an optional array size expression, any number of optional 693 // placement arguments, and any number of optional constructor arguments, 694 // in that order. 695 Stmt **SubExprs; 696 // Points to the allocation function used. 697 FunctionDecl *OperatorNew; 698 // Points to the deallocation function used in case of error. May be null. 699 FunctionDecl *OperatorDelete; 700 // Points to the constructor used. Cannot be null if AllocType is a record; 701 // it would still point at the default constructor (even an implicit one). 702 // Must be null for all other types. 703 CXXConstructorDecl *Constructor; 704 705 SourceLocation StartLoc; 706 SourceLocation EndLoc; 707 708public: 709 CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, Expr **placementArgs, 710 unsigned numPlaceArgs, bool ParenTypeId, Expr *arraySize, 711 CXXConstructorDecl *constructor, bool initializer, 712 Expr **constructorArgs, unsigned numConsArgs, 713 FunctionDecl *operatorDelete, QualType ty, 714 SourceLocation startLoc, SourceLocation endLoc); 715 ~CXXNewExpr() { 716 delete[] SubExprs; 717 } 718 719 QualType getAllocatedType() const { 720 assert(getType()->isPointerType()); 721 return getType()->getAs<PointerType>()->getPointeeType(); 722 } 723 724 FunctionDecl *getOperatorNew() const { return OperatorNew; } 725 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 726 CXXConstructorDecl *getConstructor() const { return Constructor; } 727 728 bool isArray() const { return Array; } 729 Expr *getArraySize() { 730 return Array ? cast<Expr>(SubExprs[0]) : 0; 731 } 732 const Expr *getArraySize() const { 733 return Array ? cast<Expr>(SubExprs[0]) : 0; 734 } 735 736 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 737 Expr *getPlacementArg(unsigned i) { 738 assert(i < NumPlacementArgs && "Index out of range"); 739 return cast<Expr>(SubExprs[Array + i]); 740 } 741 const Expr *getPlacementArg(unsigned i) const { 742 assert(i < NumPlacementArgs && "Index out of range"); 743 return cast<Expr>(SubExprs[Array + i]); 744 } 745 746 bool isGlobalNew() const { return GlobalNew; } 747 bool isParenTypeId() const { return ParenTypeId; } 748 bool hasInitializer() const { return Initializer; } 749 750 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 751 Expr *getConstructorArg(unsigned i) { 752 assert(i < NumConstructorArgs && "Index out of range"); 753 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 754 } 755 const Expr *getConstructorArg(unsigned i) const { 756 assert(i < NumConstructorArgs && "Index out of range"); 757 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 758 } 759 760 typedef ExprIterator arg_iterator; 761 typedef ConstExprIterator const_arg_iterator; 762 763 arg_iterator placement_arg_begin() { 764 return SubExprs + Array; 765 } 766 arg_iterator placement_arg_end() { 767 return SubExprs + Array + getNumPlacementArgs(); 768 } 769 const_arg_iterator placement_arg_begin() const { 770 return SubExprs + Array; 771 } 772 const_arg_iterator placement_arg_end() const { 773 return SubExprs + Array + getNumPlacementArgs(); 774 } 775 776 arg_iterator constructor_arg_begin() { 777 return SubExprs + Array + getNumPlacementArgs(); 778 } 779 arg_iterator constructor_arg_end() { 780 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 781 } 782 const_arg_iterator constructor_arg_begin() const { 783 return SubExprs + Array + getNumPlacementArgs(); 784 } 785 const_arg_iterator constructor_arg_end() const { 786 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 787 } 788 789 virtual SourceRange getSourceRange() const { 790 return SourceRange(StartLoc, EndLoc); 791 } 792 793 static bool classof(const Stmt *T) { 794 return T->getStmtClass() == CXXNewExprClass; 795 } 796 static bool classof(const CXXNewExpr *) { return true; } 797 798 // Iterators 799 virtual child_iterator child_begin(); 800 virtual child_iterator child_end(); 801}; 802 803/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 804/// calls, e.g. "delete[] pArray". 805class CXXDeleteExpr : public Expr { 806 // Is this a forced global delete, i.e. "::delete"? 807 bool GlobalDelete : 1; 808 // Is this the array form of delete, i.e. "delete[]"? 809 bool ArrayForm : 1; 810 // Points to the operator delete overload that is used. Could be a member. 811 FunctionDecl *OperatorDelete; 812 // The pointer expression to be deleted. 813 Stmt *Argument; 814 // Location of the expression. 815 SourceLocation Loc; 816public: 817 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 818 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 819 : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete), 820 ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg), 821 Loc(loc) { } 822 823 bool isGlobalDelete() const { return GlobalDelete; } 824 bool isArrayForm() const { return ArrayForm; } 825 826 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 827 828 Expr *getArgument() { return cast<Expr>(Argument); } 829 const Expr *getArgument() const { return cast<Expr>(Argument); } 830 831 virtual SourceRange getSourceRange() const { 832 return SourceRange(Loc, Argument->getLocEnd()); 833 } 834 835 static bool classof(const Stmt *T) { 836 return T->getStmtClass() == CXXDeleteExprClass; 837 } 838 static bool classof(const CXXDeleteExpr *) { return true; } 839 840 // Iterators 841 virtual child_iterator child_begin(); 842 virtual child_iterator child_end(); 843}; 844 845/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 846/// 847/// Example: 848/// 849/// \code 850/// template<typename T> 851/// void destroy(T* ptr) { 852/// ptr->~T(); 853/// } 854/// \endcode 855/// 856/// When the template is parsed, the expression \c ptr->~T will be stored as 857/// a member reference expression. If it then instantiated with a scalar type 858/// as a template argument for T, the resulting expression will be a 859/// pseudo-destructor expression. 860class CXXPseudoDestructorExpr : public Expr { 861 /// \brief The base expression (that is being destroyed). 862 Stmt *Base; 863 864 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 865 /// period ('.'). 866 bool IsArrow : 1; 867 868 /// \brief The location of the '.' or '->' operator. 869 SourceLocation OperatorLoc; 870 871 /// \brief The nested-name-specifier that follows the operator, if present. 872 NestedNameSpecifier *Qualifier; 873 874 /// \brief The source range that covers the nested-name-specifier, if 875 /// present. 876 SourceRange QualifierRange; 877 878 /// \brief The type being destroyed. 879 QualType DestroyedType; 880 881 /// \brief The location of the type after the '~'. 882 SourceLocation DestroyedTypeLoc; 883 884public: 885 CXXPseudoDestructorExpr(ASTContext &Context, 886 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 887 NestedNameSpecifier *Qualifier, 888 SourceRange QualifierRange, 889 QualType DestroyedType, 890 SourceLocation DestroyedTypeLoc) 891 : Expr(CXXPseudoDestructorExprClass, 892 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, 893 false, 0)), 894 /*isTypeDependent=*/false, 895 /*isValueDependent=*/Base->isValueDependent()), 896 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), 897 OperatorLoc(OperatorLoc), Qualifier(Qualifier), 898 QualifierRange(QualifierRange), DestroyedType(DestroyedType), 899 DestroyedTypeLoc(DestroyedTypeLoc) { } 900 901 void setBase(Expr *E) { Base = E; } 902 Expr *getBase() const { return cast<Expr>(Base); } 903 904 /// \brief Determines whether this member expression actually had 905 /// a C++ nested-name-specifier prior to the name of the member, e.g., 906 /// x->Base::foo. 907 bool hasQualifier() const { return Qualifier != 0; } 908 909 /// \brief If the member name was qualified, retrieves the source range of 910 /// the nested-name-specifier that precedes the member name. Otherwise, 911 /// returns an empty source range. 912 SourceRange getQualifierRange() const { return QualifierRange; } 913 914 /// \brief If the member name was qualified, retrieves the 915 /// nested-name-specifier that precedes the member name. Otherwise, returns 916 /// NULL. 917 NestedNameSpecifier *getQualifier() const { return Qualifier; } 918 919 /// \brief Determine whether this pseudo-destructor expression was written 920 /// using an '->' (otherwise, it used a '.'). 921 bool isArrow() const { return IsArrow; } 922 void setArrow(bool A) { IsArrow = A; } 923 924 /// \brief Retrieve the location of the '.' or '->' operator. 925 SourceLocation getOperatorLoc() const { return OperatorLoc; } 926 927 /// \brief Retrieve the type that is being destroyed. 928 QualType getDestroyedType() const { return DestroyedType; } 929 930 /// \brief Retrieve the location of the type being destroyed. 931 SourceLocation getDestroyedTypeLoc() const { return DestroyedTypeLoc; } 932 933 virtual SourceRange getSourceRange() const { 934 return SourceRange(Base->getLocStart(), DestroyedTypeLoc); 935 } 936 937 static bool classof(const Stmt *T) { 938 return T->getStmtClass() == CXXPseudoDestructorExprClass; 939 } 940 static bool classof(const CXXPseudoDestructorExpr *) { return true; } 941 942 // Iterators 943 virtual child_iterator child_begin(); 944 virtual child_iterator child_end(); 945}; 946 947/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 948/// implementation of TR1/C++0x type trait templates. 949/// Example: 950/// __is_pod(int) == true 951/// __is_enum(std::string) == false 952class UnaryTypeTraitExpr : public Expr { 953 /// UTT - The trait. 954 UnaryTypeTrait UTT; 955 956 /// Loc - The location of the type trait keyword. 957 SourceLocation Loc; 958 959 /// RParen - The location of the closing paren. 960 SourceLocation RParen; 961 962 /// QueriedType - The type we're testing. 963 QualType QueriedType; 964 965public: 966 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried, 967 SourceLocation rparen, QualType ty) 968 : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()), 969 UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { } 970 971 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 972 973 UnaryTypeTrait getTrait() const { return UTT; } 974 975 QualType getQueriedType() const { return QueriedType; } 976 977 bool EvaluateTrait(ASTContext&) const; 978 979 static bool classof(const Stmt *T) { 980 return T->getStmtClass() == UnaryTypeTraitExprClass; 981 } 982 static bool classof(const UnaryTypeTraitExpr *) { return true; } 983 984 // Iterators 985 virtual child_iterator child_begin(); 986 virtual child_iterator child_end(); 987}; 988 989/// \brief A reference to a name which we were able to look up during 990/// parsing but could not resolve to a specific declaration. This 991/// arises in several ways: 992/// * we might be waiting for argument-dependent lookup 993/// * the name might resolve to an overloaded function 994/// and eventually: 995/// * the lookup might have included a function template 996/// These never include UnresolvedUsingValueDecls, which are always 997/// class members and therefore appear only in 998/// UnresolvedMemberLookupExprs. 999class UnresolvedLookupExpr : public Expr { 1000 /// The results. These are undesugared, which is to say, they may 1001 /// include UsingShadowDecls. 1002 UnresolvedSet Results; 1003 1004 /// The name declared. 1005 DeclarationName Name; 1006 1007 /// The qualifier given, if any. 1008 NestedNameSpecifier *Qualifier; 1009 1010 /// The source range of the nested name specifier. 1011 SourceRange QualifierRange; 1012 1013 /// The location of the name. 1014 SourceLocation NameLoc; 1015 1016 /// True if these lookup results should be extended by 1017 /// argument-dependent lookup if this is the operand of a function 1018 /// call. 1019 bool RequiresADL; 1020 1021 /// True if these lookup results are overloaded. This is pretty 1022 /// trivially rederivable if we urgently need to kill this field. 1023 bool Overloaded; 1024 1025 /// True if the name looked up had explicit template arguments. 1026 /// This requires all the results to be function templates. 1027 bool HasExplicitTemplateArgs; 1028 1029 UnresolvedLookupExpr(QualType T, bool Dependent, 1030 NestedNameSpecifier *Qualifier, SourceRange QRange, 1031 DeclarationName Name, SourceLocation NameLoc, 1032 bool RequiresADL, bool Overloaded, bool HasTemplateArgs) 1033 : Expr(UnresolvedLookupExprClass, T, Dependent, Dependent), 1034 Name(Name), Qualifier(Qualifier), QualifierRange(QRange), 1035 NameLoc(NameLoc), RequiresADL(RequiresADL), Overloaded(Overloaded), 1036 HasExplicitTemplateArgs(HasTemplateArgs) 1037 {} 1038 1039public: 1040 static UnresolvedLookupExpr *Create(ASTContext &C, 1041 bool Dependent, 1042 NestedNameSpecifier *Qualifier, 1043 SourceRange QualifierRange, 1044 DeclarationName Name, 1045 SourceLocation NameLoc, 1046 bool ADL, bool Overloaded) { 1047 return new(C) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy, 1048 Dependent, Qualifier, QualifierRange, 1049 Name, NameLoc, ADL, Overloaded, false); 1050 } 1051 1052 static UnresolvedLookupExpr *Create(ASTContext &C, 1053 bool Dependent, 1054 NestedNameSpecifier *Qualifier, 1055 SourceRange QualifierRange, 1056 DeclarationName Name, 1057 SourceLocation NameLoc, 1058 bool ADL, 1059 const TemplateArgumentListInfo &Args); 1060 1061 /// Computes whether an unresolved lookup on the given declarations 1062 /// and optional template arguments is type- and value-dependent. 1063 static bool ComputeDependence(NamedDecl * const *Begin, 1064 NamedDecl * const *End, 1065 const TemplateArgumentListInfo *Args); 1066 1067 void addDecl(NamedDecl *Decl) { 1068 Results.addDecl(Decl); 1069 } 1070 1071 typedef UnresolvedSet::iterator decls_iterator; 1072 decls_iterator decls_begin() const { return Results.begin(); } 1073 decls_iterator decls_end() const { return Results.end(); } 1074 1075 /// True if this declaration should be extended by 1076 /// argument-dependent lookup. 1077 bool requiresADL() const { return RequiresADL; } 1078 1079 /// True if this lookup is overloaded. 1080 bool isOverloaded() const { return Overloaded; } 1081 1082 /// Fetches the name looked up. 1083 DeclarationName getName() const { return Name; } 1084 1085 /// Gets the location of the name. 1086 SourceLocation getNameLoc() const { return NameLoc; } 1087 1088 /// Fetches the nested-name qualifier, if one was given. 1089 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1090 1091 /// Fetches the range of the nested-name qualifier. 1092 SourceRange getQualifierRange() const { return QualifierRange; } 1093 1094 /// Determines whether this lookup had explicit template arguments. 1095 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1096 1097 // Note that, inconsistently with the explicit-template-argument AST 1098 // nodes, users are *forbidden* from calling these methods on objects 1099 // without explicit template arguments. 1100 1101 /// Gets a reference to the explicit template argument list. 1102 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1103 assert(hasExplicitTemplateArgs()); 1104 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1105 } 1106 1107 /// \brief Copies the template arguments (if present) into the given 1108 /// structure. 1109 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1110 getExplicitTemplateArgs().copyInto(List); 1111 } 1112 1113 SourceLocation getLAngleLoc() const { 1114 return getExplicitTemplateArgs().LAngleLoc; 1115 } 1116 1117 SourceLocation getRAngleLoc() const { 1118 return getExplicitTemplateArgs().RAngleLoc; 1119 } 1120 1121 TemplateArgumentLoc const *getTemplateArgs() const { 1122 return getExplicitTemplateArgs().getTemplateArgs(); 1123 } 1124 1125 unsigned getNumTemplateArgs() const { 1126 return getExplicitTemplateArgs().NumTemplateArgs; 1127 } 1128 1129 virtual SourceRange getSourceRange() const { 1130 SourceRange Range(NameLoc); 1131 if (Qualifier) Range.setBegin(QualifierRange.getBegin()); 1132 if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc()); 1133 return Range; 1134 } 1135 1136 virtual StmtIterator child_begin(); 1137 virtual StmtIterator child_end(); 1138 1139 static bool classof(const Stmt *T) { 1140 return T->getStmtClass() == UnresolvedLookupExprClass; 1141 } 1142 static bool classof(const UnresolvedLookupExpr *) { return true; } 1143}; 1144 1145/// \brief A qualified reference to a name whose declaration cannot 1146/// yet be resolved. 1147/// 1148/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 1149/// it expresses a reference to a declaration such as 1150/// X<T>::value. The difference, however, is that an 1151/// DependentScopeDeclRefExpr node is used only within C++ templates when 1152/// the qualification (e.g., X<T>::) refers to a dependent type. In 1153/// this case, X<T>::value cannot resolve to a declaration because the 1154/// declaration will differ from on instantiation of X<T> to the 1155/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 1156/// qualifier (X<T>::) and the name of the entity being referenced 1157/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 1158/// declaration can be found. 1159class DependentScopeDeclRefExpr : public Expr { 1160 /// The name of the entity we will be referencing. 1161 DeclarationName Name; 1162 1163 /// Location of the name of the declaration we're referencing. 1164 SourceLocation Loc; 1165 1166 /// QualifierRange - The source range that covers the 1167 /// nested-name-specifier. 1168 SourceRange QualifierRange; 1169 1170 /// \brief The nested-name-specifier that qualifies this unresolved 1171 /// declaration name. 1172 NestedNameSpecifier *Qualifier; 1173 1174 /// \brief Whether the name includes explicit template arguments. 1175 bool HasExplicitTemplateArgs; 1176 1177 DependentScopeDeclRefExpr(QualType T, 1178 NestedNameSpecifier *Qualifier, 1179 SourceRange QualifierRange, 1180 DeclarationName Name, 1181 SourceLocation NameLoc, 1182 bool HasExplicitTemplateArgs) 1183 : Expr(DependentScopeDeclRefExprClass, T, true, true), 1184 Name(Name), Loc(NameLoc), 1185 QualifierRange(QualifierRange), Qualifier(Qualifier), 1186 HasExplicitTemplateArgs(HasExplicitTemplateArgs) 1187 {} 1188 1189public: 1190 static DependentScopeDeclRefExpr *Create(ASTContext &C, 1191 NestedNameSpecifier *Qualifier, 1192 SourceRange QualifierRange, 1193 DeclarationName Name, 1194 SourceLocation NameLoc, 1195 const TemplateArgumentListInfo *TemplateArgs = 0); 1196 1197 /// \brief Retrieve the name that this expression refers to. 1198 DeclarationName getDeclName() const { return Name; } 1199 1200 /// \brief Retrieve the location of the name within the expression. 1201 SourceLocation getLocation() const { return Loc; } 1202 1203 /// \brief Retrieve the source range of the nested-name-specifier. 1204 SourceRange getQualifierRange() const { return QualifierRange; } 1205 1206 /// \brief Retrieve the nested-name-specifier that qualifies this 1207 /// declaration. 1208 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1209 1210 /// Determines whether this lookup had explicit template arguments. 1211 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1212 1213 // Note that, inconsistently with the explicit-template-argument AST 1214 // nodes, users are *forbidden* from calling these methods on objects 1215 // without explicit template arguments. 1216 1217 /// Gets a reference to the explicit template argument list. 1218 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1219 assert(hasExplicitTemplateArgs()); 1220 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1221 } 1222 1223 /// \brief Copies the template arguments (if present) into the given 1224 /// structure. 1225 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1226 getExplicitTemplateArgs().copyInto(List); 1227 } 1228 1229 SourceLocation getLAngleLoc() const { 1230 return getExplicitTemplateArgs().LAngleLoc; 1231 } 1232 1233 SourceLocation getRAngleLoc() const { 1234 return getExplicitTemplateArgs().RAngleLoc; 1235 } 1236 1237 TemplateArgumentLoc const *getTemplateArgs() const { 1238 return getExplicitTemplateArgs().getTemplateArgs(); 1239 } 1240 1241 unsigned getNumTemplateArgs() const { 1242 return getExplicitTemplateArgs().NumTemplateArgs; 1243 } 1244 1245 virtual SourceRange getSourceRange() const { 1246 SourceRange Range(QualifierRange.getBegin(), getLocation()); 1247 if (hasExplicitTemplateArgs()) 1248 Range.setEnd(getRAngleLoc()); 1249 return Range; 1250 } 1251 1252 static bool classof(const Stmt *T) { 1253 return T->getStmtClass() == DependentScopeDeclRefExprClass; 1254 } 1255 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 1256 1257 virtual StmtIterator child_begin(); 1258 virtual StmtIterator child_end(); 1259}; 1260 1261class CXXExprWithTemporaries : public Expr { 1262 Stmt *SubExpr; 1263 1264 CXXTemporary **Temps; 1265 unsigned NumTemps; 1266 1267 CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps, 1268 unsigned NumTemps); 1269 ~CXXExprWithTemporaries(); 1270 1271protected: 1272 virtual void DoDestroy(ASTContext &C); 1273 1274public: 1275 static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr, 1276 CXXTemporary **Temps, 1277 unsigned NumTemps); 1278 1279 unsigned getNumTemporaries() const { return NumTemps; } 1280 CXXTemporary *getTemporary(unsigned i) { 1281 assert(i < NumTemps && "Index out of range"); 1282 return Temps[i]; 1283 } 1284 const CXXTemporary *getTemporary(unsigned i) const { 1285 return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i); 1286 } 1287 1288 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1289 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1290 void setSubExpr(Expr *E) { SubExpr = E; } 1291 1292 virtual SourceRange getSourceRange() const { 1293 return SubExpr->getSourceRange(); 1294 } 1295 1296 // Implement isa/cast/dyncast/etc. 1297 static bool classof(const Stmt *T) { 1298 return T->getStmtClass() == CXXExprWithTemporariesClass; 1299 } 1300 static bool classof(const CXXExprWithTemporaries *) { return true; } 1301 1302 // Iterators 1303 virtual child_iterator child_begin(); 1304 virtual child_iterator child_end(); 1305}; 1306 1307/// \brief Describes an explicit type conversion that uses functional 1308/// notion but could not be resolved because one or more arguments are 1309/// type-dependent. 1310/// 1311/// The explicit type conversions expressed by 1312/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 1313/// where \c T is some type and \c a1, a2, ..., aN are values, and 1314/// either \C T is a dependent type or one or more of the \c a's is 1315/// type-dependent. For example, this would occur in a template such 1316/// as: 1317/// 1318/// \code 1319/// template<typename T, typename A1> 1320/// inline T make_a(const A1& a1) { 1321/// return T(a1); 1322/// } 1323/// \endcode 1324/// 1325/// When the returned expression is instantiated, it may resolve to a 1326/// constructor call, conversion function call, or some kind of type 1327/// conversion. 1328class CXXUnresolvedConstructExpr : public Expr { 1329 /// \brief The starting location of the type 1330 SourceLocation TyBeginLoc; 1331 1332 /// \brief The type being constructed. 1333 QualType Type; 1334 1335 /// \brief The location of the left parentheses ('('). 1336 SourceLocation LParenLoc; 1337 1338 /// \brief The location of the right parentheses (')'). 1339 SourceLocation RParenLoc; 1340 1341 /// \brief The number of arguments used to construct the type. 1342 unsigned NumArgs; 1343 1344 CXXUnresolvedConstructExpr(SourceLocation TyBegin, 1345 QualType T, 1346 SourceLocation LParenLoc, 1347 Expr **Args, 1348 unsigned NumArgs, 1349 SourceLocation RParenLoc); 1350 1351public: 1352 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 1353 SourceLocation TyBegin, 1354 QualType T, 1355 SourceLocation LParenLoc, 1356 Expr **Args, 1357 unsigned NumArgs, 1358 SourceLocation RParenLoc); 1359 1360 /// \brief Retrieve the source location where the type begins. 1361 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 1362 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 1363 1364 /// \brief Retrieve the type that is being constructed, as specified 1365 /// in the source code. 1366 QualType getTypeAsWritten() const { return Type; } 1367 void setTypeAsWritten(QualType T) { Type = T; } 1368 1369 /// \brief Retrieve the location of the left parentheses ('(') that 1370 /// precedes the argument list. 1371 SourceLocation getLParenLoc() const { return LParenLoc; } 1372 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1373 1374 /// \brief Retrieve the location of the right parentheses (')') that 1375 /// follows the argument list. 1376 SourceLocation getRParenLoc() const { return RParenLoc; } 1377 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1378 1379 /// \brief Retrieve the number of arguments. 1380 unsigned arg_size() const { return NumArgs; } 1381 1382 typedef Expr** arg_iterator; 1383 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 1384 arg_iterator arg_end() { return arg_begin() + NumArgs; } 1385 1386 Expr *getArg(unsigned I) { 1387 assert(I < NumArgs && "Argument index out-of-range"); 1388 return *(arg_begin() + I); 1389 } 1390 1391 virtual SourceRange getSourceRange() const { 1392 return SourceRange(TyBeginLoc, RParenLoc); 1393 } 1394 static bool classof(const Stmt *T) { 1395 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 1396 } 1397 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 1398 1399 // Iterators 1400 virtual child_iterator child_begin(); 1401 virtual child_iterator child_end(); 1402}; 1403 1404/// \brief Represents a C++ member access expression where the actual 1405/// member referenced could not be resolved because the base 1406/// expression or the member name was dependent. 1407/// 1408/// Like UnresolvedMemberExprs, these can be either implicit or 1409/// explicit accesses. It is only possible to get one of these with 1410/// an implicit access if a qualifier is provided. 1411class CXXDependentScopeMemberExpr : public Expr { 1412 /// \brief The expression for the base pointer or class reference, 1413 /// e.g., the \c x in x.f. Can be null in implicit accesses. 1414 Stmt *Base; 1415 1416 /// \brief The type of the base expression. Never null, even for 1417 /// implicit accesses. 1418 QualType BaseType; 1419 1420 /// \brief Whether this member expression used the '->' operator or 1421 /// the '.' operator. 1422 bool IsArrow : 1; 1423 1424 /// \brief Whether this member expression has explicitly-specified template 1425 /// arguments. 1426 bool HasExplicitTemplateArgs : 1; 1427 1428 /// \brief The location of the '->' or '.' operator. 1429 SourceLocation OperatorLoc; 1430 1431 /// \brief The nested-name-specifier that precedes the member name, if any. 1432 NestedNameSpecifier *Qualifier; 1433 1434 /// \brief The source range covering the nested name specifier. 1435 SourceRange QualifierRange; 1436 1437 /// \brief In a qualified member access expression such as t->Base::f, this 1438 /// member stores the resolves of name lookup in the context of the member 1439 /// access expression, to be used at instantiation time. 1440 /// 1441 /// FIXME: This member, along with the Qualifier and QualifierRange, could 1442 /// be stuck into a structure that is optionally allocated at the end of 1443 /// the CXXDependentScopeMemberExpr, to save space in the common case. 1444 NamedDecl *FirstQualifierFoundInScope; 1445 1446 /// \brief The member to which this member expression refers, which 1447 /// can be name, overloaded operator, or destructor. 1448 /// FIXME: could also be a template-id 1449 DeclarationName Member; 1450 1451 /// \brief The location of the member name. 1452 SourceLocation MemberLoc; 1453 1454 /// \brief Retrieve the explicit template argument list that followed the 1455 /// member template name, if any. 1456 ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 1457 assert(HasExplicitTemplateArgs); 1458 return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1459 } 1460 1461 /// \brief Retrieve the explicit template argument list that followed the 1462 /// member template name, if any. 1463 const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 1464 return const_cast<CXXDependentScopeMemberExpr *>(this) 1465 ->getExplicitTemplateArgumentList(); 1466 } 1467 1468 CXXDependentScopeMemberExpr(ASTContext &C, 1469 Expr *Base, QualType BaseType, bool IsArrow, 1470 SourceLocation OperatorLoc, 1471 NestedNameSpecifier *Qualifier, 1472 SourceRange QualifierRange, 1473 NamedDecl *FirstQualifierFoundInScope, 1474 DeclarationName Member, 1475 SourceLocation MemberLoc, 1476 const TemplateArgumentListInfo *TemplateArgs); 1477 1478public: 1479 CXXDependentScopeMemberExpr(ASTContext &C, 1480 Expr *Base, QualType BaseType, 1481 bool IsArrow, 1482 SourceLocation OperatorLoc, 1483 NestedNameSpecifier *Qualifier, 1484 SourceRange QualifierRange, 1485 NamedDecl *FirstQualifierFoundInScope, 1486 DeclarationName Member, 1487 SourceLocation MemberLoc) 1488 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true), 1489 Base(Base), BaseType(BaseType), IsArrow(IsArrow), 1490 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc), 1491 Qualifier(Qualifier), QualifierRange(QualifierRange), 1492 FirstQualifierFoundInScope(FirstQualifierFoundInScope), 1493 Member(Member), MemberLoc(MemberLoc) { } 1494 1495 static CXXDependentScopeMemberExpr * 1496 Create(ASTContext &C, 1497 Expr *Base, QualType BaseType, bool IsArrow, 1498 SourceLocation OperatorLoc, 1499 NestedNameSpecifier *Qualifier, 1500 SourceRange QualifierRange, 1501 NamedDecl *FirstQualifierFoundInScope, 1502 DeclarationName Member, 1503 SourceLocation MemberLoc, 1504 const TemplateArgumentListInfo *TemplateArgs); 1505 1506 /// \brief True if this is an implicit access, i.e. one in which the 1507 /// member being accessed was not written in the source. The source 1508 /// location of the operator is invalid in this case. 1509 bool isImplicitAccess() const { return Base == 0; } 1510 1511 /// \brief Retrieve the base object of this member expressions, 1512 /// e.g., the \c x in \c x.m. 1513 Expr *getBase() const { 1514 assert(!isImplicitAccess()); 1515 return cast<Expr>(Base); 1516 } 1517 void setBase(Expr *E) { Base = E; } 1518 1519 QualType getBaseType() const { return BaseType; } 1520 1521 /// \brief Determine whether this member expression used the '->' 1522 /// operator; otherwise, it used the '.' operator. 1523 bool isArrow() const { return IsArrow; } 1524 void setArrow(bool A) { IsArrow = A; } 1525 1526 /// \brief Retrieve the location of the '->' or '.' operator. 1527 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1528 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1529 1530 /// \brief Retrieve the nested-name-specifier that qualifies the member 1531 /// name. 1532 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1533 1534 /// \brief Retrieve the source range covering the nested-name-specifier 1535 /// that qualifies the member name. 1536 SourceRange getQualifierRange() const { return QualifierRange; } 1537 1538 /// \brief Retrieve the first part of the nested-name-specifier that was 1539 /// found in the scope of the member access expression when the member access 1540 /// was initially parsed. 1541 /// 1542 /// This function only returns a useful result when member access expression 1543 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 1544 /// returned by this function describes what was found by unqualified name 1545 /// lookup for the identifier "Base" within the scope of the member access 1546 /// expression itself. At template instantiation time, this information is 1547 /// combined with the results of name lookup into the type of the object 1548 /// expression itself (the class type of x). 1549 NamedDecl *getFirstQualifierFoundInScope() const { 1550 return FirstQualifierFoundInScope; 1551 } 1552 1553 /// \brief Retrieve the name of the member that this expression 1554 /// refers to. 1555 DeclarationName getMember() const { return Member; } 1556 void setMember(DeclarationName N) { Member = N; } 1557 1558 // \brief Retrieve the location of the name of the member that this 1559 // expression refers to. 1560 SourceLocation getMemberLoc() const { return MemberLoc; } 1561 void setMemberLoc(SourceLocation L) { MemberLoc = L; } 1562 1563 /// \brief Determines whether this member expression actually had a C++ 1564 /// template argument list explicitly specified, e.g., x.f<int>. 1565 bool hasExplicitTemplateArgs() const { 1566 return HasExplicitTemplateArgs; 1567 } 1568 1569 /// \brief Copies the template arguments (if present) into the given 1570 /// structure. 1571 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1572 assert(HasExplicitTemplateArgs); 1573 getExplicitTemplateArgumentList()->copyInto(List); 1574 } 1575 1576 /// \brief Retrieve the location of the left angle bracket following the 1577 /// member name ('<'), if any. 1578 SourceLocation getLAngleLoc() const { 1579 assert(HasExplicitTemplateArgs); 1580 return getExplicitTemplateArgumentList()->LAngleLoc; 1581 } 1582 1583 /// \brief Retrieve the template arguments provided as part of this 1584 /// template-id. 1585 const TemplateArgumentLoc *getTemplateArgs() const { 1586 assert(HasExplicitTemplateArgs); 1587 return getExplicitTemplateArgumentList()->getTemplateArgs(); 1588 } 1589 1590 /// \brief Retrieve the number of template arguments provided as part of this 1591 /// template-id. 1592 unsigned getNumTemplateArgs() const { 1593 assert(HasExplicitTemplateArgs); 1594 return getExplicitTemplateArgumentList()->NumTemplateArgs; 1595 } 1596 1597 /// \brief Retrieve the location of the right angle bracket following the 1598 /// template arguments ('>'). 1599 SourceLocation getRAngleLoc() const { 1600 assert(HasExplicitTemplateArgs); 1601 return getExplicitTemplateArgumentList()->RAngleLoc; 1602 } 1603 1604 virtual SourceRange getSourceRange() const { 1605 SourceRange Range; 1606 if (!isImplicitAccess()) 1607 Range.setBegin(Base->getSourceRange().getBegin()); 1608 else if (getQualifier()) 1609 Range.setBegin(getQualifierRange().getBegin()); 1610 else 1611 Range.setBegin(MemberLoc); 1612 1613 if (hasExplicitTemplateArgs()) 1614 Range.setEnd(getRAngleLoc()); 1615 else 1616 Range.setEnd(MemberLoc); 1617 return Range; 1618 } 1619 1620 static bool classof(const Stmt *T) { 1621 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 1622 } 1623 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 1624 1625 // Iterators 1626 virtual child_iterator child_begin(); 1627 virtual child_iterator child_end(); 1628}; 1629 1630/// \brief Represents a C++ member access expression for which lookup 1631/// produced a set of overloaded functions. 1632/// 1633/// The member access may be explicit or implicit: 1634/// struct A { 1635/// int a, b; 1636/// int explicitAccess() { return this->a + this->A::b; } 1637/// int implicitAccess() { return a + A::b; } 1638/// }; 1639/// 1640/// In the final AST, an explicit access always becomes a MemberExpr. 1641/// An implicit access may become either a MemberExpr or a 1642/// DeclRefExpr, depending on whether the member is static. 1643class UnresolvedMemberExpr : public Expr { 1644 /// The results. These are undesugared, which is to say, they may 1645 /// include UsingShadowDecls. 1646 UnresolvedSet Results; 1647 1648 /// \brief The expression for the base pointer or class reference, 1649 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 1650 /// member expression 1651 Stmt *Base; 1652 1653 /// \brief The type of the base expression; never null. 1654 QualType BaseType; 1655 1656 /// \brief Whether this member expression used the '->' operator or 1657 /// the '.' operator. 1658 bool IsArrow : 1; 1659 1660 /// \brief Whether the lookup results contain an unresolved using 1661 /// declaration. 1662 bool HasUnresolvedUsing : 1; 1663 1664 /// \brief Whether this member expression has explicitly-specified template 1665 /// arguments. 1666 bool HasExplicitTemplateArgs : 1; 1667 1668 /// \brief The location of the '->' or '.' operator. 1669 SourceLocation OperatorLoc; 1670 1671 /// \brief The nested-name-specifier that precedes the member name, if any. 1672 NestedNameSpecifier *Qualifier; 1673 1674 /// \brief The source range covering the nested name specifier. 1675 SourceRange QualifierRange; 1676 1677 /// \brief The member to which this member expression refers, which 1678 /// can be a name or an overloaded operator. 1679 DeclarationName MemberName; 1680 1681 /// \brief The location of the member name. 1682 SourceLocation MemberLoc; 1683 1684 /// \brief Retrieve the explicit template argument list that followed the 1685 /// member template name. 1686 ExplicitTemplateArgumentList *getExplicitTemplateArgs() { 1687 assert(HasExplicitTemplateArgs); 1688 return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1689 } 1690 1691 /// \brief Retrieve the explicit template argument list that followed the 1692 /// member template name, if any. 1693 const ExplicitTemplateArgumentList *getExplicitTemplateArgs() const { 1694 return const_cast<UnresolvedMemberExpr*>(this)->getExplicitTemplateArgs(); 1695 } 1696 1697 UnresolvedMemberExpr(QualType T, bool Dependent, 1698 bool HasUnresolvedUsing, 1699 Expr *Base, QualType BaseType, bool IsArrow, 1700 SourceLocation OperatorLoc, 1701 NestedNameSpecifier *Qualifier, 1702 SourceRange QualifierRange, 1703 DeclarationName Member, 1704 SourceLocation MemberLoc, 1705 const TemplateArgumentListInfo *TemplateArgs); 1706 1707public: 1708 static UnresolvedMemberExpr * 1709 Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing, 1710 Expr *Base, QualType BaseType, bool IsArrow, 1711 SourceLocation OperatorLoc, 1712 NestedNameSpecifier *Qualifier, 1713 SourceRange QualifierRange, 1714 DeclarationName Member, 1715 SourceLocation MemberLoc, 1716 const TemplateArgumentListInfo *TemplateArgs); 1717 1718 /// Adds a declaration to the unresolved set. By assumption, all of 1719 /// these happen at initialization time and properties like 1720 /// 'Dependent' and 'HasUnresolvedUsing' take them into account. 1721 void addDecl(NamedDecl *Decl) { 1722 Results.addDecl(Decl); 1723 } 1724 1725 typedef UnresolvedSet::iterator decls_iterator; 1726 decls_iterator decls_begin() const { return Results.begin(); } 1727 decls_iterator decls_end() const { return Results.end(); } 1728 1729 unsigned getNumDecls() const { return Results.size(); } 1730 1731 /// \brief True if this is an implicit access, i.e. one in which the 1732 /// member being accessed was not written in the source. The source 1733 /// location of the operator is invalid in this case. 1734 bool isImplicitAccess() const { return Base == 0; } 1735 1736 /// \brief Retrieve the base object of this member expressions, 1737 /// e.g., the \c x in \c x.m. 1738 Expr *getBase() { 1739 assert(!isImplicitAccess()); 1740 return cast<Expr>(Base); 1741 } 1742 void setBase(Expr *E) { Base = E; } 1743 1744 QualType getBaseType() const { return BaseType; } 1745 1746 /// \brief Determine whether this member expression used the '->' 1747 /// operator; otherwise, it used the '.' operator. 1748 bool isArrow() const { return IsArrow; } 1749 void setArrow(bool A) { IsArrow = A; } 1750 1751 /// \brief Retrieve the location of the '->' or '.' operator. 1752 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1753 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1754 1755 /// \brief Retrieve the nested-name-specifier that qualifies the member 1756 /// name. 1757 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1758 1759 /// \brief Retrieve the source range covering the nested-name-specifier 1760 /// that qualifies the member name. 1761 SourceRange getQualifierRange() const { return QualifierRange; } 1762 1763 /// \brief Retrieve the name of the member that this expression 1764 /// refers to. 1765 DeclarationName getMemberName() const { return MemberName; } 1766 void setMemberName(DeclarationName N) { MemberName = N; } 1767 1768 // \brief Retrieve the location of the name of the member that this 1769 // expression refers to. 1770 SourceLocation getMemberLoc() const { return MemberLoc; } 1771 void setMemberLoc(SourceLocation L) { MemberLoc = L; } 1772 1773 /// \brief Determines whether this member expression actually had a C++ 1774 /// template argument list explicitly specified, e.g., x.f<int>. 1775 bool hasExplicitTemplateArgs() const { 1776 return HasExplicitTemplateArgs; 1777 } 1778 1779 /// \brief Copies the template arguments into the given structure. 1780 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1781 getExplicitTemplateArgs()->copyInto(List); 1782 } 1783 1784 /// \brief Retrieve the location of the left angle bracket following 1785 /// the member name ('<'). 1786 SourceLocation getLAngleLoc() const { 1787 return getExplicitTemplateArgs()->LAngleLoc; 1788 } 1789 1790 /// \brief Retrieve the template arguments provided as part of this 1791 /// template-id. 1792 const TemplateArgumentLoc *getTemplateArgs() const { 1793 return getExplicitTemplateArgs()->getTemplateArgs(); 1794 } 1795 1796 /// \brief Retrieve the number of template arguments provided as 1797 /// part of this template-id. 1798 unsigned getNumTemplateArgs() const { 1799 return getExplicitTemplateArgs()->NumTemplateArgs; 1800 } 1801 1802 /// \brief Retrieve the location of the right angle bracket 1803 /// following the template arguments ('>'). 1804 SourceLocation getRAngleLoc() const { 1805 return getExplicitTemplateArgs()->RAngleLoc; 1806 } 1807 1808 virtual SourceRange getSourceRange() const { 1809 SourceRange Range; 1810 if (!isImplicitAccess()) 1811 Range.setBegin(Base->getSourceRange().getBegin()); 1812 else if (getQualifier()) 1813 Range.setBegin(getQualifierRange().getBegin()); 1814 else 1815 Range.setBegin(MemberLoc); 1816 1817 if (hasExplicitTemplateArgs()) 1818 Range.setEnd(getRAngleLoc()); 1819 else 1820 Range.setEnd(MemberLoc); 1821 return Range; 1822 } 1823 1824 static bool classof(const Stmt *T) { 1825 return T->getStmtClass() == UnresolvedMemberExprClass; 1826 } 1827 static bool classof(const UnresolvedMemberExpr *) { return true; } 1828 1829 // Iterators 1830 virtual child_iterator child_begin(); 1831 virtual child_iterator child_end(); 1832}; 1833 1834} // end namespace clang 1835 1836#endif 1837