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