1193326Sed//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9263509Sdim/// 10263509Sdim/// \file 11263509Sdim/// \brief Defines the clang::Expr interface and subclasses for C++ expressions. 12263509Sdim/// 13193326Sed//===----------------------------------------------------------------------===// 14193326Sed 15193326Sed#ifndef LLVM_CLANG_AST_EXPRCXX_H 16193326Sed#define LLVM_CLANG_AST_EXPRCXX_H 17193326Sed 18245431Sdim#include "clang/AST/Decl.h" 19193326Sed#include "clang/AST/Expr.h" 20252723Sdim#include "clang/AST/TemplateBase.h" 21202879Srdivacky#include "clang/AST/UnresolvedSet.h" 22235633Sdim#include "clang/Basic/ExpressionTraits.h" 23235633Sdim#include "clang/Basic/Lambda.h" 24235633Sdim#include "clang/Basic/TypeTraits.h" 25235633Sdim#include "llvm/Support/Compiler.h" 26193326Sed 27193326Sednamespace clang { 28193326Sed 29218893Sdimclass CXXConstructorDecl; 30218893Sdimclass CXXDestructorDecl; 31218893Sdimclass CXXMethodDecl; 32218893Sdimclass CXXTemporary; 33252723Sdimclass MSPropertyDecl; 34218893Sdimclass TemplateArgumentListInfo; 35252723Sdimclass UuidAttr; 36193326Sed 37193326Sed//===--------------------------------------------------------------------===// 38193326Sed// C++ Expressions. 39193326Sed//===--------------------------------------------------------------------===// 40193326Sed 41193326Sed/// \brief A call to an overloaded operator written using operator 42193326Sed/// syntax. 43193326Sed/// 44193326Sed/// Represents a call to an overloaded operator written using operator 45193326Sed/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 46193326Sed/// normal call, this AST node provides better information about the 47193326Sed/// syntactic representation of the call. 48193326Sed/// 49193326Sed/// In a C++ template, this expression node kind will be used whenever 50193326Sed/// any of the arguments are type-dependent. In this case, the 51193326Sed/// function itself will be a (possibly empty) set of functions and 52193326Sed/// function templates that were found by name lookup at template 53193326Sed/// definition time. 54193326Sedclass CXXOperatorCallExpr : public CallExpr { 55193326Sed /// \brief The overloaded operator. 56193326Sed OverloadedOperatorKind Operator; 57245431Sdim SourceRange Range; 58193326Sed 59245431Sdim // Record the FP_CONTRACT state that applies to this operator call. Only 60245431Sdim // meaningful for floating point types. For other types this value can be 61245431Sdim // set to false. 62245431Sdim unsigned FPContractable : 1; 63245431Sdim 64245431Sdim SourceRange getSourceRangeImpl() const LLVM_READONLY; 65193326Sedpublic: 66198092Srdivacky CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 67245431Sdim ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 68245431Sdim SourceLocation operatorloc, bool fpContractable) 69245431Sdim : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK, 70218893Sdim operatorloc), 71245431Sdim Operator(Op), FPContractable(fpContractable) { 72245431Sdim Range = getSourceRangeImpl(); 73245431Sdim } 74198092Srdivacky explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 75198092Srdivacky CallExpr(C, CXXOperatorCallExprClass, Empty) { } 76193326Sed 77198092Srdivacky 78263509Sdim /// \brief Returns the kind of overloaded operator that this 79193326Sed /// expression refers to. 80193326Sed OverloadedOperatorKind getOperator() const { return Operator; } 81193326Sed 82263509Sdim /// \brief Returns the location of the operator symbol in the expression. 83263509Sdim /// 84263509Sdim /// When \c getOperator()==OO_Call, this is the location of the right 85263509Sdim /// parentheses; when \c getOperator()==OO_Subscript, this is the location 86263509Sdim /// of the right bracket. 87193326Sed SourceLocation getOperatorLoc() const { return getRParenLoc(); } 88193326Sed 89252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 90252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 91245431Sdim SourceRange getSourceRange() const { return Range; } 92198092Srdivacky 93198092Srdivacky static bool classof(const Stmt *T) { 94198092Srdivacky return T->getStmtClass() == CXXOperatorCallExprClass; 95193326Sed } 96245431Sdim 97245431Sdim // Set the FP contractability status of this operator. Only meaningful for 98245431Sdim // operations on floating point types. 99245431Sdim void setFPContractable(bool FPC) { FPContractable = FPC; } 100245431Sdim 101245431Sdim // Get the FP contractability status of this operator. Only meaningful for 102245431Sdim // operations on floating point types. 103245431Sdim bool isFPContractable() const { return FPContractable; } 104245431Sdim 105245431Sdim friend class ASTStmtReader; 106245431Sdim friend class ASTStmtWriter; 107193326Sed}; 108193326Sed 109263509Sdim/// Represents a call to a member function that 110193326Sed/// may be written either with member call syntax (e.g., "obj.func()" 111193326Sed/// or "objptr->func()") or with normal function-call syntax 112193326Sed/// ("func()") within a member function that ends up calling a member 113193326Sed/// function. The callee in either case is a MemberExpr that contains 114193326Sed/// both the object argument and the member function, while the 115193326Sed/// arguments are the arguments within the parentheses (not including 116193326Sed/// the object argument). 117193326Sedclass CXXMemberCallExpr : public CallExpr { 118193326Sedpublic: 119245431Sdim CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args, 120218893Sdim QualType t, ExprValueKind VK, SourceLocation RP) 121245431Sdim : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {} 122193326Sed 123208600Srdivacky CXXMemberCallExpr(ASTContext &C, EmptyShell Empty) 124208600Srdivacky : CallExpr(C, CXXMemberCallExprClass, Empty) { } 125208600Srdivacky 126263509Sdim /// \brief Retrieves the implicit object argument for the member call. 127263509Sdim /// 128263509Sdim /// For example, in "x.f(5)", this returns the sub-expression "x". 129221345Sdim Expr *getImplicitObjectArgument() const; 130235633Sdim 131263509Sdim /// \brief Retrieves the declaration of the called method. 132221345Sdim CXXMethodDecl *getMethodDecl() const; 133193326Sed 134263509Sdim /// \brief Retrieves the CXXRecordDecl for the underlying type of 135263509Sdim /// the implicit object argument. 136263509Sdim /// 137263509Sdim /// Note that this is may not be the same declaration as that of the class 138263509Sdim /// context of the CXXMethodDecl which this function is calling. 139218893Sdim /// FIXME: Returns 0 for member pointer call exprs. 140245431Sdim CXXRecordDecl *getRecordDecl() const; 141218893Sdim 142198092Srdivacky static bool classof(const Stmt *T) { 143193326Sed return T->getStmtClass() == CXXMemberCallExprClass; 144193326Sed } 145193326Sed}; 146193326Sed 147263509Sdim/// \brief Represents a call to a CUDA kernel function. 148218893Sdimclass CUDAKernelCallExpr : public CallExpr { 149218893Sdimprivate: 150218893Sdim enum { CONFIG, END_PREARG }; 151218893Sdim 152218893Sdimpublic: 153218893Sdim CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config, 154245431Sdim ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 155245431Sdim SourceLocation RP) 156245431Sdim : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) { 157218893Sdim setConfig(Config); 158218893Sdim } 159218893Sdim 160218893Sdim CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty) 161218893Sdim : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { } 162218893Sdim 163218893Sdim const CallExpr *getConfig() const { 164218893Sdim return cast_or_null<CallExpr>(getPreArg(CONFIG)); 165218893Sdim } 166218893Sdim CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } 167218893Sdim void setConfig(CallExpr *E) { setPreArg(CONFIG, E); } 168218893Sdim 169218893Sdim static bool classof(const Stmt *T) { 170218893Sdim return T->getStmtClass() == CUDAKernelCallExprClass; 171218893Sdim } 172218893Sdim}; 173218893Sdim 174263509Sdim/// \brief Abstract class common to all of the C++ "named"/"keyword" casts. 175193326Sed/// 176193326Sed/// This abstract class is inherited by all of the classes 177263509Sdim/// representing "named" casts: CXXStaticCastExpr for \c static_cast, 178263509Sdim/// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for 179263509Sdim/// reinterpret_cast, and CXXConstCastExpr for \c const_cast. 180193326Sedclass CXXNamedCastExpr : public ExplicitCastExpr { 181193326Sedprivate: 182193326Sed SourceLocation Loc; // the location of the casting op 183218893Sdim SourceLocation RParenLoc; // the location of the right parenthesis 184252723Sdim SourceRange AngleBrackets; // range for '<' '>' 185235633Sdim 186193326Sedprotected: 187218893Sdim CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 188218893Sdim CastKind kind, Expr *op, unsigned PathSize, 189218893Sdim TypeSourceInfo *writtenTy, SourceLocation l, 190252723Sdim SourceLocation RParenLoc, 191252723Sdim SourceRange AngleBrackets) 192218893Sdim : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l), 193252723Sdim RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {} 194193326Sed 195212904Sdim explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 196212904Sdim : ExplicitCastExpr(SC, Shell, PathSize) { } 197202879Srdivacky 198218893Sdim friend class ASTStmtReader; 199235633Sdim 200193326Sedpublic: 201193326Sed const char *getCastName() const; 202193326Sed 203193326Sed /// \brief Retrieve the location of the cast operator keyword, e.g., 204263509Sdim /// \c static_cast. 205193326Sed SourceLocation getOperatorLoc() const { return Loc; } 206193326Sed 207218893Sdim /// \brief Retrieve the location of the closing parenthesis. 208218893Sdim SourceLocation getRParenLoc() const { return RParenLoc; } 209235633Sdim 210252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 211252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 212252723Sdim SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; } 213252723Sdim 214198092Srdivacky static bool classof(const Stmt *T) { 215193326Sed switch (T->getStmtClass()) { 216193326Sed case CXXStaticCastExprClass: 217193326Sed case CXXDynamicCastExprClass: 218193326Sed case CXXReinterpretCastExprClass: 219193326Sed case CXXConstCastExprClass: 220193326Sed return true; 221193326Sed default: 222193326Sed return false; 223193326Sed } 224193326Sed } 225193326Sed}; 226193326Sed 227263509Sdim/// \brief A C++ \c static_cast expression (C++ [expr.static.cast]). 228198092Srdivacky/// 229193326Sed/// This expression node represents a C++ static cast, e.g., 230263509Sdim/// \c static_cast<int>(1.0). 231193326Sedclass CXXStaticCastExpr : public CXXNamedCastExpr { 232218893Sdim CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, 233212904Sdim unsigned pathSize, TypeSourceInfo *writtenTy, 234252723Sdim SourceLocation l, SourceLocation RParenLoc, 235252723Sdim SourceRange AngleBrackets) 236218893Sdim : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, 237252723Sdim writtenTy, l, RParenLoc, AngleBrackets) {} 238193326Sed 239212904Sdim explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize) 240212904Sdim : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { } 241202879Srdivacky 242212904Sdimpublic: 243263509Sdim static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T, 244218893Sdim ExprValueKind VK, CastKind K, Expr *Op, 245212904Sdim const CXXCastPath *Path, 246235633Sdim TypeSourceInfo *Written, SourceLocation L, 247252723Sdim SourceLocation RParenLoc, 248252723Sdim SourceRange AngleBrackets); 249263509Sdim static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context, 250212904Sdim unsigned PathSize); 251212904Sdim 252198092Srdivacky static bool classof(const Stmt *T) { 253193326Sed return T->getStmtClass() == CXXStaticCastExprClass; 254193326Sed } 255193326Sed}; 256193326Sed 257263509Sdim/// \brief A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]). 258198092Srdivacky/// 259193326Sed/// This expression node represents a dynamic cast, e.g., 260263509Sdim/// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time 261263509Sdim/// check to determine how to perform the type conversion. 262193326Sedclass CXXDynamicCastExpr : public CXXNamedCastExpr { 263218893Sdim CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, 264218893Sdim Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy, 265252723Sdim SourceLocation l, SourceLocation RParenLoc, 266252723Sdim SourceRange AngleBrackets) 267218893Sdim : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, 268252723Sdim writtenTy, l, RParenLoc, AngleBrackets) {} 269193326Sed 270212904Sdim explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) 271212904Sdim : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { } 272202879Srdivacky 273212904Sdimpublic: 274263509Sdim static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T, 275218893Sdim ExprValueKind VK, CastKind Kind, Expr *Op, 276212904Sdim const CXXCastPath *Path, 277235633Sdim TypeSourceInfo *Written, SourceLocation L, 278252723Sdim SourceLocation RParenLoc, 279252723Sdim SourceRange AngleBrackets); 280235633Sdim 281263509Sdim static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context, 282212904Sdim unsigned pathSize); 283212904Sdim 284221345Sdim bool isAlwaysNull() const; 285221345Sdim 286198092Srdivacky static bool classof(const Stmt *T) { 287193326Sed return T->getStmtClass() == CXXDynamicCastExprClass; 288193326Sed } 289193326Sed}; 290193326Sed 291263509Sdim/// \brief A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]). 292198092Srdivacky/// 293193326Sed/// This expression node represents a reinterpret cast, e.g., 294193326Sed/// @c reinterpret_cast<int>(VoidPtr). 295263509Sdim/// 296263509Sdim/// A reinterpret_cast provides a differently-typed view of a value but 297263509Sdim/// (in Clang, as in most C++ implementations) performs no actual work at 298263509Sdim/// run time. 299193326Sedclass CXXReinterpretCastExpr : public CXXNamedCastExpr { 300218893Sdim CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, 301218893Sdim Expr *op, unsigned pathSize, 302235633Sdim TypeSourceInfo *writtenTy, SourceLocation l, 303252723Sdim SourceLocation RParenLoc, 304252723Sdim SourceRange AngleBrackets) 305218893Sdim : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, 306252723Sdim pathSize, writtenTy, l, RParenLoc, AngleBrackets) {} 307193326Sed 308212904Sdim CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) 309212904Sdim : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { } 310202879Srdivacky 311212904Sdimpublic: 312263509Sdim static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T, 313218893Sdim ExprValueKind VK, CastKind Kind, 314218893Sdim Expr *Op, const CXXCastPath *Path, 315235633Sdim TypeSourceInfo *WrittenTy, SourceLocation L, 316252723Sdim SourceLocation RParenLoc, 317252723Sdim SourceRange AngleBrackets); 318263509Sdim static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context, 319212904Sdim unsigned pathSize); 320212904Sdim 321198092Srdivacky static bool classof(const Stmt *T) { 322193326Sed return T->getStmtClass() == CXXReinterpretCastExprClass; 323193326Sed } 324193326Sed}; 325193326Sed 326263509Sdim/// \brief A C++ \c const_cast expression (C++ [expr.const.cast]). 327198092Srdivacky/// 328193326Sed/// This expression node represents a const cast, e.g., 329263509Sdim/// \c const_cast<char*>(PtrToConstChar). 330263509Sdim/// 331263509Sdim/// A const_cast can remove type qualifiers but does not change the underlying 332263509Sdim/// value. 333193326Sedclass CXXConstCastExpr : public CXXNamedCastExpr { 334218893Sdim CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, 335235633Sdim TypeSourceInfo *writtenTy, SourceLocation l, 336252723Sdim SourceLocation RParenLoc, SourceRange AngleBrackets) 337235633Sdim : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 338252723Sdim 0, writtenTy, l, RParenLoc, AngleBrackets) {} 339193326Sed 340202879Srdivacky explicit CXXConstCastExpr(EmptyShell Empty) 341212904Sdim : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { } 342202879Srdivacky 343212904Sdimpublic: 344263509Sdim static CXXConstCastExpr *Create(const ASTContext &Context, QualType T, 345218893Sdim ExprValueKind VK, Expr *Op, 346235633Sdim TypeSourceInfo *WrittenTy, SourceLocation L, 347252723Sdim SourceLocation RParenLoc, 348252723Sdim SourceRange AngleBrackets); 349263509Sdim static CXXConstCastExpr *CreateEmpty(const ASTContext &Context); 350212904Sdim 351198092Srdivacky static bool classof(const Stmt *T) { 352193326Sed return T->getStmtClass() == CXXConstCastExprClass; 353193326Sed } 354193326Sed}; 355193326Sed 356263509Sdim/// \brief A call to a literal operator (C++11 [over.literal]) 357235633Sdim/// written as a user-defined literal (C++11 [lit.ext]). 358235633Sdim/// 359235633Sdim/// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this 360235633Sdim/// is semantically equivalent to a normal call, this AST node provides better 361235633Sdim/// information about the syntactic representation of the literal. 362235633Sdim/// 363235633Sdim/// Since literal operators are never found by ADL and can only be declared at 364235633Sdim/// namespace scope, a user-defined literal is never dependent. 365235633Sdimclass UserDefinedLiteral : public CallExpr { 366235633Sdim /// \brief The location of a ud-suffix within the literal. 367235633Sdim SourceLocation UDSuffixLoc; 368235633Sdim 369235633Sdimpublic: 370263509Sdim UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args, 371235633Sdim QualType T, ExprValueKind VK, SourceLocation LitEndLoc, 372235633Sdim SourceLocation SuffixLoc) 373245431Sdim : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc), 374245431Sdim UDSuffixLoc(SuffixLoc) {} 375263509Sdim explicit UserDefinedLiteral(const ASTContext &C, EmptyShell Empty) 376235633Sdim : CallExpr(C, UserDefinedLiteralClass, Empty) {} 377235633Sdim 378235633Sdim /// The kind of literal operator which is invoked. 379235633Sdim enum LiteralOperatorKind { 380235633Sdim LOK_Raw, ///< Raw form: operator "" X (const char *) 381235633Sdim LOK_Template, ///< Raw form: operator "" X<cs...> () 382235633Sdim LOK_Integer, ///< operator "" X (unsigned long long) 383235633Sdim LOK_Floating, ///< operator "" X (long double) 384235633Sdim LOK_String, ///< operator "" X (const CharT *, size_t) 385235633Sdim LOK_Character ///< operator "" X (CharT) 386235633Sdim }; 387235633Sdim 388263509Sdim /// \brief Returns the kind of literal operator invocation 389235633Sdim /// which this expression represents. 390235633Sdim LiteralOperatorKind getLiteralOperatorKind() const; 391235633Sdim 392263509Sdim /// \brief If this is not a raw user-defined literal, get the 393235633Sdim /// underlying cooked literal (representing the literal with the suffix 394235633Sdim /// removed). 395235633Sdim Expr *getCookedLiteral(); 396235633Sdim const Expr *getCookedLiteral() const { 397235633Sdim return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral(); 398235633Sdim } 399235633Sdim 400245431Sdim SourceLocation getLocStart() const { 401245431Sdim if (getLiteralOperatorKind() == LOK_Template) 402245431Sdim return getRParenLoc(); 403245431Sdim return getArg(0)->getLocStart(); 404245431Sdim } 405245431Sdim SourceLocation getLocEnd() const { return getRParenLoc(); } 406245431Sdim 407245431Sdim 408263509Sdim /// \brief Returns the location of a ud-suffix in the expression. 409263509Sdim /// 410235633Sdim /// For a string literal, there may be multiple identical suffixes. This 411235633Sdim /// returns the first. 412245431Sdim SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; } 413235633Sdim 414263509Sdim /// \brief Returns the ud-suffix specified for this literal. 415235633Sdim const IdentifierInfo *getUDSuffix() const; 416235633Sdim 417235633Sdim static bool classof(const Stmt *S) { 418235633Sdim return S->getStmtClass() == UserDefinedLiteralClass; 419235633Sdim } 420235633Sdim 421235633Sdim friend class ASTStmtReader; 422235633Sdim friend class ASTStmtWriter; 423235633Sdim}; 424235633Sdim 425263509Sdim/// \brief A boolean literal, per ([C++ lex.bool] Boolean literals). 426198092Srdivacky/// 427193326Sedclass CXXBoolLiteralExpr : public Expr { 428193326Sed bool Value; 429193326Sed SourceLocation Loc; 430193326Sedpublic: 431198092Srdivacky CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 432218893Sdim Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 433224145Sdim false, false), 434218893Sdim Value(val), Loc(l) {} 435193326Sed 436203955Srdivacky explicit CXXBoolLiteralExpr(EmptyShell Empty) 437203955Srdivacky : Expr(CXXBoolLiteralExprClass, Empty) { } 438203955Srdivacky 439193326Sed bool getValue() const { return Value; } 440203955Srdivacky void setValue(bool V) { Value = V; } 441193326Sed 442252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 443252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 444198092Srdivacky 445203955Srdivacky SourceLocation getLocation() const { return Loc; } 446203955Srdivacky void setLocation(SourceLocation L) { Loc = L; } 447203955Srdivacky 448198092Srdivacky static bool classof(const Stmt *T) { 449193326Sed return T->getStmtClass() == CXXBoolLiteralExprClass; 450193326Sed } 451198092Srdivacky 452193326Sed // Iterators 453218893Sdim child_range children() { return child_range(); } 454193326Sed}; 455193326Sed 456263509Sdim/// \brief The null pointer literal (C++11 [lex.nullptr]) 457263509Sdim/// 458263509Sdim/// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr. 459193326Sedclass CXXNullPtrLiteralExpr : public Expr { 460193326Sed SourceLocation Loc; 461193326Sedpublic: 462193326Sed CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 463218893Sdim Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 464224145Sdim false, false), 465218893Sdim Loc(l) {} 466193326Sed 467203955Srdivacky explicit CXXNullPtrLiteralExpr(EmptyShell Empty) 468203955Srdivacky : Expr(CXXNullPtrLiteralExprClass, Empty) { } 469203955Srdivacky 470252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 471252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 472193326Sed 473203955Srdivacky SourceLocation getLocation() const { return Loc; } 474203955Srdivacky void setLocation(SourceLocation L) { Loc = L; } 475203955Srdivacky 476193326Sed static bool classof(const Stmt *T) { 477193326Sed return T->getStmtClass() == CXXNullPtrLiteralExprClass; 478193326Sed } 479193326Sed 480218893Sdim child_range children() { return child_range(); } 481193326Sed}; 482193326Sed 483263509Sdim/// \brief Implicit construction of a std::initializer_list<T> object from an 484263509Sdim/// array temporary within list-initialization (C++11 [dcl.init.list]p5). 485263509Sdimclass CXXStdInitializerListExpr : public Expr { 486263509Sdim Stmt *SubExpr; 487263509Sdim 488263509Sdim CXXStdInitializerListExpr(EmptyShell Empty) 489263509Sdim : Expr(CXXStdInitializerListExprClass, Empty), SubExpr(0) {} 490263509Sdim 491263509Sdimpublic: 492263509Sdim CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr) 493263509Sdim : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary, 494263509Sdim Ty->isDependentType(), SubExpr->isValueDependent(), 495263509Sdim SubExpr->isInstantiationDependent(), 496263509Sdim SubExpr->containsUnexpandedParameterPack()), 497263509Sdim SubExpr(SubExpr) {} 498263509Sdim 499263509Sdim Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); } 500263509Sdim const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); } 501263509Sdim 502263509Sdim SourceLocation getLocStart() const LLVM_READONLY { 503263509Sdim return SubExpr->getLocStart(); 504263509Sdim } 505263509Sdim SourceLocation getLocEnd() const LLVM_READONLY { 506263509Sdim return SubExpr->getLocEnd(); 507263509Sdim } 508263509Sdim SourceRange getSourceRange() const LLVM_READONLY { 509263509Sdim return SubExpr->getSourceRange(); 510263509Sdim } 511263509Sdim 512263509Sdim static bool classof(const Stmt *S) { 513263509Sdim return S->getStmtClass() == CXXStdInitializerListExprClass; 514263509Sdim } 515263509Sdim 516263509Sdim child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 517263509Sdim 518263509Sdim friend class ASTReader; 519263509Sdim friend class ASTStmtReader; 520263509Sdim}; 521263509Sdim 522263509Sdim/// A C++ \c typeid expression (C++ [expr.typeid]), which gets 523263509Sdim/// the \c type_info that corresponds to the supplied type, or the (possibly 524193326Sed/// dynamic) type of the supplied expression. 525193326Sed/// 526263509Sdim/// This represents code like \c typeid(int) or \c typeid(*objPtr) 527193326Sedclass CXXTypeidExpr : public Expr { 528193326Sedprivate: 529207619Srdivacky llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 530193326Sed SourceRange Range; 531193326Sed 532193326Sedpublic: 533207619Srdivacky CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 534218893Sdim : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 535207619Srdivacky // typeid is never type-dependent (C++ [temp.dep.expr]p4) 536207619Srdivacky false, 537207619Srdivacky // typeid is value-dependent if the type or expression are dependent 538218893Sdim Operand->getType()->isDependentType(), 539224145Sdim Operand->getType()->isInstantiationDependentType(), 540218893Sdim Operand->getType()->containsUnexpandedParameterPack()), 541207619Srdivacky Operand(Operand), Range(R) { } 542235633Sdim 543207619Srdivacky CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) 544218893Sdim : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 545193326Sed // typeid is never type-dependent (C++ [temp.dep.expr]p4) 546218893Sdim false, 547193326Sed // typeid is value-dependent if the type or expression are dependent 548218893Sdim Operand->isTypeDependent() || Operand->isValueDependent(), 549224145Sdim Operand->isInstantiationDependent(), 550218893Sdim Operand->containsUnexpandedParameterPack()), 551207619Srdivacky Operand(Operand), Range(R) { } 552193326Sed 553208600Srdivacky CXXTypeidExpr(EmptyShell Empty, bool isExpr) 554208600Srdivacky : Expr(CXXTypeidExprClass, Empty) { 555208600Srdivacky if (isExpr) 556208600Srdivacky Operand = (Expr*)0; 557208600Srdivacky else 558208600Srdivacky Operand = (TypeSourceInfo*)0; 559208600Srdivacky } 560235633Sdim 561245431Sdim /// Determine whether this typeid has a type operand which is potentially 562245431Sdim /// evaluated, per C++11 [expr.typeid]p3. 563245431Sdim bool isPotentiallyEvaluated() const; 564245431Sdim 565207619Srdivacky bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 566235633Sdim 567207619Srdivacky /// \brief Retrieves the type operand of this typeid() expression after 568207619Srdivacky /// various required adjustments (removing reference types, cv-qualifiers). 569263509Sdim QualType getTypeOperand(ASTContext &Context) const; 570207619Srdivacky 571207619Srdivacky /// \brief Retrieve source information for the type operand. 572207619Srdivacky TypeSourceInfo *getTypeOperandSourceInfo() const { 573193326Sed assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 574207619Srdivacky return Operand.get<TypeSourceInfo *>(); 575193326Sed } 576208600Srdivacky 577208600Srdivacky void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 578208600Srdivacky assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 579208600Srdivacky Operand = TSI; 580208600Srdivacky } 581235633Sdim 582208600Srdivacky Expr *getExprOperand() const { 583193326Sed assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 584207619Srdivacky return static_cast<Expr*>(Operand.get<Stmt *>()); 585193326Sed } 586235633Sdim 587208600Srdivacky void setExprOperand(Expr *E) { 588208600Srdivacky assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 589208600Srdivacky Operand = E; 590193326Sed } 591235633Sdim 592252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 593252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 594235633Sdim SourceRange getSourceRange() const LLVM_READONLY { return Range; } 595208600Srdivacky void setSourceRange(SourceRange R) { Range = R; } 596235633Sdim 597193326Sed static bool classof(const Stmt *T) { 598193326Sed return T->getStmtClass() == CXXTypeidExprClass; 599193326Sed } 600193326Sed 601193326Sed // Iterators 602218893Sdim child_range children() { 603218893Sdim if (isTypeOperand()) return child_range(); 604218893Sdim Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 605218893Sdim return child_range(begin, begin + 1); 606218893Sdim } 607193326Sed}; 608193326Sed 609263509Sdim/// \brief A member reference to an MSPropertyDecl. 610263509Sdim/// 611263509Sdim/// This expression always has pseudo-object type, and therefore it is 612263509Sdim/// typically not encountered in a fully-typechecked expression except 613263509Sdim/// within the syntactic form of a PseudoObjectExpr. 614252723Sdimclass MSPropertyRefExpr : public Expr { 615252723Sdim Expr *BaseExpr; 616252723Sdim MSPropertyDecl *TheDecl; 617252723Sdim SourceLocation MemberLoc; 618252723Sdim bool IsArrow; 619252723Sdim NestedNameSpecifierLoc QualifierLoc; 620252723Sdim 621252723Sdimpublic: 622252723Sdim MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow, 623252723Sdim QualType ty, ExprValueKind VK, 624252723Sdim NestedNameSpecifierLoc qualifierLoc, 625252723Sdim SourceLocation nameLoc) 626252723Sdim : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary, 627252723Sdim /*type-dependent*/ false, baseExpr->isValueDependent(), 628252723Sdim baseExpr->isInstantiationDependent(), 629252723Sdim baseExpr->containsUnexpandedParameterPack()), 630252723Sdim BaseExpr(baseExpr), TheDecl(decl), 631252723Sdim MemberLoc(nameLoc), IsArrow(isArrow), 632252723Sdim QualifierLoc(qualifierLoc) {} 633252723Sdim 634252723Sdim MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {} 635252723Sdim 636252723Sdim SourceRange getSourceRange() const LLVM_READONLY { 637252723Sdim return SourceRange(getLocStart(), getLocEnd()); 638252723Sdim } 639252723Sdim bool isImplicitAccess() const { 640252723Sdim return getBaseExpr() && getBaseExpr()->isImplicitCXXThis(); 641252723Sdim } 642252723Sdim SourceLocation getLocStart() const { 643252723Sdim if (!isImplicitAccess()) 644252723Sdim return BaseExpr->getLocStart(); 645252723Sdim else if (QualifierLoc) 646252723Sdim return QualifierLoc.getBeginLoc(); 647252723Sdim else 648252723Sdim return MemberLoc; 649252723Sdim } 650252723Sdim SourceLocation getLocEnd() const { return getMemberLoc(); } 651252723Sdim 652252723Sdim child_range children() { 653252723Sdim return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1); 654252723Sdim } 655252723Sdim static bool classof(const Stmt *T) { 656252723Sdim return T->getStmtClass() == MSPropertyRefExprClass; 657252723Sdim } 658252723Sdim 659252723Sdim Expr *getBaseExpr() const { return BaseExpr; } 660252723Sdim MSPropertyDecl *getPropertyDecl() const { return TheDecl; } 661252723Sdim bool isArrow() const { return IsArrow; } 662252723Sdim SourceLocation getMemberLoc() const { return MemberLoc; } 663252723Sdim NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 664252723Sdim 665252723Sdim friend class ASTStmtReader; 666252723Sdim}; 667252723Sdim 668263509Sdim/// A Microsoft C++ @c __uuidof expression, which gets 669218893Sdim/// the _GUID that corresponds to the supplied type or expression. 670218893Sdim/// 671218893Sdim/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) 672218893Sdimclass CXXUuidofExpr : public Expr { 673218893Sdimprivate: 674218893Sdim llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 675218893Sdim SourceRange Range; 676218893Sdim 677218893Sdimpublic: 678218893Sdim CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 679218893Sdim : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 680218893Sdim false, Operand->getType()->isDependentType(), 681224145Sdim Operand->getType()->isInstantiationDependentType(), 682218893Sdim Operand->getType()->containsUnexpandedParameterPack()), 683218893Sdim Operand(Operand), Range(R) { } 684235633Sdim 685218893Sdim CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R) 686218893Sdim : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 687218893Sdim false, Operand->isTypeDependent(), 688224145Sdim Operand->isInstantiationDependent(), 689218893Sdim Operand->containsUnexpandedParameterPack()), 690218893Sdim Operand(Operand), Range(R) { } 691218893Sdim 692218893Sdim CXXUuidofExpr(EmptyShell Empty, bool isExpr) 693218893Sdim : Expr(CXXUuidofExprClass, Empty) { 694218893Sdim if (isExpr) 695218893Sdim Operand = (Expr*)0; 696218893Sdim else 697218893Sdim Operand = (TypeSourceInfo*)0; 698218893Sdim } 699235633Sdim 700218893Sdim bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 701235633Sdim 702218893Sdim /// \brief Retrieves the type operand of this __uuidof() expression after 703218893Sdim /// various required adjustments (removing reference types, cv-qualifiers). 704263509Sdim QualType getTypeOperand(ASTContext &Context) const; 705218893Sdim 706218893Sdim /// \brief Retrieve source information for the type operand. 707218893Sdim TypeSourceInfo *getTypeOperandSourceInfo() const { 708218893Sdim assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 709218893Sdim return Operand.get<TypeSourceInfo *>(); 710218893Sdim } 711218893Sdim 712218893Sdim void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 713218893Sdim assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 714218893Sdim Operand = TSI; 715218893Sdim } 716235633Sdim 717218893Sdim Expr *getExprOperand() const { 718218893Sdim assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 719218893Sdim return static_cast<Expr*>(Operand.get<Stmt *>()); 720218893Sdim } 721235633Sdim 722218893Sdim void setExprOperand(Expr *E) { 723218893Sdim assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 724218893Sdim Operand = E; 725218893Sdim } 726218893Sdim 727263509Sdim StringRef getUuidAsStringRef(ASTContext &Context) const; 728263509Sdim 729252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 730252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 731235633Sdim SourceRange getSourceRange() const LLVM_READONLY { return Range; } 732218893Sdim void setSourceRange(SourceRange R) { Range = R; } 733235633Sdim 734218893Sdim static bool classof(const Stmt *T) { 735218893Sdim return T->getStmtClass() == CXXUuidofExprClass; 736218893Sdim } 737218893Sdim 738263509Sdim /// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to 739263509Sdim /// a single GUID. 740263509Sdim static UuidAttr *GetUuidAttrOfType(QualType QT, 741263509Sdim bool *HasMultipleGUIDsPtr = 0); 742245431Sdim 743218893Sdim // Iterators 744218893Sdim child_range children() { 745218893Sdim if (isTypeOperand()) return child_range(); 746218893Sdim Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 747218893Sdim return child_range(begin, begin + 1); 748218893Sdim } 749218893Sdim}; 750218893Sdim 751263509Sdim/// \brief Represents the \c this expression in C++. 752263509Sdim/// 753263509Sdim/// This is a pointer to the object on which the current member function is 754193326Sed/// executing (C++ [expr.prim]p3). Example: 755193326Sed/// 756263509Sdim/// \code 757193326Sed/// class Foo { 758193326Sed/// public: 759193326Sed/// void bar(); 760193326Sed/// void test() { this->bar(); } 761193326Sed/// }; 762263509Sdim/// \endcode 763193326Sedclass CXXThisExpr : public Expr { 764193326Sed SourceLocation Loc; 765202379Srdivacky bool Implicit : 1; 766235633Sdim 767193326Sedpublic: 768202379Srdivacky CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 769218893Sdim : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, 770193326Sed // 'this' is type-dependent if the class type of the enclosing 771193326Sed // member function is dependent (C++ [temp.dep.expr]p2) 772218893Sdim Type->isDependentType(), Type->isDependentType(), 773224145Sdim Type->isInstantiationDependentType(), 774218893Sdim /*ContainsUnexpandedParameterPack=*/false), 775202379Srdivacky Loc(L), Implicit(isImplicit) { } 776193326Sed 777208600Srdivacky CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} 778208600Srdivacky 779208600Srdivacky SourceLocation getLocation() const { return Loc; } 780208600Srdivacky void setLocation(SourceLocation L) { Loc = L; } 781208600Srdivacky 782252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 783252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 784193326Sed 785202379Srdivacky bool isImplicit() const { return Implicit; } 786202379Srdivacky void setImplicit(bool I) { Implicit = I; } 787235633Sdim 788198092Srdivacky static bool classof(const Stmt *T) { 789193326Sed return T->getStmtClass() == CXXThisExprClass; 790193326Sed } 791193326Sed 792193326Sed // Iterators 793218893Sdim child_range children() { return child_range(); } 794193326Sed}; 795193326Sed 796263509Sdim/// \brief A C++ throw-expression (C++ [except.throw]). 797193326Sed/// 798263509Sdim/// This handles 'throw' (for re-throwing the current exception) and 799263509Sdim/// 'throw' assignment-expression. When assignment-expression isn't 800263509Sdim/// present, Op will be null. 801193326Sedclass CXXThrowExpr : public Expr { 802193326Sed Stmt *Op; 803193326Sed SourceLocation ThrowLoc; 804224145Sdim /// \brief Whether the thrown variable (if any) is in scope. 805224145Sdim unsigned IsThrownVariableInScope : 1; 806235633Sdim 807224145Sdim friend class ASTStmtReader; 808235633Sdim 809193326Sedpublic: 810263509Sdim // \p Ty is the void type which is used as the result type of the 811263509Sdim // expression. The \p l is the location of the throw keyword. \p expr 812193326Sed // can by null, if the optional expression to throw isn't present. 813224145Sdim CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l, 814224145Sdim bool IsThrownVariableInScope) : 815218893Sdim Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 816224145Sdim expr && expr->isInstantiationDependent(), 817218893Sdim expr && expr->containsUnexpandedParameterPack()), 818224145Sdim Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {} 819208600Srdivacky CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} 820208600Srdivacky 821193326Sed const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 822193326Sed Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 823193326Sed 824193326Sed SourceLocation getThrowLoc() const { return ThrowLoc; } 825193326Sed 826224145Sdim /// \brief Determines whether the variable thrown by this expression (if any!) 827224145Sdim /// is within the innermost try block. 828224145Sdim /// 829224145Sdim /// This information is required to determine whether the NRVO can apply to 830224145Sdim /// this variable. 831224145Sdim bool isThrownVariableInScope() const { return IsThrownVariableInScope; } 832235633Sdim 833252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; } 834252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { 835193326Sed if (getSubExpr() == 0) 836252723Sdim return ThrowLoc; 837252723Sdim return getSubExpr()->getLocEnd(); 838193326Sed } 839193326Sed 840193326Sed static bool classof(const Stmt *T) { 841193326Sed return T->getStmtClass() == CXXThrowExprClass; 842193326Sed } 843193326Sed 844193326Sed // Iterators 845218893Sdim child_range children() { 846218893Sdim return child_range(&Op, Op ? &Op+1 : &Op); 847218893Sdim } 848193326Sed}; 849193326Sed 850263509Sdim/// \brief A default argument (C++ [dcl.fct.default]). 851263509Sdim/// 852263509Sdim/// This wraps up a function call argument that was created from the 853263509Sdim/// corresponding parameter's default argument, when the call did not 854263509Sdim/// explicitly supply arguments for all of the parameters. 855193326Sedclass CXXDefaultArgExpr : public Expr { 856201361Srdivacky /// \brief The parameter whose default is being used. 857201361Srdivacky /// 858235633Sdim /// When the bit is set, the subexpression is stored after the 859201361Srdivacky /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 860201361Srdivacky /// actual default expression is the subexpression. 861201361Srdivacky llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 862198092Srdivacky 863201361Srdivacky /// \brief The location where the default argument expression was used. 864201361Srdivacky SourceLocation Loc; 865235633Sdim 866201361Srdivacky CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 867235633Sdim : Expr(SC, 868201361Srdivacky param->hasUnparsedDefaultArg() 869201361Srdivacky ? param->getType().getNonReferenceType() 870201361Srdivacky : param->getDefaultArg()->getType(), 871218893Sdim param->getDefaultArg()->getValueKind(), 872224145Sdim param->getDefaultArg()->getObjectKind(), false, false, false, false), 873201361Srdivacky Param(param, false), Loc(Loc) { } 874198092Srdivacky 875235633Sdim CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 876201361Srdivacky Expr *SubExpr) 877218893Sdim : Expr(SC, SubExpr->getType(), 878218893Sdim SubExpr->getValueKind(), SubExpr->getObjectKind(), 879235633Sdim false, false, false, false), 880218893Sdim Param(param, true), Loc(Loc) { 881201361Srdivacky *reinterpret_cast<Expr **>(this + 1) = SubExpr; 882201361Srdivacky } 883235633Sdim 884193326Sedpublic: 885208600Srdivacky CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} 886208600Srdivacky 887263509Sdim // \p Param is the parameter whose default argument is used by this 888193326Sed // expression. 889263509Sdim static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc, 890201361Srdivacky ParmVarDecl *Param) { 891201361Srdivacky return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 892198092Srdivacky } 893193326Sed 894263509Sdim // \p Param is the parameter whose default argument is used by this 895263509Sdim // expression, and \p SubExpr is the expression that will actually be used. 896263509Sdim static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc, 897263509Sdim ParmVarDecl *Param, Expr *SubExpr); 898235633Sdim 899193326Sed // Retrieve the parameter that the argument was created from. 900201361Srdivacky const ParmVarDecl *getParam() const { return Param.getPointer(); } 901201361Srdivacky ParmVarDecl *getParam() { return Param.getPointer(); } 902235633Sdim 903193326Sed // Retrieve the actual argument to the function call. 904235633Sdim const Expr *getExpr() const { 905201361Srdivacky if (Param.getInt()) 906201361Srdivacky return *reinterpret_cast<Expr const * const*> (this + 1); 907235633Sdim return getParam()->getDefaultArg(); 908201361Srdivacky } 909235633Sdim Expr *getExpr() { 910201361Srdivacky if (Param.getInt()) 911201361Srdivacky return *reinterpret_cast<Expr **> (this + 1); 912235633Sdim return getParam()->getDefaultArg(); 913201361Srdivacky } 914193326Sed 915235633Sdim /// \brief Retrieve the location where this default argument was actually 916201361Srdivacky /// used. 917201361Srdivacky SourceLocation getUsedLocation() const { return Loc; } 918235633Sdim 919263509Sdim /// Default argument expressions have no representation in the 920263509Sdim /// source, so they have an empty source range. 921252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } 922252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } 923193326Sed 924252723Sdim SourceLocation getExprLoc() const LLVM_READONLY { return Loc; } 925252723Sdim 926193326Sed static bool classof(const Stmt *T) { 927193326Sed return T->getStmtClass() == CXXDefaultArgExprClass; 928193326Sed } 929193326Sed 930193326Sed // Iterators 931218893Sdim child_range children() { return child_range(); } 932210299Sed 933212904Sdim friend class ASTStmtReader; 934212904Sdim friend class ASTStmtWriter; 935193326Sed}; 936193326Sed 937263509Sdim/// \brief A use of a default initializer in a constructor or in aggregate 938263509Sdim/// initialization. 939263509Sdim/// 940263509Sdim/// This wraps a use of a C++ default initializer (technically, 941252723Sdim/// a brace-or-equal-initializer for a non-static data member) when it 942252723Sdim/// is implicitly used in a mem-initializer-list in a constructor 943252723Sdim/// (C++11 [class.base.init]p8) or in aggregate initialization 944252723Sdim/// (C++1y [dcl.init.aggr]p7). 945252723Sdimclass CXXDefaultInitExpr : public Expr { 946252723Sdim /// \brief The field whose default is being used. 947252723Sdim FieldDecl *Field; 948252723Sdim 949252723Sdim /// \brief The location where the default initializer expression was used. 950252723Sdim SourceLocation Loc; 951252723Sdim 952263509Sdim CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field, 953252723Sdim QualType T); 954252723Sdim 955252723Sdim CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {} 956252723Sdim 957252723Sdimpublic: 958263509Sdim /// \p Field is the non-static data member whose default initializer is used 959263509Sdim /// by this expression. 960263509Sdim static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc, 961252723Sdim FieldDecl *Field) { 962252723Sdim return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType()); 963252723Sdim } 964252723Sdim 965263509Sdim /// \brief Get the field whose initializer will be used. 966252723Sdim FieldDecl *getField() { return Field; } 967252723Sdim const FieldDecl *getField() const { return Field; } 968252723Sdim 969263509Sdim /// \brief Get the initialization expression that will be used. 970252723Sdim const Expr *getExpr() const { return Field->getInClassInitializer(); } 971252723Sdim Expr *getExpr() { return Field->getInClassInitializer(); } 972252723Sdim 973252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 974252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 975252723Sdim 976252723Sdim static bool classof(const Stmt *T) { 977252723Sdim return T->getStmtClass() == CXXDefaultInitExprClass; 978252723Sdim } 979252723Sdim 980252723Sdim // Iterators 981252723Sdim child_range children() { return child_range(); } 982252723Sdim 983252723Sdim friend class ASTReader; 984252723Sdim friend class ASTStmtReader; 985252723Sdim}; 986252723Sdim 987263509Sdim/// \brief Represents a C++ temporary. 988193326Sedclass CXXTemporary { 989263509Sdim /// \brief The destructor that needs to be called. 990193326Sed const CXXDestructorDecl *Destructor; 991198092Srdivacky 992263509Sdim explicit CXXTemporary(const CXXDestructorDecl *destructor) 993193326Sed : Destructor(destructor) { } 994193326Sed 995193326Sedpublic: 996263509Sdim static CXXTemporary *Create(const ASTContext &C, 997193326Sed const CXXDestructorDecl *Destructor); 998198092Srdivacky 999193326Sed const CXXDestructorDecl *getDestructor() const { return Destructor; } 1000235633Sdim void setDestructor(const CXXDestructorDecl *Dtor) { 1001235633Sdim Destructor = Dtor; 1002235633Sdim } 1003193326Sed}; 1004193326Sed 1005208600Srdivacky/// \brief Represents binding an expression to a temporary. 1006208600Srdivacky/// 1007208600Srdivacky/// This ensures the destructor is called for the temporary. It should only be 1008208600Srdivacky/// needed for non-POD, non-trivially destructable class types. For example: 1009208600Srdivacky/// 1010208600Srdivacky/// \code 1011208600Srdivacky/// struct S { 1012208600Srdivacky/// S() { } // User defined constructor makes S non-POD. 1013208600Srdivacky/// ~S() { } // User defined destructor makes it non-trivial. 1014208600Srdivacky/// }; 1015208600Srdivacky/// void test() { 1016208600Srdivacky/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 1017208600Srdivacky/// } 1018208600Srdivacky/// \endcode 1019193326Sedclass CXXBindTemporaryExpr : public Expr { 1020193326Sed CXXTemporary *Temp; 1021198092Srdivacky 1022193326Sed Stmt *SubExpr; 1023193326Sed 1024218893Sdim CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 1025218893Sdim : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 1026235633Sdim VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 1027218893Sdim SubExpr->isValueDependent(), 1028224145Sdim SubExpr->isInstantiationDependent(), 1029218893Sdim SubExpr->containsUnexpandedParameterPack()), 1030218893Sdim Temp(temp), SubExpr(SubExpr) { } 1031193326Sed 1032193326Sedpublic: 1033208600Srdivacky CXXBindTemporaryExpr(EmptyShell Empty) 1034208600Srdivacky : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 1035235633Sdim 1036263509Sdim static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp, 1037193326Sed Expr* SubExpr); 1038198092Srdivacky 1039193326Sed CXXTemporary *getTemporary() { return Temp; } 1040193326Sed const CXXTemporary *getTemporary() const { return Temp; } 1041208600Srdivacky void setTemporary(CXXTemporary *T) { Temp = T; } 1042193326Sed 1043193326Sed const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1044193326Sed Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1045193326Sed void setSubExpr(Expr *E) { SubExpr = E; } 1046193326Sed 1047252723Sdim SourceLocation getLocStart() const LLVM_READONLY { 1048252723Sdim return SubExpr->getLocStart(); 1049198092Srdivacky } 1050252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 1051193326Sed 1052193326Sed // Implement isa/cast/dyncast/etc. 1053193326Sed static bool classof(const Stmt *T) { 1054193326Sed return T->getStmtClass() == CXXBindTemporaryExprClass; 1055193326Sed } 1056193326Sed 1057193326Sed // Iterators 1058218893Sdim child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 1059193326Sed}; 1060193326Sed 1061245431Sdim/// \brief Represents a call to a C++ constructor. 1062193326Sedclass CXXConstructExpr : public Expr { 1063207619Srdivackypublic: 1064207619Srdivacky enum ConstructionKind { 1065207619Srdivacky CK_Complete, 1066207619Srdivacky CK_NonVirtualBase, 1067221345Sdim CK_VirtualBase, 1068221345Sdim CK_Delegating 1069207619Srdivacky }; 1070235633Sdim 1071207619Srdivackyprivate: 1072193326Sed CXXConstructorDecl *Constructor; 1073193326Sed 1074201361Srdivacky SourceLocation Loc; 1075263509Sdim SourceRange ParenOrBraceRange; 1076226890Sdim unsigned NumArgs : 16; 1077201361Srdivacky bool Elidable : 1; 1078226890Sdim bool HadMultipleCandidates : 1; 1079235633Sdim bool ListInitialization : 1; 1080201361Srdivacky bool ZeroInitialization : 1; 1081207619Srdivacky unsigned ConstructKind : 2; 1082193326Sed Stmt **Args; 1083193326Sed 1084193326Sedprotected: 1085263509Sdim CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T, 1086201361Srdivacky SourceLocation Loc, 1087193326Sed CXXConstructorDecl *d, bool elidable, 1088245431Sdim ArrayRef<Expr *> Args, 1089226890Sdim bool HadMultipleCandidates, 1090235633Sdim bool ListInitialization, 1091235633Sdim bool ZeroInitialization, 1092235633Sdim ConstructionKind ConstructKind, 1093263509Sdim SourceRange ParenOrBraceRange); 1094193326Sed 1095210299Sed /// \brief Construct an empty C++ construction expression. 1096210299Sed CXXConstructExpr(StmtClass SC, EmptyShell Empty) 1097235633Sdim : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 1098235633Sdim HadMultipleCandidates(false), ListInitialization(false), 1099235633Sdim ZeroInitialization(false), ConstructKind(0), Args(0) 1100235633Sdim { } 1101210299Sed 1102193326Sedpublic: 1103210299Sed /// \brief Construct an empty C++ construction expression. 1104210299Sed explicit CXXConstructExpr(EmptyShell Empty) 1105210299Sed : Expr(CXXConstructExprClass, Empty), Constructor(0), 1106235633Sdim NumArgs(0), Elidable(false), HadMultipleCandidates(false), 1107235633Sdim ListInitialization(false), ZeroInitialization(false), 1108235633Sdim ConstructKind(0), Args(0) 1109235633Sdim { } 1110210299Sed 1111263509Sdim static CXXConstructExpr *Create(const ASTContext &C, QualType T, 1112201361Srdivacky SourceLocation Loc, 1113198092Srdivacky CXXConstructorDecl *D, bool Elidable, 1114245431Sdim ArrayRef<Expr *> Args, 1115226890Sdim bool HadMultipleCandidates, 1116235633Sdim bool ListInitialization, 1117235633Sdim bool ZeroInitialization, 1118235633Sdim ConstructionKind ConstructKind, 1119263509Sdim SourceRange ParenOrBraceRange); 1120198092Srdivacky 1121198092Srdivacky CXXConstructorDecl* getConstructor() const { return Constructor; } 1122198092Srdivacky void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 1123235633Sdim 1124201361Srdivacky SourceLocation getLocation() const { return Loc; } 1125201361Srdivacky void setLocation(SourceLocation Loc) { this->Loc = Loc; } 1126235633Sdim 1127193326Sed /// \brief Whether this construction is elidable. 1128193326Sed bool isElidable() const { return Elidable; } 1129198092Srdivacky void setElidable(bool E) { Elidable = E; } 1130226890Sdim 1131226890Sdim /// \brief Whether the referred constructor was resolved from 1132226890Sdim /// an overloaded set having size greater than 1. 1133226890Sdim bool hadMultipleCandidates() const { return HadMultipleCandidates; } 1134226890Sdim void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 1135226890Sdim 1136235633Sdim /// \brief Whether this constructor call was written as list-initialization. 1137235633Sdim bool isListInitialization() const { return ListInitialization; } 1138235633Sdim void setListInitialization(bool V) { ListInitialization = V; } 1139235633Sdim 1140201361Srdivacky /// \brief Whether this construction first requires 1141201361Srdivacky /// zero-initialization before the initializer is called. 1142201361Srdivacky bool requiresZeroInitialization() const { return ZeroInitialization; } 1143201361Srdivacky void setRequiresZeroInitialization(bool ZeroInit) { 1144201361Srdivacky ZeroInitialization = ZeroInit; 1145201361Srdivacky } 1146235633Sdim 1147263509Sdim /// \brief Determine whether this constructor is actually constructing 1148203955Srdivacky /// a base class (rather than a complete object). 1149207619Srdivacky ConstructionKind getConstructionKind() const { 1150207619Srdivacky return (ConstructionKind)ConstructKind; 1151207619Srdivacky } 1152235633Sdim void setConstructionKind(ConstructionKind CK) { 1153207619Srdivacky ConstructKind = CK; 1154207619Srdivacky } 1155235633Sdim 1156193326Sed typedef ExprIterator arg_iterator; 1157193326Sed typedef ConstExprIterator const_arg_iterator; 1158198092Srdivacky 1159193326Sed arg_iterator arg_begin() { return Args; } 1160193326Sed arg_iterator arg_end() { return Args + NumArgs; } 1161193326Sed const_arg_iterator arg_begin() const { return Args; } 1162193326Sed const_arg_iterator arg_end() const { return Args + NumArgs; } 1163193326Sed 1164200583Srdivacky Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 1165193326Sed unsigned getNumArgs() const { return NumArgs; } 1166193326Sed 1167263509Sdim /// \brief Return the specified argument. 1168198092Srdivacky Expr *getArg(unsigned Arg) { 1169198092Srdivacky assert(Arg < NumArgs && "Arg access out of range!"); 1170198092Srdivacky return cast<Expr>(Args[Arg]); 1171198092Srdivacky } 1172198092Srdivacky const Expr *getArg(unsigned Arg) const { 1173198092Srdivacky assert(Arg < NumArgs && "Arg access out of range!"); 1174198092Srdivacky return cast<Expr>(Args[Arg]); 1175198092Srdivacky } 1176193326Sed 1177263509Sdim /// \brief Set the specified argument. 1178198092Srdivacky void setArg(unsigned Arg, Expr *ArgExpr) { 1179198092Srdivacky assert(Arg < NumArgs && "Arg access out of range!"); 1180198092Srdivacky Args[Arg] = ArgExpr; 1181198092Srdivacky } 1182198092Srdivacky 1183252723Sdim SourceLocation getLocStart() const LLVM_READONLY; 1184252723Sdim SourceLocation getLocEnd() const LLVM_READONLY; 1185263509Sdim SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; } 1186263509Sdim void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; } 1187198092Srdivacky 1188198092Srdivacky static bool classof(const Stmt *T) { 1189193326Sed return T->getStmtClass() == CXXConstructExprClass || 1190193326Sed T->getStmtClass() == CXXTemporaryObjectExprClass; 1191193326Sed } 1192198092Srdivacky 1193193326Sed // Iterators 1194218893Sdim child_range children() { 1195218893Sdim return child_range(&Args[0], &Args[0]+NumArgs); 1196218893Sdim } 1197210299Sed 1198212904Sdim friend class ASTStmtReader; 1199193326Sed}; 1200193326Sed 1201245431Sdim/// \brief Represents an explicit C++ type conversion that uses "functional" 1202245431Sdim/// notation (C++ [expr.type.conv]). 1203245431Sdim/// 1204245431Sdim/// Example: 1205263509Sdim/// \code 1206245431Sdim/// x = int(0.5); 1207263509Sdim/// \endcode 1208193326Sedclass CXXFunctionalCastExpr : public ExplicitCastExpr { 1209263509Sdim SourceLocation LParenLoc; 1210193326Sed SourceLocation RParenLoc; 1211212904Sdim 1212218893Sdim CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 1213218893Sdim TypeSourceInfo *writtenTy, 1214263509Sdim CastKind kind, Expr *castExpr, unsigned pathSize, 1215263509Sdim SourceLocation lParenLoc, SourceLocation rParenLoc) 1216218893Sdim : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 1217218893Sdim castExpr, pathSize, writtenTy), 1218263509Sdim LParenLoc(lParenLoc), RParenLoc(rParenLoc) {} 1219193326Sed 1220212904Sdim explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 1221212904Sdim : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 1222202879Srdivacky 1223212904Sdimpublic: 1224263509Sdim static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T, 1225218893Sdim ExprValueKind VK, 1226212904Sdim TypeSourceInfo *Written, 1227212904Sdim CastKind Kind, Expr *Op, 1228212904Sdim const CXXCastPath *Path, 1229263509Sdim SourceLocation LPLoc, 1230212904Sdim SourceLocation RPLoc); 1231263509Sdim static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context, 1232212904Sdim unsigned PathSize); 1233212904Sdim 1234263509Sdim SourceLocation getLParenLoc() const { return LParenLoc; } 1235263509Sdim void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1236193326Sed SourceLocation getRParenLoc() const { return RParenLoc; } 1237202879Srdivacky void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1238198092Srdivacky 1239263509Sdim SourceLocation getLocStart() const LLVM_READONLY; 1240263509Sdim SourceLocation getLocEnd() const LLVM_READONLY; 1241252723Sdim 1242198092Srdivacky static bool classof(const Stmt *T) { 1243198092Srdivacky return T->getStmtClass() == CXXFunctionalCastExprClass; 1244193326Sed } 1245193326Sed}; 1246193326Sed 1247193326Sed/// @brief Represents a C++ functional cast expression that builds a 1248193326Sed/// temporary object. 1249193326Sed/// 1250198092Srdivacky/// This expression type represents a C++ "functional" cast 1251193326Sed/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 1252235633Sdim/// constructor to build a temporary object. With N == 1 arguments the 1253210299Sed/// functional cast expression will be represented by CXXFunctionalCastExpr. 1254193326Sed/// Example: 1255263509Sdim/// \code 1256193326Sed/// struct X { X(int, float); } 1257193326Sed/// 1258193326Sed/// X create_X() { 1259193326Sed/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 1260193326Sed/// }; 1261263509Sdim/// \endcode 1262193326Sedclass CXXTemporaryObjectExpr : public CXXConstructExpr { 1263218893Sdim TypeSourceInfo *Type; 1264193326Sed 1265193326Sedpublic: 1266263509Sdim CXXTemporaryObjectExpr(const ASTContext &C, CXXConstructorDecl *Cons, 1267218893Sdim TypeSourceInfo *Type, 1268245431Sdim ArrayRef<Expr *> Args, 1269263509Sdim SourceRange ParenOrBraceRange, 1270226890Sdim bool HadMultipleCandidates, 1271252723Sdim bool ListInitialization, 1272252723Sdim bool ZeroInitialization); 1273210299Sed explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1274218893Sdim : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1275193326Sed 1276218893Sdim TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1277193326Sed 1278252723Sdim SourceLocation getLocStart() const LLVM_READONLY; 1279252723Sdim SourceLocation getLocEnd() const LLVM_READONLY; 1280235633Sdim 1281198092Srdivacky static bool classof(const Stmt *T) { 1282193326Sed return T->getStmtClass() == CXXTemporaryObjectExprClass; 1283193326Sed } 1284210299Sed 1285212904Sdim friend class ASTStmtReader; 1286193326Sed}; 1287193326Sed 1288235633Sdim/// \brief A C++ lambda expression, which produces a function object 1289235633Sdim/// (of unspecified type) that can be invoked later. 1290235633Sdim/// 1291235633Sdim/// Example: 1292235633Sdim/// \code 1293235633Sdim/// void low_pass_filter(std::vector<double> &values, double cutoff) { 1294235633Sdim/// values.erase(std::remove_if(values.begin(), values.end(), 1295252723Sdim/// [=](double value) { return value > cutoff; }); 1296235633Sdim/// } 1297235633Sdim/// \endcode 1298235633Sdim/// 1299263509Sdim/// C++11 lambda expressions can capture local variables, either by copying 1300235633Sdim/// the values of those local variables at the time the function 1301235633Sdim/// object is constructed (not when it is called!) or by holding a 1302235633Sdim/// reference to the local variable. These captures can occur either 1303235633Sdim/// implicitly or can be written explicitly between the square 1304235633Sdim/// brackets ([...]) that start the lambda expression. 1305263509Sdim/// 1306263509Sdim/// C++1y introduces a new form of "capture" called an init-capture that 1307263509Sdim/// includes an initializing expression (rather than capturing a variable), 1308263509Sdim/// and which can never occur implicitly. 1309235633Sdimclass LambdaExpr : public Expr { 1310235633Sdim enum { 1311235633Sdim /// \brief Flag used by the Capture class to indicate that the given 1312235633Sdim /// capture was implicit. 1313235633Sdim Capture_Implicit = 0x01, 1314235633Sdim 1315263509Sdim /// \brief Flag used by the Capture class to indicate that the 1316235633Sdim /// given capture was by-copy. 1317263509Sdim /// 1318263509Sdim /// This includes the case of a non-reference init-capture. 1319235633Sdim Capture_ByCopy = 0x02 1320235633Sdim }; 1321235633Sdim 1322235633Sdim /// \brief The source range that covers the lambda introducer ([...]). 1323235633Sdim SourceRange IntroducerRange; 1324235633Sdim 1325263509Sdim /// \brief The source location of this lambda's capture-default ('=' or '&'). 1326263509Sdim SourceLocation CaptureDefaultLoc; 1327263509Sdim 1328235633Sdim /// \brief The number of captures. 1329235633Sdim unsigned NumCaptures : 16; 1330235633Sdim 1331235633Sdim /// \brief The default capture kind, which is a value of type 1332235633Sdim /// LambdaCaptureDefault. 1333235633Sdim unsigned CaptureDefault : 2; 1334235633Sdim 1335235633Sdim /// \brief Whether this lambda had an explicit parameter list vs. an 1336235633Sdim /// implicit (and empty) parameter list. 1337235633Sdim unsigned ExplicitParams : 1; 1338235633Sdim 1339235633Sdim /// \brief Whether this lambda had the result type explicitly specified. 1340235633Sdim unsigned ExplicitResultType : 1; 1341235633Sdim 1342235633Sdim /// \brief Whether there are any array index variables stored at the end of 1343235633Sdim /// this lambda expression. 1344235633Sdim unsigned HasArrayIndexVars : 1; 1345235633Sdim 1346235633Sdim /// \brief The location of the closing brace ('}') that completes 1347235633Sdim /// the lambda. 1348235633Sdim /// 1349235633Sdim /// The location of the brace is also available by looking up the 1350235633Sdim /// function call operator in the lambda class. However, it is 1351235633Sdim /// stored here to improve the performance of getSourceRange(), and 1352235633Sdim /// to avoid having to deserialize the function call operator from a 1353235633Sdim /// module file just to determine the source range. 1354235633Sdim SourceLocation ClosingBrace; 1355235633Sdim 1356235633Sdim // Note: The capture initializers are stored directly after the lambda 1357235633Sdim // expression, along with the index variables used to initialize by-copy 1358235633Sdim // array captures. 1359235633Sdim 1360235633Sdimpublic: 1361263509Sdim /// \brief Describes the capture of a variable or of \c this, or of a 1362263509Sdim /// C++1y init-capture. 1363235633Sdim class Capture { 1364263509Sdim llvm::PointerIntPair<Decl *, 2> DeclAndBits; 1365235633Sdim SourceLocation Loc; 1366235633Sdim SourceLocation EllipsisLoc; 1367235633Sdim 1368235633Sdim friend class ASTStmtReader; 1369235633Sdim friend class ASTStmtWriter; 1370235633Sdim 1371235633Sdim public: 1372263509Sdim /// \brief Create a new capture of a variable or of \c this. 1373235633Sdim /// 1374235633Sdim /// \param Loc The source location associated with this capture. 1375235633Sdim /// 1376263509Sdim /// \param Kind The kind of capture (this, byref, bycopy), which must 1377263509Sdim /// not be init-capture. 1378235633Sdim /// 1379235633Sdim /// \param Implicit Whether the capture was implicit or explicit. 1380235633Sdim /// 1381263509Sdim /// \param Var The local variable being captured, or null if capturing 1382263509Sdim /// \c this. 1383235633Sdim /// 1384235633Sdim /// \param EllipsisLoc The location of the ellipsis (...) for a 1385235633Sdim /// capture that is a pack expansion, or an invalid source 1386235633Sdim /// location to indicate that this is not a pack expansion. 1387235633Sdim Capture(SourceLocation Loc, bool Implicit, 1388235633Sdim LambdaCaptureKind Kind, VarDecl *Var = 0, 1389235633Sdim SourceLocation EllipsisLoc = SourceLocation()); 1390235633Sdim 1391235633Sdim /// \brief Determine the kind of capture. 1392235633Sdim LambdaCaptureKind getCaptureKind() const; 1393235633Sdim 1394263509Sdim /// \brief Determine whether this capture handles the C++ \c this 1395235633Sdim /// pointer. 1396263509Sdim bool capturesThis() const { return DeclAndBits.getPointer() == 0; } 1397235633Sdim 1398235633Sdim /// \brief Determine whether this capture handles a variable. 1399263509Sdim bool capturesVariable() const { 1400263509Sdim return dyn_cast_or_null<VarDecl>(DeclAndBits.getPointer()); 1401263509Sdim } 1402235633Sdim 1403263509Sdim /// \brief Determine whether this is an init-capture. 1404263509Sdim bool isInitCapture() const { 1405263509Sdim return capturesVariable() && getCapturedVar()->isInitCapture(); 1406263509Sdim } 1407263509Sdim 1408235633Sdim /// \brief Retrieve the declaration of the local variable being 1409235633Sdim /// captured. 1410235633Sdim /// 1411263509Sdim /// This operation is only valid if this capture is a variable capture 1412263509Sdim /// (other than a capture of \c this). 1413263509Sdim VarDecl *getCapturedVar() const { 1414263509Sdim assert(capturesVariable() && "No variable available for 'this' capture"); 1415263509Sdim return cast<VarDecl>(DeclAndBits.getPointer()); 1416235633Sdim } 1417235633Sdim 1418235633Sdim /// \brief Determine whether this was an implicit capture (not 1419235633Sdim /// written between the square brackets introducing the lambda). 1420263509Sdim bool isImplicit() const { return DeclAndBits.getInt() & Capture_Implicit; } 1421235633Sdim 1422263509Sdim /// \brief Determine whether this was an explicit capture (written 1423263509Sdim /// between the square brackets introducing the lambda). 1424235633Sdim bool isExplicit() const { return !isImplicit(); } 1425235633Sdim 1426235633Sdim /// \brief Retrieve the source location of the capture. 1427235633Sdim /// 1428235633Sdim /// For an explicit capture, this returns the location of the 1429235633Sdim /// explicit capture in the source. For an implicit capture, this 1430263509Sdim /// returns the location at which the variable or \c this was first 1431235633Sdim /// used. 1432235633Sdim SourceLocation getLocation() const { return Loc; } 1433235633Sdim 1434235633Sdim /// \brief Determine whether this capture is a pack expansion, 1435235633Sdim /// which captures a function parameter pack. 1436235633Sdim bool isPackExpansion() const { return EllipsisLoc.isValid(); } 1437235633Sdim 1438235633Sdim /// \brief Retrieve the location of the ellipsis for a capture 1439235633Sdim /// that is a pack expansion. 1440235633Sdim SourceLocation getEllipsisLoc() const { 1441235633Sdim assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 1442235633Sdim return EllipsisLoc; 1443235633Sdim } 1444235633Sdim }; 1445235633Sdim 1446235633Sdimprivate: 1447235633Sdim /// \brief Construct a lambda expression. 1448235633Sdim LambdaExpr(QualType T, SourceRange IntroducerRange, 1449235633Sdim LambdaCaptureDefault CaptureDefault, 1450263509Sdim SourceLocation CaptureDefaultLoc, 1451235633Sdim ArrayRef<Capture> Captures, 1452235633Sdim bool ExplicitParams, 1453235633Sdim bool ExplicitResultType, 1454235633Sdim ArrayRef<Expr *> CaptureInits, 1455235633Sdim ArrayRef<VarDecl *> ArrayIndexVars, 1456235633Sdim ArrayRef<unsigned> ArrayIndexStarts, 1457245431Sdim SourceLocation ClosingBrace, 1458245431Sdim bool ContainsUnexpandedParameterPack); 1459235633Sdim 1460235633Sdim /// \brief Construct an empty lambda expression. 1461235633Sdim LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars) 1462235633Sdim : Expr(LambdaExprClass, Empty), 1463235633Sdim NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false), 1464235633Sdim ExplicitResultType(false), HasArrayIndexVars(true) { 1465235633Sdim getStoredStmts()[NumCaptures] = 0; 1466235633Sdim } 1467235633Sdim 1468235633Sdim Stmt **getStoredStmts() const { 1469235633Sdim return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1); 1470235633Sdim } 1471235633Sdim 1472235633Sdim /// \brief Retrieve the mapping from captures to the first array index 1473235633Sdim /// variable. 1474235633Sdim unsigned *getArrayIndexStarts() const { 1475235633Sdim return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1); 1476235633Sdim } 1477235633Sdim 1478235633Sdim /// \brief Retrieve the complete set of array-index variables. 1479235633Sdim VarDecl **getArrayIndexVars() const { 1480245431Sdim unsigned ArrayIndexSize = 1481245431Sdim llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1), 1482245431Sdim llvm::alignOf<VarDecl*>()); 1483235633Sdim return reinterpret_cast<VarDecl **>( 1484245431Sdim reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize); 1485235633Sdim } 1486235633Sdim 1487235633Sdimpublic: 1488235633Sdim /// \brief Construct a new lambda expression. 1489263509Sdim static LambdaExpr *Create(const ASTContext &C, 1490235633Sdim CXXRecordDecl *Class, 1491235633Sdim SourceRange IntroducerRange, 1492235633Sdim LambdaCaptureDefault CaptureDefault, 1493263509Sdim SourceLocation CaptureDefaultLoc, 1494235633Sdim ArrayRef<Capture> Captures, 1495235633Sdim bool ExplicitParams, 1496235633Sdim bool ExplicitResultType, 1497235633Sdim ArrayRef<Expr *> CaptureInits, 1498235633Sdim ArrayRef<VarDecl *> ArrayIndexVars, 1499235633Sdim ArrayRef<unsigned> ArrayIndexStarts, 1500245431Sdim SourceLocation ClosingBrace, 1501245431Sdim bool ContainsUnexpandedParameterPack); 1502235633Sdim 1503235633Sdim /// \brief Construct a new lambda expression that will be deserialized from 1504235633Sdim /// an external source. 1505263509Sdim static LambdaExpr *CreateDeserialized(const ASTContext &C, 1506263509Sdim unsigned NumCaptures, 1507235633Sdim unsigned NumArrayIndexVars); 1508263509Sdim 1509235633Sdim /// \brief Determine the default capture kind for this lambda. 1510235633Sdim LambdaCaptureDefault getCaptureDefault() const { 1511235633Sdim return static_cast<LambdaCaptureDefault>(CaptureDefault); 1512235633Sdim } 1513235633Sdim 1514263509Sdim /// \brief Retrieve the location of this lambda's capture-default, if any. 1515263509Sdim SourceLocation getCaptureDefaultLoc() const { 1516263509Sdim return CaptureDefaultLoc; 1517263509Sdim } 1518263509Sdim 1519235633Sdim /// \brief An iterator that walks over the captures of the lambda, 1520235633Sdim /// both implicit and explicit. 1521235633Sdim typedef const Capture *capture_iterator; 1522235633Sdim 1523235633Sdim /// \brief Retrieve an iterator pointing to the first lambda capture. 1524235633Sdim capture_iterator capture_begin() const; 1525235633Sdim 1526235633Sdim /// \brief Retrieve an iterator pointing past the end of the 1527235633Sdim /// sequence of lambda captures. 1528235633Sdim capture_iterator capture_end() const; 1529235633Sdim 1530235633Sdim /// \brief Determine the number of captures in this lambda. 1531235633Sdim unsigned capture_size() const { return NumCaptures; } 1532235633Sdim 1533235633Sdim /// \brief Retrieve an iterator pointing to the first explicit 1534235633Sdim /// lambda capture. 1535235633Sdim capture_iterator explicit_capture_begin() const; 1536235633Sdim 1537235633Sdim /// \brief Retrieve an iterator pointing past the end of the sequence of 1538235633Sdim /// explicit lambda captures. 1539235633Sdim capture_iterator explicit_capture_end() const; 1540235633Sdim 1541235633Sdim /// \brief Retrieve an iterator pointing to the first implicit 1542235633Sdim /// lambda capture. 1543235633Sdim capture_iterator implicit_capture_begin() const; 1544235633Sdim 1545235633Sdim /// \brief Retrieve an iterator pointing past the end of the sequence of 1546235633Sdim /// implicit lambda captures. 1547235633Sdim capture_iterator implicit_capture_end() const; 1548235633Sdim 1549235633Sdim /// \brief Iterator that walks over the capture initialization 1550235633Sdim /// arguments. 1551235633Sdim typedef Expr **capture_init_iterator; 1552235633Sdim 1553235633Sdim /// \brief Retrieve the first initialization argument for this 1554235633Sdim /// lambda expression (which initializes the first capture field). 1555235633Sdim capture_init_iterator capture_init_begin() const { 1556235633Sdim return reinterpret_cast<Expr **>(getStoredStmts()); 1557235633Sdim } 1558235633Sdim 1559235633Sdim /// \brief Retrieve the iterator pointing one past the last 1560235633Sdim /// initialization argument for this lambda expression. 1561235633Sdim capture_init_iterator capture_init_end() const { 1562235633Sdim return capture_init_begin() + NumCaptures; 1563235633Sdim } 1564235633Sdim 1565235633Sdim /// \brief Retrieve the set of index variables used in the capture 1566235633Sdim /// initializer of an array captured by copy. 1567235633Sdim /// 1568235633Sdim /// \param Iter The iterator that points at the capture initializer for 1569235633Sdim /// which we are extracting the corresponding index variables. 1570235633Sdim ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const; 1571235633Sdim 1572235633Sdim /// \brief Retrieve the source range covering the lambda introducer, 1573235633Sdim /// which contains the explicit capture list surrounded by square 1574235633Sdim /// brackets ([...]). 1575235633Sdim SourceRange getIntroducerRange() const { return IntroducerRange; } 1576235633Sdim 1577263509Sdim /// \brief Retrieve the class that corresponds to the lambda. 1578263509Sdim /// 1579263509Sdim /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the 1580263509Sdim /// captures in its fields and provides the various operations permitted 1581263509Sdim /// on a lambda (copying, calling). 1582235633Sdim CXXRecordDecl *getLambdaClass() const; 1583235633Sdim 1584235633Sdim /// \brief Retrieve the function call operator associated with this 1585235633Sdim /// lambda expression. 1586235633Sdim CXXMethodDecl *getCallOperator() const; 1587235633Sdim 1588263509Sdim /// \brief If this is a generic lambda expression, retrieve the template 1589263509Sdim /// parameter list associated with it, or else return null. 1590263509Sdim TemplateParameterList *getTemplateParameterList() const; 1591263509Sdim 1592263509Sdim /// \brief Whether this is a generic lambda. 1593263509Sdim bool isGenericLambda() const { return getTemplateParameterList(); } 1594263509Sdim 1595235633Sdim /// \brief Retrieve the body of the lambda. 1596235633Sdim CompoundStmt *getBody() const; 1597235633Sdim 1598235633Sdim /// \brief Determine whether the lambda is mutable, meaning that any 1599235633Sdim /// captures values can be modified. 1600235633Sdim bool isMutable() const; 1601235633Sdim 1602235633Sdim /// \brief Determine whether this lambda has an explicit parameter 1603235633Sdim /// list vs. an implicit (empty) parameter list. 1604235633Sdim bool hasExplicitParameters() const { return ExplicitParams; } 1605235633Sdim 1606235633Sdim /// \brief Whether this lambda had its result type explicitly specified. 1607235633Sdim bool hasExplicitResultType() const { return ExplicitResultType; } 1608235633Sdim 1609235633Sdim static bool classof(const Stmt *T) { 1610235633Sdim return T->getStmtClass() == LambdaExprClass; 1611235633Sdim } 1612235633Sdim 1613252723Sdim SourceLocation getLocStart() const LLVM_READONLY { 1614252723Sdim return IntroducerRange.getBegin(); 1615235633Sdim } 1616252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; } 1617235633Sdim 1618235633Sdim child_range children() { 1619235633Sdim return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); 1620235633Sdim } 1621235633Sdim 1622235633Sdim friend class ASTStmtReader; 1623235633Sdim friend class ASTStmtWriter; 1624235633Sdim}; 1625235633Sdim 1626263509Sdim/// An expression "T()" which creates a value-initialized rvalue of type 1627263509Sdim/// T, which is a non-class type. See (C++98 [5.2.3p2]). 1628210299Sedclass CXXScalarValueInitExpr : public Expr { 1629193326Sed SourceLocation RParenLoc; 1630218893Sdim TypeSourceInfo *TypeInfo; 1631193326Sed 1632218893Sdim friend class ASTStmtReader; 1633235633Sdim 1634193326Sedpublic: 1635235633Sdim /// \brief Create an explicitly-written scalar-value initialization 1636218893Sdim /// expression. 1637218893Sdim CXXScalarValueInitExpr(QualType Type, 1638218893Sdim TypeSourceInfo *TypeInfo, 1639218893Sdim SourceLocation rParenLoc ) : 1640218893Sdim Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 1641224145Sdim false, false, Type->isInstantiationDependentType(), false), 1642218893Sdim RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 1643218893Sdim 1644210299Sed explicit CXXScalarValueInitExpr(EmptyShell Shell) 1645210299Sed : Expr(CXXScalarValueInitExprClass, Shell) { } 1646198092Srdivacky 1647218893Sdim TypeSourceInfo *getTypeSourceInfo() const { 1648218893Sdim return TypeInfo; 1649218893Sdim } 1650235633Sdim 1651193326Sed SourceLocation getRParenLoc() const { return RParenLoc; } 1652193326Sed 1653252723Sdim SourceLocation getLocStart() const LLVM_READONLY; 1654252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 1655193326Sed 1656198092Srdivacky static bool classof(const Stmt *T) { 1657210299Sed return T->getStmtClass() == CXXScalarValueInitExprClass; 1658193326Sed } 1659198092Srdivacky 1660193326Sed // Iterators 1661218893Sdim child_range children() { return child_range(); } 1662193326Sed}; 1663193326Sed 1664263509Sdim/// \brief Represents a new-expression for memory allocation and constructor 1665263509Sdim/// calls, e.g: "new CXXNewExpr(foo)". 1666193326Sedclass CXXNewExpr : public Expr { 1667263509Sdim /// Contains an optional array size expression, an optional initialization 1668263509Sdim /// expression, and any number of optional placement arguments, in that order. 1669193326Sed Stmt **SubExprs; 1670245431Sdim /// \brief Points to the allocation function used. 1671193326Sed FunctionDecl *OperatorNew; 1672245431Sdim /// \brief Points to the deallocation function used in case of error. May be 1673245431Sdim /// null. 1674193326Sed FunctionDecl *OperatorDelete; 1675193326Sed 1676218893Sdim /// \brief The allocated type-source information, as written in the source. 1677218893Sdim TypeSourceInfo *AllocatedTypeInfo; 1678235633Sdim 1679235633Sdim /// \brief If the allocated type was expressed as a parenthesized type-id, 1680210299Sed /// the source range covering the parenthesized type-id. 1681210299Sed SourceRange TypeIdParens; 1682235633Sdim 1683245431Sdim /// \brief Range of the entire new expression. 1684245431Sdim SourceRange Range; 1685193326Sed 1686235633Sdim /// \brief Source-range of a paren-delimited initializer. 1687235633Sdim SourceRange DirectInitRange; 1688235633Sdim 1689263509Sdim /// Was the usage ::new, i.e. is the global new to be used? 1690235633Sdim bool GlobalNew : 1; 1691263509Sdim /// Do we allocate an array? If so, the first SubExpr is the size expression. 1692235633Sdim bool Array : 1; 1693263509Sdim /// If this is an array allocation, does the usual deallocation 1694263509Sdim /// function for the allocated type want to know the allocated size? 1695235633Sdim bool UsualArrayDeleteWantsSize : 1; 1696263509Sdim /// The number of placement new arguments. 1697235633Sdim unsigned NumPlacementArgs : 13; 1698263509Sdim /// What kind of initializer do we have? Could be none, parens, or braces. 1699263509Sdim /// In storage, we distinguish between "none, and no initializer expr", and 1700263509Sdim /// "none, but an implicit initializer expr". 1701235633Sdim unsigned StoredInitializationStyle : 2; 1702235633Sdim 1703212904Sdim friend class ASTStmtReader; 1704235633Sdim friend class ASTStmtWriter; 1705193326Sedpublic: 1706235633Sdim enum InitializationStyle { 1707235633Sdim NoInit, ///< New-expression has no initializer as written. 1708235633Sdim CallInit, ///< New-expression has a C++98 paren-delimited initializer. 1709235633Sdim ListInit ///< New-expression has a C++11 list-initializer. 1710235633Sdim }; 1711235633Sdim 1712263509Sdim CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 1713235633Sdim FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, 1714245431Sdim ArrayRef<Expr*> placementArgs, 1715235633Sdim SourceRange typeIdParens, Expr *arraySize, 1716235633Sdim InitializationStyle initializationStyle, Expr *initializer, 1717218893Sdim QualType ty, TypeSourceInfo *AllocatedTypeInfo, 1718245431Sdim SourceRange Range, SourceRange directInitRange); 1719208600Srdivacky explicit CXXNewExpr(EmptyShell Shell) 1720208600Srdivacky : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 1721208600Srdivacky 1722263509Sdim void AllocateArgsArray(const ASTContext &C, bool isArray, 1723263509Sdim unsigned numPlaceArgs, bool hasInitializer); 1724235633Sdim 1725193326Sed QualType getAllocatedType() const { 1726193326Sed assert(getType()->isPointerType()); 1727198092Srdivacky return getType()->getAs<PointerType>()->getPointeeType(); 1728193326Sed } 1729193326Sed 1730218893Sdim TypeSourceInfo *getAllocatedTypeSourceInfo() const { 1731218893Sdim return AllocatedTypeInfo; 1732218893Sdim } 1733221345Sdim 1734221345Sdim /// \brief True if the allocation result needs to be null-checked. 1735263509Sdim /// 1736263509Sdim /// C++11 [expr.new]p13: 1737221345Sdim /// If the allocation function returns null, initialization shall 1738221345Sdim /// not be done, the deallocation function shall not be called, 1739221345Sdim /// and the value of the new-expression shall be null. 1740263509Sdim /// 1741221345Sdim /// An allocation function is not allowed to return null unless it 1742221345Sdim /// has a non-throwing exception-specification. The '03 rule is 1743221345Sdim /// identical except that the definition of a non-throwing 1744221345Sdim /// exception specification is just "is it throw()?". 1745263509Sdim bool shouldNullCheckAllocation(const ASTContext &Ctx) const; 1746235633Sdim 1747193326Sed FunctionDecl *getOperatorNew() const { return OperatorNew; } 1748208600Srdivacky void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 1749193326Sed FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1750208600Srdivacky void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 1751193326Sed 1752193326Sed bool isArray() const { return Array; } 1753193326Sed Expr *getArraySize() { 1754193326Sed return Array ? cast<Expr>(SubExprs[0]) : 0; 1755193326Sed } 1756193326Sed const Expr *getArraySize() const { 1757193326Sed return Array ? cast<Expr>(SubExprs[0]) : 0; 1758193326Sed } 1759193326Sed 1760193326Sed unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1761235633Sdim Expr **getPlacementArgs() { 1762235633Sdim return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer()); 1763218893Sdim } 1764235633Sdim 1765193326Sed Expr *getPlacementArg(unsigned i) { 1766193326Sed assert(i < NumPlacementArgs && "Index out of range"); 1767235633Sdim return getPlacementArgs()[i]; 1768193326Sed } 1769193326Sed const Expr *getPlacementArg(unsigned i) const { 1770193326Sed assert(i < NumPlacementArgs && "Index out of range"); 1771235633Sdim return const_cast<CXXNewExpr*>(this)->getPlacementArg(i); 1772193326Sed } 1773193326Sed 1774210299Sed bool isParenTypeId() const { return TypeIdParens.isValid(); } 1775210299Sed SourceRange getTypeIdParens() const { return TypeIdParens; } 1776210299Sed 1777193326Sed bool isGlobalNew() const { return GlobalNew; } 1778193326Sed 1779235633Sdim /// \brief Whether this new-expression has any initializer at all. 1780235633Sdim bool hasInitializer() const { return StoredInitializationStyle > 0; } 1781235633Sdim 1782235633Sdim /// \brief The kind of initializer this new-expression has. 1783235633Sdim InitializationStyle getInitializationStyle() const { 1784235633Sdim if (StoredInitializationStyle == 0) 1785235633Sdim return NoInit; 1786235633Sdim return static_cast<InitializationStyle>(StoredInitializationStyle-1); 1787235633Sdim } 1788235633Sdim 1789235633Sdim /// \brief The initializer of this new-expression. 1790235633Sdim Expr *getInitializer() { 1791235633Sdim return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 1792235633Sdim } 1793235633Sdim const Expr *getInitializer() const { 1794235633Sdim return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 1795235633Sdim } 1796235633Sdim 1797263509Sdim /// \brief Returns the CXXConstructExpr from this new-expression, or null. 1798245431Sdim const CXXConstructExpr* getConstructExpr() const { 1799235633Sdim return dyn_cast_or_null<CXXConstructExpr>(getInitializer()); 1800235633Sdim } 1801235633Sdim 1802218893Sdim /// Answers whether the usual array deallocation function for the 1803218893Sdim /// allocated type expects the size of the allocation as a 1804218893Sdim /// parameter. 1805218893Sdim bool doesUsualArrayDeleteWantSize() const { 1806218893Sdim return UsualArrayDeleteWantsSize; 1807218893Sdim } 1808218893Sdim 1809193326Sed typedef ExprIterator arg_iterator; 1810193326Sed typedef ConstExprIterator const_arg_iterator; 1811193326Sed 1812193326Sed arg_iterator placement_arg_begin() { 1813235633Sdim return SubExprs + Array + hasInitializer(); 1814193326Sed } 1815193326Sed arg_iterator placement_arg_end() { 1816235633Sdim return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1817193326Sed } 1818193326Sed const_arg_iterator placement_arg_begin() const { 1819235633Sdim return SubExprs + Array + hasInitializer(); 1820193326Sed } 1821193326Sed const_arg_iterator placement_arg_end() const { 1822235633Sdim return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1823193326Sed } 1824193326Sed 1825208600Srdivacky typedef Stmt **raw_arg_iterator; 1826208600Srdivacky raw_arg_iterator raw_arg_begin() { return SubExprs; } 1827208600Srdivacky raw_arg_iterator raw_arg_end() { 1828235633Sdim return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1829208600Srdivacky } 1830208600Srdivacky const_arg_iterator raw_arg_begin() const { return SubExprs; } 1831235633Sdim const_arg_iterator raw_arg_end() const { 1832235633Sdim return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1833235633Sdim } 1834193326Sed 1835245431Sdim SourceLocation getStartLoc() const { return Range.getBegin(); } 1836245431Sdim SourceLocation getEndLoc() const { return Range.getEnd(); } 1837218893Sdim 1838235633Sdim SourceRange getDirectInitRange() const { return DirectInitRange; } 1839218893Sdim 1840235633Sdim SourceRange getSourceRange() const LLVM_READONLY { 1841245431Sdim return Range; 1842193326Sed } 1843252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); } 1844252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 1845193326Sed 1846193326Sed static bool classof(const Stmt *T) { 1847193326Sed return T->getStmtClass() == CXXNewExprClass; 1848193326Sed } 1849193326Sed 1850193326Sed // Iterators 1851218893Sdim child_range children() { 1852235633Sdim return child_range(raw_arg_begin(), raw_arg_end()); 1853218893Sdim } 1854193326Sed}; 1855193326Sed 1856245431Sdim/// \brief Represents a \c delete expression for memory deallocation and 1857245431Sdim/// destructor calls, e.g. "delete[] pArray". 1858193326Sedclass CXXDeleteExpr : public Expr { 1859263509Sdim /// Points to the operator delete overload that is used. Could be a member. 1860235633Sdim FunctionDecl *OperatorDelete; 1861263509Sdim /// The pointer expression to be deleted. 1862235633Sdim Stmt *Argument; 1863263509Sdim /// Location of the expression. 1864235633Sdim SourceLocation Loc; 1865263509Sdim /// Is this a forced global delete, i.e. "::delete"? 1866193326Sed bool GlobalDelete : 1; 1867263509Sdim /// Is this the array form of delete, i.e. "delete[]"? 1868193326Sed bool ArrayForm : 1; 1869263509Sdim /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 1870263509Sdim /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 1871263509Sdim /// will be true). 1872218893Sdim bool ArrayFormAsWritten : 1; 1873263509Sdim /// Does the usual deallocation function for the element type require 1874263509Sdim /// a size_t argument? 1875218893Sdim bool UsualArrayDeleteWantsSize : 1; 1876193326Sedpublic: 1877193326Sed CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 1878218893Sdim bool arrayFormAsWritten, bool usualArrayDeleteWantsSize, 1879193326Sed FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1880218893Sdim : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1881224145Sdim arg->isInstantiationDependent(), 1882218893Sdim arg->containsUnexpandedParameterPack()), 1883235633Sdim OperatorDelete(operatorDelete), Argument(arg), Loc(loc), 1884218893Sdim GlobalDelete(globalDelete), 1885218893Sdim ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 1886235633Sdim UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { } 1887210299Sed explicit CXXDeleteExpr(EmptyShell Shell) 1888210299Sed : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 1889193326Sed 1890193326Sed bool isGlobalDelete() const { return GlobalDelete; } 1891193326Sed bool isArrayForm() const { return ArrayForm; } 1892218893Sdim bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 1893193326Sed 1894218893Sdim /// Answers whether the usual array deallocation function for the 1895218893Sdim /// allocated type expects the size of the allocation as a 1896218893Sdim /// parameter. This can be true even if the actual deallocation 1897218893Sdim /// function that we're using doesn't want a size. 1898218893Sdim bool doesUsualArrayDeleteWantSize() const { 1899218893Sdim return UsualArrayDeleteWantsSize; 1900218893Sdim } 1901218893Sdim 1902193326Sed FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1903193326Sed 1904193326Sed Expr *getArgument() { return cast<Expr>(Argument); } 1905193326Sed const Expr *getArgument() const { return cast<Expr>(Argument); } 1906193326Sed 1907263509Sdim /// \brief Retrieve the type being destroyed. 1908263509Sdim /// 1909263509Sdim /// If the type being destroyed is a dependent type which may or may not 1910263509Sdim /// be a pointer, return an invalid type. 1911218893Sdim QualType getDestroyedType() const; 1912235633Sdim 1913252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 1914252723Sdim SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();} 1915193326Sed 1916193326Sed static bool classof(const Stmt *T) { 1917193326Sed return T->getStmtClass() == CXXDeleteExprClass; 1918193326Sed } 1919193326Sed 1920193326Sed // Iterators 1921218893Sdim child_range children() { return child_range(&Argument, &Argument+1); } 1922218893Sdim 1923218893Sdim friend class ASTStmtReader; 1924193326Sed}; 1925193326Sed 1926245431Sdim/// \brief Stores the type being destroyed by a pseudo-destructor expression. 1927204643Srdivackyclass PseudoDestructorTypeStorage { 1928235633Sdim /// \brief Either the type source information or the name of the type, if 1929204643Srdivacky /// it couldn't be resolved due to type-dependence. 1930204643Srdivacky llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1931235633Sdim 1932204643Srdivacky /// \brief The starting source location of the pseudo-destructor type. 1933204643Srdivacky SourceLocation Location; 1934235633Sdim 1935204643Srdivackypublic: 1936204643Srdivacky PseudoDestructorTypeStorage() { } 1937235633Sdim 1938204643Srdivacky PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1939204643Srdivacky : Type(II), Location(Loc) { } 1940235633Sdim 1941204643Srdivacky PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1942235633Sdim 1943235633Sdim TypeSourceInfo *getTypeSourceInfo() const { 1944235633Sdim return Type.dyn_cast<TypeSourceInfo *>(); 1945204643Srdivacky } 1946235633Sdim 1947204643Srdivacky IdentifierInfo *getIdentifier() const { 1948204643Srdivacky return Type.dyn_cast<IdentifierInfo *>(); 1949204643Srdivacky } 1950235633Sdim 1951204643Srdivacky SourceLocation getLocation() const { return Location; } 1952204643Srdivacky}; 1953235633Sdim 1954198092Srdivacky/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1955198092Srdivacky/// 1956204643Srdivacky/// A pseudo-destructor is an expression that looks like a member access to a 1957235633Sdim/// destructor of a scalar type, except that scalar types don't have 1958204643Srdivacky/// destructors. For example: 1959198092Srdivacky/// 1960198092Srdivacky/// \code 1961204643Srdivacky/// typedef int T; 1962204643Srdivacky/// void f(int *p) { 1963204643Srdivacky/// p->T::~T(); 1964204643Srdivacky/// } 1965204643Srdivacky/// \endcode 1966204643Srdivacky/// 1967204643Srdivacky/// Pseudo-destructors typically occur when instantiating templates such as: 1968235633Sdim/// 1969204643Srdivacky/// \code 1970198092Srdivacky/// template<typename T> 1971198092Srdivacky/// void destroy(T* ptr) { 1972204643Srdivacky/// ptr->T::~T(); 1973198092Srdivacky/// } 1974198092Srdivacky/// \endcode 1975198092Srdivacky/// 1976204643Srdivacky/// for scalar types. A pseudo-destructor expression has no run-time semantics 1977204643Srdivacky/// beyond evaluating the base expression. 1978198092Srdivackyclass CXXPseudoDestructorExpr : public Expr { 1979198092Srdivacky /// \brief The base expression (that is being destroyed). 1980198092Srdivacky Stmt *Base; 1981198092Srdivacky 1982198092Srdivacky /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1983198092Srdivacky /// period ('.'). 1984198092Srdivacky bool IsArrow : 1; 1985198092Srdivacky 1986198092Srdivacky /// \brief The location of the '.' or '->' operator. 1987198092Srdivacky SourceLocation OperatorLoc; 1988235633Sdim 1989198092Srdivacky /// \brief The nested-name-specifier that follows the operator, if present. 1990219077Sdim NestedNameSpecifierLoc QualifierLoc; 1991198092Srdivacky 1992204643Srdivacky /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1993204643Srdivacky /// expression. 1994204643Srdivacky TypeSourceInfo *ScopeType; 1995235633Sdim 1996235633Sdim /// \brief The location of the '::' in a qualified pseudo-destructor 1997204643Srdivacky /// expression. 1998204643Srdivacky SourceLocation ColonColonLoc; 1999235633Sdim 2000204643Srdivacky /// \brief The location of the '~'. 2001204643Srdivacky SourceLocation TildeLoc; 2002235633Sdim 2003235633Sdim /// \brief The type being destroyed, or its name if we were unable to 2004204643Srdivacky /// resolve the name. 2005204643Srdivacky PseudoDestructorTypeStorage DestroyedType; 2006198092Srdivacky 2007219077Sdim friend class ASTStmtReader; 2008235633Sdim 2009198092Srdivackypublic: 2010263509Sdim CXXPseudoDestructorExpr(const ASTContext &Context, 2011198092Srdivacky Expr *Base, bool isArrow, SourceLocation OperatorLoc, 2012219077Sdim NestedNameSpecifierLoc QualifierLoc, 2013204643Srdivacky TypeSourceInfo *ScopeType, 2014204643Srdivacky SourceLocation ColonColonLoc, 2015204643Srdivacky SourceLocation TildeLoc, 2016218893Sdim PseudoDestructorTypeStorage DestroyedType); 2017198092Srdivacky 2018210299Sed explicit CXXPseudoDestructorExpr(EmptyShell Shell) 2019210299Sed : Expr(CXXPseudoDestructorExprClass, Shell), 2020219077Sdim Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { } 2021210299Sed 2022198092Srdivacky Expr *getBase() const { return cast<Expr>(Base); } 2023198092Srdivacky 2024198092Srdivacky /// \brief Determines whether this member expression actually had 2025198092Srdivacky /// a C++ nested-name-specifier prior to the name of the member, e.g., 2026198092Srdivacky /// x->Base::foo. 2027263509Sdim bool hasQualifier() const { return QualifierLoc.hasQualifier(); } 2028198092Srdivacky 2029219077Sdim /// \brief Retrieves the nested-name-specifier that qualifies the type name, 2030219077Sdim /// with source-location information. 2031219077Sdim NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2032235633Sdim 2033198092Srdivacky /// \brief If the member name was qualified, retrieves the 2034198092Srdivacky /// nested-name-specifier that precedes the member name. Otherwise, returns 2035263509Sdim /// null. 2036235633Sdim NestedNameSpecifier *getQualifier() const { 2037235633Sdim return QualifierLoc.getNestedNameSpecifier(); 2038219077Sdim } 2039198092Srdivacky 2040198092Srdivacky /// \brief Determine whether this pseudo-destructor expression was written 2041198092Srdivacky /// using an '->' (otherwise, it used a '.'). 2042198092Srdivacky bool isArrow() const { return IsArrow; } 2043198092Srdivacky 2044198092Srdivacky /// \brief Retrieve the location of the '.' or '->' operator. 2045198092Srdivacky SourceLocation getOperatorLoc() const { return OperatorLoc; } 2046198092Srdivacky 2047235633Sdim /// \brief Retrieve the scope type in a qualified pseudo-destructor 2048204643Srdivacky /// expression. 2049204643Srdivacky /// 2050204643Srdivacky /// Pseudo-destructor expressions can have extra qualification within them 2051204643Srdivacky /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 2052204643Srdivacky /// Here, if the object type of the expression is (or may be) a scalar type, 2053235633Sdim /// \p T may also be a scalar type and, therefore, cannot be part of a 2054204643Srdivacky /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 2055204643Srdivacky /// destructor expression. 2056204643Srdivacky TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 2057235633Sdim 2058204643Srdivacky /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 2059204643Srdivacky /// expression. 2060204643Srdivacky SourceLocation getColonColonLoc() const { return ColonColonLoc; } 2061235633Sdim 2062204643Srdivacky /// \brief Retrieve the location of the '~'. 2063204643Srdivacky SourceLocation getTildeLoc() const { return TildeLoc; } 2064235633Sdim 2065204643Srdivacky /// \brief Retrieve the source location information for the type 2066204643Srdivacky /// being destroyed. 2067204643Srdivacky /// 2068235633Sdim /// This type-source information is available for non-dependent 2069204643Srdivacky /// pseudo-destructor expressions and some dependent pseudo-destructor 2070263509Sdim /// expressions. Returns null if we only have the identifier for a 2071204643Srdivacky /// dependent pseudo-destructor expression. 2072235633Sdim TypeSourceInfo *getDestroyedTypeInfo() const { 2073235633Sdim return DestroyedType.getTypeSourceInfo(); 2074204643Srdivacky } 2075235633Sdim 2076204643Srdivacky /// \brief In a dependent pseudo-destructor expression for which we do not 2077204643Srdivacky /// have full type information on the destroyed type, provides the name 2078204643Srdivacky /// of the destroyed type. 2079204643Srdivacky IdentifierInfo *getDestroyedTypeIdentifier() const { 2080204643Srdivacky return DestroyedType.getIdentifier(); 2081204643Srdivacky } 2082235633Sdim 2083204643Srdivacky /// \brief Retrieve the type being destroyed. 2084204643Srdivacky QualType getDestroyedType() const; 2085235633Sdim 2086204643Srdivacky /// \brief Retrieve the starting location of the type being destroyed. 2087235633Sdim SourceLocation getDestroyedTypeLoc() const { 2088235633Sdim return DestroyedType.getLocation(); 2089204643Srdivacky } 2090198092Srdivacky 2091210299Sed /// \brief Set the name of destroyed type for a dependent pseudo-destructor 2092210299Sed /// expression. 2093210299Sed void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 2094210299Sed DestroyedType = PseudoDestructorTypeStorage(II, Loc); 2095210299Sed } 2096210299Sed 2097210299Sed /// \brief Set the destroyed type. 2098210299Sed void setDestroyedType(TypeSourceInfo *Info) { 2099210299Sed DestroyedType = PseudoDestructorTypeStorage(Info); 2100210299Sed } 2101210299Sed 2102252723Sdim SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();} 2103252723Sdim SourceLocation getLocEnd() const LLVM_READONLY; 2104198092Srdivacky 2105198092Srdivacky static bool classof(const Stmt *T) { 2106198092Srdivacky return T->getStmtClass() == CXXPseudoDestructorExprClass; 2107198092Srdivacky } 2108198092Srdivacky 2109198092Srdivacky // Iterators 2110218893Sdim child_range children() { return child_range(&Base, &Base + 1); } 2111198092Srdivacky}; 2112198092Srdivacky 2113245431Sdim/// \brief Represents a GCC or MS unary type trait, as used in the 2114245431Sdim/// implementation of TR1/C++11 type trait templates. 2115245431Sdim/// 2116193326Sed/// Example: 2117263509Sdim/// \code 2118245431Sdim/// __is_pod(int) == true 2119245431Sdim/// __is_enum(std::string) == false 2120263509Sdim/// \endcode 2121193326Sedclass UnaryTypeTraitExpr : public Expr { 2122263509Sdim /// \brief The trait. A UnaryTypeTrait enum in MSVC compatible unsigned. 2123218893Sdim unsigned UTT : 31; 2124218893Sdim /// The value of the type trait. Unspecified if dependent. 2125218893Sdim bool Value : 1; 2126193326Sed 2127263509Sdim /// \brief The location of the type trait keyword. 2128193326Sed SourceLocation Loc; 2129193326Sed 2130263509Sdim /// \brief The location of the closing paren. 2131193326Sed SourceLocation RParen; 2132193326Sed 2133263509Sdim /// \brief The type being queried. 2134218893Sdim TypeSourceInfo *QueriedType; 2135193326Sed 2136193326Sedpublic: 2137235633Sdim UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 2138218893Sdim TypeSourceInfo *queried, bool value, 2139193326Sed SourceLocation rparen, QualType ty) 2140218893Sdim : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 2141218893Sdim false, queried->getType()->isDependentType(), 2142224145Sdim queried->getType()->isInstantiationDependentType(), 2143218893Sdim queried->getType()->containsUnexpandedParameterPack()), 2144218893Sdim UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 2145193326Sed 2146210299Sed explicit UnaryTypeTraitExpr(EmptyShell Empty) 2147218893Sdim : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 2148218893Sdim QueriedType() { } 2149210299Sed 2150252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2151252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2152193326Sed 2153218893Sdim UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 2154193326Sed 2155218893Sdim QualType getQueriedType() const { return QueriedType->getType(); } 2156193326Sed 2157218893Sdim TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 2158235633Sdim 2159218893Sdim bool getValue() const { return Value; } 2160193326Sed 2161193326Sed static bool classof(const Stmt *T) { 2162193326Sed return T->getStmtClass() == UnaryTypeTraitExprClass; 2163193326Sed } 2164193326Sed 2165193326Sed // Iterators 2166218893Sdim child_range children() { return child_range(); } 2167210299Sed 2168212904Sdim friend class ASTStmtReader; 2169193326Sed}; 2170193326Sed 2171245431Sdim/// \brief Represents a GCC or MS binary type trait, as used in the 2172245431Sdim/// implementation of TR1/C++11 type trait templates. 2173245431Sdim/// 2174218893Sdim/// Example: 2175263509Sdim/// \code 2176245431Sdim/// __is_base_of(Base, Derived) == true 2177263509Sdim/// \endcode 2178218893Sdimclass BinaryTypeTraitExpr : public Expr { 2179263509Sdim /// \brief The trait. A BinaryTypeTrait enum in MSVC compatible unsigned. 2180218893Sdim unsigned BTT : 8; 2181218893Sdim 2182218893Sdim /// The value of the type trait. Unspecified if dependent. 2183218893Sdim bool Value : 1; 2184218893Sdim 2185263509Sdim /// \brief The location of the type trait keyword. 2186218893Sdim SourceLocation Loc; 2187218893Sdim 2188263509Sdim /// \brief The location of the closing paren. 2189218893Sdim SourceLocation RParen; 2190218893Sdim 2191263509Sdim /// \brief The lhs type being queried. 2192218893Sdim TypeSourceInfo *LhsType; 2193218893Sdim 2194263509Sdim /// \brief The rhs type being queried. 2195218893Sdim TypeSourceInfo *RhsType; 2196218893Sdim 2197218893Sdimpublic: 2198235633Sdim BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 2199235633Sdim TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 2200218893Sdim bool value, SourceLocation rparen, QualType ty) 2201235633Sdim : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 2202218893Sdim lhsType->getType()->isDependentType() || 2203218893Sdim rhsType->getType()->isDependentType(), 2204224145Sdim (lhsType->getType()->isInstantiationDependentType() || 2205224145Sdim rhsType->getType()->isInstantiationDependentType()), 2206218893Sdim (lhsType->getType()->containsUnexpandedParameterPack() || 2207218893Sdim rhsType->getType()->containsUnexpandedParameterPack())), 2208218893Sdim BTT(btt), Value(value), Loc(loc), RParen(rparen), 2209218893Sdim LhsType(lhsType), RhsType(rhsType) { } 2210218893Sdim 2211218893Sdim 2212218893Sdim explicit BinaryTypeTraitExpr(EmptyShell Empty) 2213218893Sdim : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 2214218893Sdim LhsType(), RhsType() { } 2215218893Sdim 2216252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2217252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2218218893Sdim 2219218893Sdim BinaryTypeTrait getTrait() const { 2220218893Sdim return static_cast<BinaryTypeTrait>(BTT); 2221218893Sdim } 2222218893Sdim 2223218893Sdim QualType getLhsType() const { return LhsType->getType(); } 2224218893Sdim QualType getRhsType() const { return RhsType->getType(); } 2225218893Sdim 2226218893Sdim TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 2227218893Sdim TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 2228235633Sdim 2229218893Sdim bool getValue() const { assert(!isTypeDependent()); return Value; } 2230218893Sdim 2231218893Sdim static bool classof(const Stmt *T) { 2232218893Sdim return T->getStmtClass() == BinaryTypeTraitExprClass; 2233218893Sdim } 2234218893Sdim 2235218893Sdim // Iterators 2236218893Sdim child_range children() { return child_range(); } 2237218893Sdim 2238218893Sdim friend class ASTStmtReader; 2239218893Sdim}; 2240218893Sdim 2241235633Sdim/// \brief A type trait used in the implementation of various C++11 and 2242235633Sdim/// Library TR1 trait templates. 2243235633Sdim/// 2244235633Sdim/// \code 2245235633Sdim/// __is_trivially_constructible(vector<int>, int*, int*) 2246235633Sdim/// \endcode 2247235633Sdimclass TypeTraitExpr : public Expr { 2248235633Sdim /// \brief The location of the type trait keyword. 2249235633Sdim SourceLocation Loc; 2250235633Sdim 2251235633Sdim /// \brief The location of the closing parenthesis. 2252235633Sdim SourceLocation RParenLoc; 2253235633Sdim 2254235633Sdim // Note: The TypeSourceInfos for the arguments are allocated after the 2255235633Sdim // TypeTraitExpr. 2256235633Sdim 2257235633Sdim TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, 2258235633Sdim ArrayRef<TypeSourceInfo *> Args, 2259235633Sdim SourceLocation RParenLoc, 2260235633Sdim bool Value); 2261235633Sdim 2262235633Sdim TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { } 2263235633Sdim 2264235633Sdim /// \brief Retrieve the argument types. 2265235633Sdim TypeSourceInfo **getTypeSourceInfos() { 2266235633Sdim return reinterpret_cast<TypeSourceInfo **>(this+1); 2267235633Sdim } 2268235633Sdim 2269235633Sdim /// \brief Retrieve the argument types. 2270235633Sdim TypeSourceInfo * const *getTypeSourceInfos() const { 2271235633Sdim return reinterpret_cast<TypeSourceInfo * const*>(this+1); 2272235633Sdim } 2273235633Sdim 2274235633Sdimpublic: 2275235633Sdim /// \brief Create a new type trait expression. 2276263509Sdim static TypeTraitExpr *Create(const ASTContext &C, QualType T, 2277263509Sdim SourceLocation Loc, TypeTrait Kind, 2278235633Sdim ArrayRef<TypeSourceInfo *> Args, 2279235633Sdim SourceLocation RParenLoc, 2280235633Sdim bool Value); 2281235633Sdim 2282263509Sdim static TypeTraitExpr *CreateDeserialized(const ASTContext &C, 2283263509Sdim unsigned NumArgs); 2284235633Sdim 2285235633Sdim /// \brief Determine which type trait this expression uses. 2286235633Sdim TypeTrait getTrait() const { 2287235633Sdim return static_cast<TypeTrait>(TypeTraitExprBits.Kind); 2288235633Sdim } 2289235633Sdim 2290235633Sdim bool getValue() const { 2291235633Sdim assert(!isValueDependent()); 2292235633Sdim return TypeTraitExprBits.Value; 2293235633Sdim } 2294235633Sdim 2295235633Sdim /// \brief Determine the number of arguments to this type trait. 2296235633Sdim unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; } 2297235633Sdim 2298235633Sdim /// \brief Retrieve the Ith argument. 2299235633Sdim TypeSourceInfo *getArg(unsigned I) const { 2300235633Sdim assert(I < getNumArgs() && "Argument out-of-range"); 2301235633Sdim return getArgs()[I]; 2302235633Sdim } 2303235633Sdim 2304235633Sdim /// \brief Retrieve the argument types. 2305235633Sdim ArrayRef<TypeSourceInfo *> getArgs() const { 2306235633Sdim return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs()); 2307235633Sdim } 2308235633Sdim 2309235633Sdim typedef TypeSourceInfo **arg_iterator; 2310235633Sdim arg_iterator arg_begin() { 2311235633Sdim return getTypeSourceInfos(); 2312235633Sdim } 2313235633Sdim arg_iterator arg_end() { 2314235633Sdim return getTypeSourceInfos() + getNumArgs(); 2315235633Sdim } 2316235633Sdim 2317235633Sdim typedef TypeSourceInfo const * const *arg_const_iterator; 2318235633Sdim arg_const_iterator arg_begin() const { return getTypeSourceInfos(); } 2319235633Sdim arg_const_iterator arg_end() const { 2320235633Sdim return getTypeSourceInfos() + getNumArgs(); 2321235633Sdim } 2322235633Sdim 2323252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2324252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 2325252723Sdim 2326235633Sdim static bool classof(const Stmt *T) { 2327235633Sdim return T->getStmtClass() == TypeTraitExprClass; 2328235633Sdim } 2329235633Sdim 2330235633Sdim // Iterators 2331235633Sdim child_range children() { return child_range(); } 2332235633Sdim 2333235633Sdim friend class ASTStmtReader; 2334235633Sdim friend class ASTStmtWriter; 2335235633Sdim 2336235633Sdim}; 2337235633Sdim 2338245431Sdim/// \brief An Embarcadero array type trait, as used in the implementation of 2339245431Sdim/// __array_rank and __array_extent. 2340245431Sdim/// 2341221345Sdim/// Example: 2342263509Sdim/// \code 2343245431Sdim/// __array_rank(int[10][20]) == 2 2344245431Sdim/// __array_extent(int, 1) == 20 2345263509Sdim/// \endcode 2346221345Sdimclass ArrayTypeTraitExpr : public Expr { 2347235633Sdim virtual void anchor(); 2348235633Sdim 2349245431Sdim /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 2350221345Sdim unsigned ATT : 2; 2351221345Sdim 2352245431Sdim /// \brief The value of the type trait. Unspecified if dependent. 2353221345Sdim uint64_t Value; 2354221345Sdim 2355245431Sdim /// \brief The array dimension being queried, or -1 if not used. 2356221345Sdim Expr *Dimension; 2357221345Sdim 2358245431Sdim /// \brief The location of the type trait keyword. 2359221345Sdim SourceLocation Loc; 2360221345Sdim 2361245431Sdim /// \brief The location of the closing paren. 2362221345Sdim SourceLocation RParen; 2363221345Sdim 2364245431Sdim /// \brief The type being queried. 2365221345Sdim TypeSourceInfo *QueriedType; 2366221345Sdim 2367221345Sdimpublic: 2368221345Sdim ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 2369221345Sdim TypeSourceInfo *queried, uint64_t value, 2370221345Sdim Expr *dimension, SourceLocation rparen, QualType ty) 2371221345Sdim : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 2372221345Sdim false, queried->getType()->isDependentType(), 2373224145Sdim (queried->getType()->isInstantiationDependentType() || 2374224145Sdim (dimension && dimension->isInstantiationDependent())), 2375221345Sdim queried->getType()->containsUnexpandedParameterPack()), 2376221345Sdim ATT(att), Value(value), Dimension(dimension), 2377221345Sdim Loc(loc), RParen(rparen), QueriedType(queried) { } 2378221345Sdim 2379221345Sdim 2380221345Sdim explicit ArrayTypeTraitExpr(EmptyShell Empty) 2381221345Sdim : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 2382221345Sdim QueriedType() { } 2383221345Sdim 2384221345Sdim virtual ~ArrayTypeTraitExpr() { } 2385221345Sdim 2386252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2387252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2388221345Sdim 2389221345Sdim ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 2390221345Sdim 2391221345Sdim QualType getQueriedType() const { return QueriedType->getType(); } 2392221345Sdim 2393221345Sdim TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 2394221345Sdim 2395221345Sdim uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 2396221345Sdim 2397221345Sdim Expr *getDimensionExpression() const { return Dimension; } 2398221345Sdim 2399221345Sdim static bool classof(const Stmt *T) { 2400221345Sdim return T->getStmtClass() == ArrayTypeTraitExprClass; 2401221345Sdim } 2402221345Sdim 2403221345Sdim // Iterators 2404221345Sdim child_range children() { return child_range(); } 2405221345Sdim 2406221345Sdim friend class ASTStmtReader; 2407221345Sdim}; 2408221345Sdim 2409245431Sdim/// \brief An expression trait intrinsic. 2410245431Sdim/// 2411221345Sdim/// Example: 2412263509Sdim/// \code 2413245431Sdim/// __is_lvalue_expr(std::cout) == true 2414245431Sdim/// __is_lvalue_expr(1) == false 2415263509Sdim/// \endcode 2416221345Sdimclass ExpressionTraitExpr : public Expr { 2417263509Sdim /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned. 2418221345Sdim unsigned ET : 31; 2419245431Sdim /// \brief The value of the type trait. Unspecified if dependent. 2420221345Sdim bool Value : 1; 2421221345Sdim 2422245431Sdim /// \brief The location of the type trait keyword. 2423221345Sdim SourceLocation Loc; 2424221345Sdim 2425245431Sdim /// \brief The location of the closing paren. 2426221345Sdim SourceLocation RParen; 2427221345Sdim 2428245431Sdim /// \brief The expression being queried. 2429221345Sdim Expr* QueriedExpression; 2430221345Sdimpublic: 2431235633Sdim ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2432221345Sdim Expr *queried, bool value, 2433221345Sdim SourceLocation rparen, QualType resultType) 2434221345Sdim : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2435221345Sdim false, // Not type-dependent 2436221345Sdim // Value-dependent if the argument is type-dependent. 2437221345Sdim queried->isTypeDependent(), 2438224145Sdim queried->isInstantiationDependent(), 2439221345Sdim queried->containsUnexpandedParameterPack()), 2440235633Sdim ET(et), Value(value), Loc(loc), RParen(rparen), 2441235633Sdim QueriedExpression(queried) { } 2442221345Sdim 2443221345Sdim explicit ExpressionTraitExpr(EmptyShell Empty) 2444221345Sdim : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2445221345Sdim QueriedExpression() { } 2446221345Sdim 2447252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2448252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2449221345Sdim 2450221345Sdim ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2451221345Sdim 2452221345Sdim Expr *getQueriedExpression() const { return QueriedExpression; } 2453221345Sdim 2454221345Sdim bool getValue() const { return Value; } 2455221345Sdim 2456221345Sdim static bool classof(const Stmt *T) { 2457221345Sdim return T->getStmtClass() == ExpressionTraitExprClass; 2458221345Sdim } 2459221345Sdim 2460221345Sdim // Iterators 2461221345Sdim child_range children() { return child_range(); } 2462221345Sdim 2463221345Sdim friend class ASTStmtReader; 2464221345Sdim}; 2465221345Sdim 2466221345Sdim 2467203955Srdivacky/// \brief A reference to an overloaded function set, either an 2468245431Sdim/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr. 2469203955Srdivackyclass OverloadExpr : public Expr { 2470245431Sdim /// \brief The common name of these declarations. 2471235633Sdim DeclarationNameInfo NameInfo; 2472235633Sdim 2473235633Sdim /// \brief The nested-name-specifier that qualifies the name, if any. 2474235633Sdim NestedNameSpecifierLoc QualifierLoc; 2475235633Sdim 2476199990Srdivacky /// The results. These are undesugared, which is to say, they may 2477203955Srdivacky /// include UsingShadowDecls. Access is relative to the naming 2478203955Srdivacky /// class. 2479208600Srdivacky // FIXME: Allocate this data after the OverloadExpr subclass. 2480208600Srdivacky DeclAccessPair *Results; 2481208600Srdivacky unsigned NumResults; 2482199990Srdivacky 2483235633Sdimprotected: 2484235633Sdim /// \brief Whether the name includes info for explicit template 2485235633Sdim /// keyword and arguments. 2486235633Sdim bool HasTemplateKWAndArgsInfo; 2487199990Srdivacky 2488235633Sdim /// \brief Return the optional template keyword and arguments info. 2489235633Sdim ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2490199990Srdivacky 2491235633Sdim /// \brief Return the optional template keyword and arguments info. 2492235633Sdim const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2493235633Sdim return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2494235633Sdim } 2495203955Srdivacky 2496263509Sdim OverloadExpr(StmtClass K, const ASTContext &C, 2497221345Sdim NestedNameSpecifierLoc QualifierLoc, 2498235633Sdim SourceLocation TemplateKWLoc, 2499212904Sdim const DeclarationNameInfo &NameInfo, 2500218893Sdim const TemplateArgumentListInfo *TemplateArgs, 2501218893Sdim UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2502224145Sdim bool KnownDependent, 2503224145Sdim bool KnownInstantiationDependent, 2504224145Sdim bool KnownContainsUnexpandedParameterPack); 2505203955Srdivacky 2506210299Sed OverloadExpr(StmtClass K, EmptyShell Empty) 2507235633Sdim : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0), 2508235633Sdim HasTemplateKWAndArgsInfo(false) { } 2509210299Sed 2510263509Sdim void initializeResults(const ASTContext &C, 2511218893Sdim UnresolvedSetIterator Begin, 2512218893Sdim UnresolvedSetIterator End); 2513218893Sdim 2514203955Srdivackypublic: 2515212904Sdim struct FindResult { 2516212904Sdim OverloadExpr *Expression; 2517212904Sdim bool IsAddressOfOperand; 2518212904Sdim bool HasFormOfMemberPointer; 2519212904Sdim }; 2520212904Sdim 2521263509Sdim /// \brief Finds the overloaded expression in the given expression \p E of 2522203955Srdivacky /// OverloadTy. 2523203955Srdivacky /// 2524212904Sdim /// \return the expression (which must be there) and true if it has 2525212904Sdim /// the particular form of a member pointer expression 2526212904Sdim static FindResult find(Expr *E) { 2527203955Srdivacky assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 2528203955Srdivacky 2529212904Sdim FindResult Result; 2530212904Sdim 2531203955Srdivacky E = E->IgnoreParens(); 2532212904Sdim if (isa<UnaryOperator>(E)) { 2533212904Sdim assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 2534212904Sdim E = cast<UnaryOperator>(E)->getSubExpr(); 2535212904Sdim OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 2536212904Sdim 2537212904Sdim Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 2538212904Sdim Result.IsAddressOfOperand = true; 2539212904Sdim Result.Expression = Ovl; 2540212904Sdim } else { 2541212904Sdim Result.HasFormOfMemberPointer = false; 2542212904Sdim Result.IsAddressOfOperand = false; 2543212904Sdim Result.Expression = cast<OverloadExpr>(E); 2544212904Sdim } 2545212904Sdim 2546212904Sdim return Result; 2547203955Srdivacky } 2548203955Srdivacky 2549245431Sdim /// \brief Gets the naming class of this lookup, if any. 2550207619Srdivacky CXXRecordDecl *getNamingClass() const; 2551207619Srdivacky 2552203955Srdivacky typedef UnresolvedSetImpl::iterator decls_iterator; 2553208600Srdivacky decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2554235633Sdim decls_iterator decls_end() const { 2555208600Srdivacky return UnresolvedSetIterator(Results + NumResults); 2556208600Srdivacky } 2557235633Sdim 2558245431Sdim /// \brief Gets the number of declarations in the unresolved set. 2559208600Srdivacky unsigned getNumDecls() const { return NumResults; } 2560203955Srdivacky 2561245431Sdim /// \brief Gets the full name info. 2562212904Sdim const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2563212904Sdim 2564245431Sdim /// \brief Gets the name looked up. 2565212904Sdim DeclarationName getName() const { return NameInfo.getName(); } 2566203955Srdivacky 2567245431Sdim /// \brief Gets the location of the name. 2568212904Sdim SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 2569203955Srdivacky 2570245431Sdim /// \brief Fetches the nested-name qualifier, if one was given. 2571235633Sdim NestedNameSpecifier *getQualifier() const { 2572235633Sdim return QualifierLoc.getNestedNameSpecifier(); 2573221345Sdim } 2574203955Srdivacky 2575245431Sdim /// \brief Fetches the nested-name qualifier with source-location 2576245431Sdim /// information, if one was given. 2577221345Sdim NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2578203955Srdivacky 2579235633Sdim /// \brief Retrieve the location of the template keyword preceding 2580235633Sdim /// this name, if any. 2581235633Sdim SourceLocation getTemplateKeywordLoc() const { 2582235633Sdim if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2583235633Sdim return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2584235633Sdim } 2585203955Srdivacky 2586235633Sdim /// \brief Retrieve the location of the left angle bracket starting the 2587235633Sdim /// explicit template argument list following the name, if any. 2588235633Sdim SourceLocation getLAngleLoc() const { 2589235633Sdim if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2590235633Sdim return getTemplateKWAndArgsInfo()->LAngleLoc; 2591235633Sdim } 2592203955Srdivacky 2593235633Sdim /// \brief Retrieve the location of the right angle bracket ending the 2594235633Sdim /// explicit template argument list following the name, if any. 2595235633Sdim SourceLocation getRAngleLoc() const { 2596235633Sdim if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2597235633Sdim return getTemplateKWAndArgsInfo()->RAngleLoc; 2598235633Sdim } 2599235633Sdim 2600245431Sdim /// \brief Determines whether the name was preceded by the template keyword. 2601235633Sdim bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2602235633Sdim 2603245431Sdim /// \brief Determines whether this expression had explicit template arguments. 2604235633Sdim bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2605235633Sdim 2606235633Sdim // Note that, inconsistently with the explicit-template-argument AST 2607235633Sdim // nodes, users are *forbidden* from calling these methods on objects 2608235633Sdim // without explicit template arguments. 2609235633Sdim 2610235633Sdim ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2611235633Sdim assert(hasExplicitTemplateArgs()); 2612235633Sdim return *getTemplateKWAndArgsInfo(); 2613235633Sdim } 2614235633Sdim 2615226890Sdim const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2616203955Srdivacky return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 2617203955Srdivacky } 2618203955Srdivacky 2619235633Sdim TemplateArgumentLoc const *getTemplateArgs() const { 2620235633Sdim return getExplicitTemplateArgs().getTemplateArgs(); 2621235633Sdim } 2622235633Sdim 2623235633Sdim unsigned getNumTemplateArgs() const { 2624235633Sdim return getExplicitTemplateArgs().NumTemplateArgs; 2625235633Sdim } 2626235633Sdim 2627245431Sdim /// \brief Copies the template arguments into the given structure. 2628235633Sdim void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2629235633Sdim getExplicitTemplateArgs().copyInto(List); 2630235633Sdim } 2631235633Sdim 2632212904Sdim /// \brief Retrieves the optional explicit template arguments. 2633245431Sdim /// 2634212904Sdim /// This points to the same data as getExplicitTemplateArgs(), but 2635212904Sdim /// returns null if there are no explicit template arguments. 2636252723Sdim const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2637212904Sdim if (!hasExplicitTemplateArgs()) return 0; 2638212904Sdim return &getExplicitTemplateArgs(); 2639203955Srdivacky } 2640203955Srdivacky 2641203955Srdivacky static bool classof(const Stmt *T) { 2642203955Srdivacky return T->getStmtClass() == UnresolvedLookupExprClass || 2643203955Srdivacky T->getStmtClass() == UnresolvedMemberExprClass; 2644203955Srdivacky } 2645218893Sdim 2646218893Sdim friend class ASTStmtReader; 2647218893Sdim friend class ASTStmtWriter; 2648203955Srdivacky}; 2649203955Srdivacky 2650203955Srdivacky/// \brief A reference to a name which we were able to look up during 2651245431Sdim/// parsing but could not resolve to a specific declaration. 2652245431Sdim/// 2653245431Sdim/// This arises in several ways: 2654263509Sdim/// * we might be waiting for argument-dependent lookup; 2655263509Sdim/// * the name might resolve to an overloaded function; 2656203955Srdivacky/// and eventually: 2657263509Sdim/// * the lookup might have included a function template. 2658263509Sdim/// 2659245431Sdim/// These never include UnresolvedUsingValueDecls, which are always class 2660245431Sdim/// members and therefore appear only in UnresolvedMemberLookupExprs. 2661203955Srdivackyclass UnresolvedLookupExpr : public OverloadExpr { 2662199990Srdivacky /// True if these lookup results should be extended by 2663199990Srdivacky /// argument-dependent lookup if this is the operand of a function 2664199990Srdivacky /// call. 2665199990Srdivacky bool RequiresADL; 2666199990Srdivacky 2667199990Srdivacky /// True if these lookup results are overloaded. This is pretty 2668199990Srdivacky /// trivially rederivable if we urgently need to kill this field. 2669199990Srdivacky bool Overloaded; 2670199990Srdivacky 2671203955Srdivacky /// The naming class (C++ [class.access.base]p5) of the lookup, if 2672203955Srdivacky /// any. This can generally be recalculated from the context chain, 2673203955Srdivacky /// but that can be fairly expensive for unqualified lookups. If we 2674203955Srdivacky /// want to improve memory use here, this could go in a union 2675203955Srdivacky /// against the qualified-lookup bits. 2676203955Srdivacky CXXRecordDecl *NamingClass; 2677199990Srdivacky 2678263509Sdim UnresolvedLookupExpr(const ASTContext &C, 2679208600Srdivacky CXXRecordDecl *NamingClass, 2680221345Sdim NestedNameSpecifierLoc QualifierLoc, 2681235633Sdim SourceLocation TemplateKWLoc, 2682212904Sdim const DeclarationNameInfo &NameInfo, 2683235633Sdim bool RequiresADL, bool Overloaded, 2684218893Sdim const TemplateArgumentListInfo *TemplateArgs, 2685245431Sdim UnresolvedSetIterator Begin, UnresolvedSetIterator End) 2686235633Sdim : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2687235633Sdim NameInfo, TemplateArgs, Begin, End, false, false, false), 2688221345Sdim RequiresADL(RequiresADL), 2689221345Sdim Overloaded(Overloaded), NamingClass(NamingClass) 2690199990Srdivacky {} 2691199990Srdivacky 2692210299Sed UnresolvedLookupExpr(EmptyShell Empty) 2693210299Sed : OverloadExpr(UnresolvedLookupExprClass, Empty), 2694245431Sdim RequiresADL(false), Overloaded(false), NamingClass(0) 2695210299Sed {} 2696210299Sed 2697221345Sdim friend class ASTStmtReader; 2698235633Sdim 2699199990Srdivackypublic: 2700263509Sdim static UnresolvedLookupExpr *Create(const ASTContext &C, 2701203955Srdivacky CXXRecordDecl *NamingClass, 2702221345Sdim NestedNameSpecifierLoc QualifierLoc, 2703212904Sdim const DeclarationNameInfo &NameInfo, 2704208600Srdivacky bool ADL, bool Overloaded, 2705235633Sdim UnresolvedSetIterator Begin, 2706245431Sdim UnresolvedSetIterator End) { 2707235633Sdim return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2708235633Sdim SourceLocation(), NameInfo, 2709245431Sdim ADL, Overloaded, 0, Begin, End); 2710199990Srdivacky } 2711199990Srdivacky 2712263509Sdim static UnresolvedLookupExpr *Create(const ASTContext &C, 2713203955Srdivacky CXXRecordDecl *NamingClass, 2714221345Sdim NestedNameSpecifierLoc QualifierLoc, 2715235633Sdim SourceLocation TemplateKWLoc, 2716212904Sdim const DeclarationNameInfo &NameInfo, 2717199990Srdivacky bool ADL, 2718235633Sdim const TemplateArgumentListInfo *Args, 2719235633Sdim UnresolvedSetIterator Begin, 2720208600Srdivacky UnresolvedSetIterator End); 2721199990Srdivacky 2722263509Sdim static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C, 2723235633Sdim bool HasTemplateKWAndArgsInfo, 2724210299Sed unsigned NumTemplateArgs); 2725210299Sed 2726199990Srdivacky /// True if this declaration should be extended by 2727199990Srdivacky /// argument-dependent lookup. 2728199990Srdivacky bool requiresADL() const { return RequiresADL; } 2729199990Srdivacky 2730199990Srdivacky /// True if this lookup is overloaded. 2731199990Srdivacky bool isOverloaded() const { return Overloaded; } 2732199990Srdivacky 2733203955Srdivacky /// Gets the 'naming class' (in the sense of C++0x 2734203955Srdivacky /// [class.access.base]p5) of the lookup. This is the scope 2735203955Srdivacky /// that was looked in to find these results. 2736203955Srdivacky CXXRecordDecl *getNamingClass() const { return NamingClass; } 2737199990Srdivacky 2738252723Sdim SourceLocation getLocStart() const LLVM_READONLY { 2739252723Sdim if (NestedNameSpecifierLoc l = getQualifierLoc()) 2740252723Sdim return l.getBeginLoc(); 2741252723Sdim return getNameInfo().getLocStart(); 2742252723Sdim } 2743252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { 2744235633Sdim if (hasExplicitTemplateArgs()) 2745252723Sdim return getRAngleLoc(); 2746252723Sdim return getNameInfo().getLocEnd(); 2747199990Srdivacky } 2748199990Srdivacky 2749218893Sdim child_range children() { return child_range(); } 2750199990Srdivacky 2751199990Srdivacky static bool classof(const Stmt *T) { 2752199990Srdivacky return T->getStmtClass() == UnresolvedLookupExprClass; 2753199990Srdivacky } 2754199990Srdivacky}; 2755199990Srdivacky 2756193326Sed/// \brief A qualified reference to a name whose declaration cannot 2757193326Sed/// yet be resolved. 2758193326Sed/// 2759199990Srdivacky/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2760198893Srdivacky/// it expresses a reference to a declaration such as 2761193326Sed/// X<T>::value. The difference, however, is that an 2762199990Srdivacky/// DependentScopeDeclRefExpr node is used only within C++ templates when 2763193326Sed/// the qualification (e.g., X<T>::) refers to a dependent type. In 2764193326Sed/// this case, X<T>::value cannot resolve to a declaration because the 2765263509Sdim/// declaration will differ from one instantiation of X<T> to the 2766199990Srdivacky/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2767193326Sed/// qualifier (X<T>::) and the name of the entity being referenced 2768198893Srdivacky/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2769198893Srdivacky/// declaration can be found. 2770199990Srdivackyclass DependentScopeDeclRefExpr : public Expr { 2771219077Sdim /// \brief The nested-name-specifier that qualifies this unresolved 2772219077Sdim /// declaration name. 2773219077Sdim NestedNameSpecifierLoc QualifierLoc; 2774235633Sdim 2775263509Sdim /// \brief The name of the entity we will be referencing. 2776212904Sdim DeclarationNameInfo NameInfo; 2777193326Sed 2778235633Sdim /// \brief Whether the name includes info for explicit template 2779235633Sdim /// keyword and arguments. 2780235633Sdim bool HasTemplateKWAndArgsInfo; 2781198092Srdivacky 2782235633Sdim /// \brief Return the optional template keyword and arguments info. 2783235633Sdim ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2784235633Sdim if (!HasTemplateKWAndArgsInfo) return 0; 2785235633Sdim return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2786235633Sdim } 2787235633Sdim /// \brief Return the optional template keyword and arguments info. 2788235633Sdim const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2789235633Sdim return const_cast<DependentScopeDeclRefExpr*>(this) 2790235633Sdim ->getTemplateKWAndArgsInfo(); 2791235633Sdim } 2792235633Sdim 2793199990Srdivacky DependentScopeDeclRefExpr(QualType T, 2794219077Sdim NestedNameSpecifierLoc QualifierLoc, 2795235633Sdim SourceLocation TemplateKWLoc, 2796212904Sdim const DeclarationNameInfo &NameInfo, 2797218893Sdim const TemplateArgumentListInfo *Args); 2798199990Srdivacky 2799193326Sedpublic: 2800263509Sdim static DependentScopeDeclRefExpr *Create(const ASTContext &C, 2801219077Sdim NestedNameSpecifierLoc QualifierLoc, 2802235633Sdim SourceLocation TemplateKWLoc, 2803212904Sdim const DeclarationNameInfo &NameInfo, 2804235633Sdim const TemplateArgumentListInfo *TemplateArgs); 2805193326Sed 2806263509Sdim static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C, 2807235633Sdim bool HasTemplateKWAndArgsInfo, 2808210299Sed unsigned NumTemplateArgs); 2809210299Sed 2810193326Sed /// \brief Retrieve the name that this expression refers to. 2811212904Sdim const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2812193326Sed 2813212904Sdim /// \brief Retrieve the name that this expression refers to. 2814212904Sdim DeclarationName getDeclName() const { return NameInfo.getName(); } 2815212904Sdim 2816193326Sed /// \brief Retrieve the location of the name within the expression. 2817263509Sdim /// 2818263509Sdim /// For example, in "X<T>::value" this is the location of "value". 2819212904Sdim SourceLocation getLocation() const { return NameInfo.getLoc(); } 2820193326Sed 2821219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the 2822219077Sdim /// name, with source location information. 2823219077Sdim NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2824235633Sdim 2825193326Sed /// \brief Retrieve the nested-name-specifier that qualifies this 2826193326Sed /// declaration. 2827235633Sdim NestedNameSpecifier *getQualifier() const { 2828235633Sdim return QualifierLoc.getNestedNameSpecifier(); 2829219077Sdim } 2830193326Sed 2831235633Sdim /// \brief Retrieve the location of the template keyword preceding 2832235633Sdim /// this name, if any. 2833235633Sdim SourceLocation getTemplateKeywordLoc() const { 2834235633Sdim if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2835235633Sdim return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2836235633Sdim } 2837235633Sdim 2838235633Sdim /// \brief Retrieve the location of the left angle bracket starting the 2839235633Sdim /// explicit template argument list following the name, if any. 2840235633Sdim SourceLocation getLAngleLoc() const { 2841235633Sdim if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2842235633Sdim return getTemplateKWAndArgsInfo()->LAngleLoc; 2843235633Sdim } 2844235633Sdim 2845235633Sdim /// \brief Retrieve the location of the right angle bracket ending the 2846235633Sdim /// explicit template argument list following the name, if any. 2847235633Sdim SourceLocation getRAngleLoc() const { 2848235633Sdim if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2849235633Sdim return getTemplateKWAndArgsInfo()->RAngleLoc; 2850235633Sdim } 2851235633Sdim 2852235633Sdim /// Determines whether the name was preceded by the template keyword. 2853235633Sdim bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2854235633Sdim 2855199990Srdivacky /// Determines whether this lookup had explicit template arguments. 2856235633Sdim bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2857198092Srdivacky 2858199990Srdivacky // Note that, inconsistently with the explicit-template-argument AST 2859199990Srdivacky // nodes, users are *forbidden* from calling these methods on objects 2860199990Srdivacky // without explicit template arguments. 2861199990Srdivacky 2862226890Sdim ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2863210299Sed assert(hasExplicitTemplateArgs()); 2864226890Sdim return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 2865210299Sed } 2866210299Sed 2867199990Srdivacky /// Gets a reference to the explicit template argument list. 2868226890Sdim const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2869199990Srdivacky assert(hasExplicitTemplateArgs()); 2870226890Sdim return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2871193326Sed } 2872193326Sed 2873212904Sdim /// \brief Retrieves the optional explicit template arguments. 2874263509Sdim /// 2875212904Sdim /// This points to the same data as getExplicitTemplateArgs(), but 2876212904Sdim /// returns null if there are no explicit template arguments. 2877252723Sdim const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2878212904Sdim if (!hasExplicitTemplateArgs()) return 0; 2879212904Sdim return &getExplicitTemplateArgs(); 2880212904Sdim } 2881212904Sdim 2882199990Srdivacky /// \brief Copies the template arguments (if present) into the given 2883199990Srdivacky /// structure. 2884199990Srdivacky void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2885199990Srdivacky getExplicitTemplateArgs().copyInto(List); 2886193326Sed } 2887193326Sed 2888199990Srdivacky TemplateArgumentLoc const *getTemplateArgs() const { 2889199990Srdivacky return getExplicitTemplateArgs().getTemplateArgs(); 2890199990Srdivacky } 2891198092Srdivacky 2892199990Srdivacky unsigned getNumTemplateArgs() const { 2893199990Srdivacky return getExplicitTemplateArgs().NumTemplateArgs; 2894195341Sed } 2895198092Srdivacky 2896263509Sdim /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr, 2897263509Sdim /// and differs from getLocation().getStart(). 2898252723Sdim SourceLocation getLocStart() const LLVM_READONLY { 2899252723Sdim return QualifierLoc.getBeginLoc(); 2900252723Sdim } 2901252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { 2902199990Srdivacky if (hasExplicitTemplateArgs()) 2903252723Sdim return getRAngleLoc(); 2904252723Sdim return getLocation(); 2905195341Sed } 2906198092Srdivacky 2907198092Srdivacky static bool classof(const Stmt *T) { 2908199990Srdivacky return T->getStmtClass() == DependentScopeDeclRefExprClass; 2909195341Sed } 2910199990Srdivacky 2911218893Sdim child_range children() { return child_range(); } 2912218893Sdim 2913218893Sdim friend class ASTStmtReader; 2914218893Sdim friend class ASTStmtWriter; 2915195341Sed}; 2916198092Srdivacky 2917263509Sdim/// Represents an expression -- generally a full-expression -- that 2918218893Sdim/// introduces cleanups to be run at the end of the sub-expression's 2919218893Sdim/// evaluation. The most common source of expression-introduced 2920235633Sdim/// cleanups is temporary objects in C++, but several other kinds of 2921235633Sdim/// expressions can create cleanups, including basically every 2922235633Sdim/// call in ARC that returns an Objective-C pointer. 2923235633Sdim/// 2924235633Sdim/// This expression also tracks whether the sub-expression contains a 2925235633Sdim/// potentially-evaluated block literal. The lifetime of a block 2926235633Sdim/// literal is the extent of the enclosing scope. 2927218893Sdimclass ExprWithCleanups : public Expr { 2928235633Sdimpublic: 2929235633Sdim /// The type of objects that are kept in the cleanup. 2930235633Sdim /// It's useful to remember the set of blocks; we could also 2931235633Sdim /// remember the set of temporaries, but there's currently 2932235633Sdim /// no need. 2933235633Sdim typedef BlockDecl *CleanupObject; 2934235633Sdim 2935235633Sdimprivate: 2936193326Sed Stmt *SubExpr; 2937198092Srdivacky 2938235633Sdim ExprWithCleanups(EmptyShell, unsigned NumObjects); 2939235633Sdim ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 2940193326Sed 2941235633Sdim CleanupObject *getObjectsBuffer() { 2942235633Sdim return reinterpret_cast<CleanupObject*>(this + 1); 2943235633Sdim } 2944235633Sdim const CleanupObject *getObjectsBuffer() const { 2945235633Sdim return reinterpret_cast<const CleanupObject*>(this + 1); 2946235633Sdim } 2947235633Sdim friend class ASTStmtReader; 2948235633Sdim 2949193326Sedpublic: 2950263509Sdim static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty, 2951235633Sdim unsigned numObjects); 2952198092Srdivacky 2953263509Sdim static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr, 2954235633Sdim ArrayRef<CleanupObject> objects); 2955235633Sdim 2956235633Sdim ArrayRef<CleanupObject> getObjects() const { 2957235633Sdim return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2958193326Sed } 2959235633Sdim 2960235633Sdim unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 2961235633Sdim 2962235633Sdim CleanupObject getObject(unsigned i) const { 2963235633Sdim assert(i < getNumObjects() && "Index out of range"); 2964235633Sdim return getObjects()[i]; 2965193326Sed } 2966198092Srdivacky 2967193326Sed Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2968193326Sed const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 2969235633Sdim 2970263509Sdim /// As with any mutator of the AST, be very careful 2971235633Sdim /// when modifying an existing AST to preserve its invariants. 2972193326Sed void setSubExpr(Expr *E) { SubExpr = E; } 2973193326Sed 2974252723Sdim SourceLocation getLocStart() const LLVM_READONLY { 2975252723Sdim return SubExpr->getLocStart(); 2976198092Srdivacky } 2977252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 2978193326Sed 2979193326Sed // Implement isa/cast/dyncast/etc. 2980193326Sed static bool classof(const Stmt *T) { 2981218893Sdim return T->getStmtClass() == ExprWithCleanupsClass; 2982193326Sed } 2983193326Sed 2984193326Sed // Iterators 2985218893Sdim child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 2986193326Sed}; 2987193326Sed 2988193326Sed/// \brief Describes an explicit type conversion that uses functional 2989193326Sed/// notion but could not be resolved because one or more arguments are 2990193326Sed/// type-dependent. 2991193326Sed/// 2992193326Sed/// The explicit type conversions expressed by 2993245431Sdim/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>, 2994245431Sdim/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and 2995245431Sdim/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is 2996193326Sed/// type-dependent. For example, this would occur in a template such 2997193326Sed/// as: 2998193326Sed/// 2999193326Sed/// \code 3000193326Sed/// template<typename T, typename A1> 3001193326Sed/// inline T make_a(const A1& a1) { 3002193326Sed/// return T(a1); 3003193326Sed/// } 3004193326Sed/// \endcode 3005193326Sed/// 3006193326Sed/// When the returned expression is instantiated, it may resolve to a 3007193326Sed/// constructor call, conversion function call, or some kind of type 3008193326Sed/// conversion. 3009193326Sedclass CXXUnresolvedConstructExpr : public Expr { 3010193326Sed /// \brief The type being constructed. 3011218893Sdim TypeSourceInfo *Type; 3012235633Sdim 3013193326Sed /// \brief The location of the left parentheses ('('). 3014193326Sed SourceLocation LParenLoc; 3015193326Sed 3016193326Sed /// \brief The location of the right parentheses (')'). 3017193326Sed SourceLocation RParenLoc; 3018193326Sed 3019193326Sed /// \brief The number of arguments used to construct the type. 3020193326Sed unsigned NumArgs; 3021198092Srdivacky 3022218893Sdim CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 3023193326Sed SourceLocation LParenLoc, 3024245431Sdim ArrayRef<Expr*> Args, 3025193326Sed SourceLocation RParenLoc); 3026193326Sed 3027210299Sed CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 3028218893Sdim : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 3029210299Sed 3030218893Sdim friend class ASTStmtReader; 3031235633Sdim 3032193326Sedpublic: 3033263509Sdim static CXXUnresolvedConstructExpr *Create(const ASTContext &C, 3034218893Sdim TypeSourceInfo *Type, 3035193326Sed SourceLocation LParenLoc, 3036245431Sdim ArrayRef<Expr*> Args, 3037193326Sed SourceLocation RParenLoc); 3038193326Sed 3039263509Sdim static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C, 3040210299Sed unsigned NumArgs); 3041210299Sed 3042193326Sed /// \brief Retrieve the type that is being constructed, as specified 3043193326Sed /// in the source code. 3044218893Sdim QualType getTypeAsWritten() const { return Type->getType(); } 3045193326Sed 3046235633Sdim /// \brief Retrieve the type source information for the type being 3047218893Sdim /// constructed. 3048218893Sdim TypeSourceInfo *getTypeSourceInfo() const { return Type; } 3049235633Sdim 3050193326Sed /// \brief Retrieve the location of the left parentheses ('(') that 3051193326Sed /// precedes the argument list. 3052193326Sed SourceLocation getLParenLoc() const { return LParenLoc; } 3053193326Sed void setLParenLoc(SourceLocation L) { LParenLoc = L; } 3054193326Sed 3055193326Sed /// \brief Retrieve the location of the right parentheses (')') that 3056193326Sed /// follows the argument list. 3057193326Sed SourceLocation getRParenLoc() const { return RParenLoc; } 3058193326Sed void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3059193326Sed 3060193326Sed /// \brief Retrieve the number of arguments. 3061193326Sed unsigned arg_size() const { return NumArgs; } 3062193326Sed 3063193326Sed typedef Expr** arg_iterator; 3064193326Sed arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 3065193326Sed arg_iterator arg_end() { return arg_begin() + NumArgs; } 3066193326Sed 3067203955Srdivacky typedef const Expr* const * const_arg_iterator; 3068203955Srdivacky const_arg_iterator arg_begin() const { 3069203955Srdivacky return reinterpret_cast<const Expr* const *>(this + 1); 3070203955Srdivacky } 3071203955Srdivacky const_arg_iterator arg_end() const { 3072203955Srdivacky return arg_begin() + NumArgs; 3073203955Srdivacky } 3074203955Srdivacky 3075193326Sed Expr *getArg(unsigned I) { 3076193326Sed assert(I < NumArgs && "Argument index out-of-range"); 3077193326Sed return *(arg_begin() + I); 3078193326Sed } 3079193326Sed 3080203955Srdivacky const Expr *getArg(unsigned I) const { 3081203955Srdivacky assert(I < NumArgs && "Argument index out-of-range"); 3082203955Srdivacky return *(arg_begin() + I); 3083203955Srdivacky } 3084203955Srdivacky 3085210299Sed void setArg(unsigned I, Expr *E) { 3086210299Sed assert(I < NumArgs && "Argument index out-of-range"); 3087210299Sed *(arg_begin() + I) = E; 3088210299Sed } 3089210299Sed 3090252723Sdim SourceLocation getLocStart() const LLVM_READONLY; 3091263509Sdim SourceLocation getLocEnd() const LLVM_READONLY { 3092263509Sdim assert(RParenLoc.isValid() || NumArgs == 1); 3093263509Sdim return RParenLoc.isValid() ? RParenLoc : getArg(0)->getLocEnd(); 3094263509Sdim } 3095235633Sdim 3096198092Srdivacky static bool classof(const Stmt *T) { 3097193326Sed return T->getStmtClass() == CXXUnresolvedConstructExprClass; 3098193326Sed } 3099193326Sed 3100193326Sed // Iterators 3101218893Sdim child_range children() { 3102218893Sdim Stmt **begin = reinterpret_cast<Stmt**>(this+1); 3103218893Sdim return child_range(begin, begin + NumArgs); 3104218893Sdim } 3105193326Sed}; 3106193326Sed 3107199990Srdivacky/// \brief Represents a C++ member access expression where the actual 3108199990Srdivacky/// member referenced could not be resolved because the base 3109199990Srdivacky/// expression or the member name was dependent. 3110200583Srdivacky/// 3111200583Srdivacky/// Like UnresolvedMemberExprs, these can be either implicit or 3112200583Srdivacky/// explicit accesses. It is only possible to get one of these with 3113200583Srdivacky/// an implicit access if a qualifier is provided. 3114199990Srdivackyclass CXXDependentScopeMemberExpr : public Expr { 3115193326Sed /// \brief The expression for the base pointer or class reference, 3116200583Srdivacky /// e.g., the \c x in x.f. Can be null in implicit accesses. 3117193326Sed Stmt *Base; 3118198092Srdivacky 3119200583Srdivacky /// \brief The type of the base expression. Never null, even for 3120200583Srdivacky /// implicit accesses. 3121200583Srdivacky QualType BaseType; 3122200583Srdivacky 3123193326Sed /// \brief Whether this member expression used the '->' operator or 3124193326Sed /// the '.' operator. 3125198092Srdivacky bool IsArrow : 1; 3126193326Sed 3127235633Sdim /// \brief Whether this member expression has info for explicit template 3128235633Sdim /// keyword and arguments. 3129235633Sdim bool HasTemplateKWAndArgsInfo : 1; 3130198092Srdivacky 3131193326Sed /// \brief The location of the '->' or '.' operator. 3132193326Sed SourceLocation OperatorLoc; 3133193326Sed 3134198092Srdivacky /// \brief The nested-name-specifier that precedes the member name, if any. 3135221345Sdim NestedNameSpecifierLoc QualifierLoc; 3136198092Srdivacky 3137198092Srdivacky /// \brief In a qualified member access expression such as t->Base::f, this 3138198092Srdivacky /// member stores the resolves of name lookup in the context of the member 3139198092Srdivacky /// access expression, to be used at instantiation time. 3140198092Srdivacky /// 3141221345Sdim /// FIXME: This member, along with the QualifierLoc, could 3142198092Srdivacky /// be stuck into a structure that is optionally allocated at the end of 3143199990Srdivacky /// the CXXDependentScopeMemberExpr, to save space in the common case. 3144198092Srdivacky NamedDecl *FirstQualifierFoundInScope; 3145198092Srdivacky 3146193326Sed /// \brief The member to which this member expression refers, which 3147193326Sed /// can be name, overloaded operator, or destructor. 3148263509Sdim /// 3149198092Srdivacky /// FIXME: could also be a template-id 3150212904Sdim DeclarationNameInfo MemberNameInfo; 3151193326Sed 3152235633Sdim /// \brief Return the optional template keyword and arguments info. 3153235633Sdim ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 3154235633Sdim if (!HasTemplateKWAndArgsInfo) return 0; 3155235633Sdim return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 3156235633Sdim } 3157235633Sdim /// \brief Return the optional template keyword and arguments info. 3158235633Sdim const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 3159235633Sdim return const_cast<CXXDependentScopeMemberExpr*>(this) 3160235633Sdim ->getTemplateKWAndArgsInfo(); 3161235633Sdim } 3162235633Sdim 3163263509Sdim CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base, 3164263509Sdim QualType BaseType, bool IsArrow, 3165263509Sdim SourceLocation OperatorLoc, 3166263509Sdim NestedNameSpecifierLoc QualifierLoc, 3167263509Sdim SourceLocation TemplateKWLoc, 3168263509Sdim NamedDecl *FirstQualifierFoundInScope, 3169263509Sdim DeclarationNameInfo MemberNameInfo, 3170263509Sdim const TemplateArgumentListInfo *TemplateArgs); 3171198092Srdivacky 3172193326Sedpublic: 3173263509Sdim CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base, 3174263509Sdim QualType BaseType, bool IsArrow, 3175218893Sdim SourceLocation OperatorLoc, 3176221345Sdim NestedNameSpecifierLoc QualifierLoc, 3177218893Sdim NamedDecl *FirstQualifierFoundInScope, 3178218893Sdim DeclarationNameInfo MemberNameInfo); 3179193326Sed 3180199990Srdivacky static CXXDependentScopeMemberExpr * 3181263509Sdim Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow, 3182263509Sdim SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, 3183263509Sdim SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, 3184212904Sdim DeclarationNameInfo MemberNameInfo, 3185199990Srdivacky const TemplateArgumentListInfo *TemplateArgs); 3186198092Srdivacky 3187210299Sed static CXXDependentScopeMemberExpr * 3188263509Sdim CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo, 3189218893Sdim unsigned NumTemplateArgs); 3190210299Sed 3191200583Srdivacky /// \brief True if this is an implicit access, i.e. one in which the 3192200583Srdivacky /// member being accessed was not written in the source. The source 3193200583Srdivacky /// location of the operator is invalid in this case. 3194221345Sdim bool isImplicitAccess() const; 3195200583Srdivacky 3196193326Sed /// \brief Retrieve the base object of this member expressions, 3197193326Sed /// e.g., the \c x in \c x.m. 3198200583Srdivacky Expr *getBase() const { 3199200583Srdivacky assert(!isImplicitAccess()); 3200200583Srdivacky return cast<Expr>(Base); 3201200583Srdivacky } 3202193326Sed 3203200583Srdivacky QualType getBaseType() const { return BaseType; } 3204200583Srdivacky 3205193326Sed /// \brief Determine whether this member expression used the '->' 3206193326Sed /// operator; otherwise, it used the '.' operator. 3207193326Sed bool isArrow() const { return IsArrow; } 3208193326Sed 3209193326Sed /// \brief Retrieve the location of the '->' or '.' operator. 3210193326Sed SourceLocation getOperatorLoc() const { return OperatorLoc; } 3211193326Sed 3212198092Srdivacky /// \brief Retrieve the nested-name-specifier that qualifies the member 3213198092Srdivacky /// name. 3214235633Sdim NestedNameSpecifier *getQualifier() const { 3215235633Sdim return QualifierLoc.getNestedNameSpecifier(); 3216221345Sdim } 3217198092Srdivacky 3218221345Sdim /// \brief Retrieve the nested-name-specifier that qualifies the member 3219221345Sdim /// name, with source location information. 3220221345Sdim NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 3221235633Sdim 3222235633Sdim 3223198092Srdivacky /// \brief Retrieve the first part of the nested-name-specifier that was 3224198092Srdivacky /// found in the scope of the member access expression when the member access 3225198092Srdivacky /// was initially parsed. 3226198092Srdivacky /// 3227198092Srdivacky /// This function only returns a useful result when member access expression 3228198092Srdivacky /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 3229198092Srdivacky /// returned by this function describes what was found by unqualified name 3230198092Srdivacky /// lookup for the identifier "Base" within the scope of the member access 3231198092Srdivacky /// expression itself. At template instantiation time, this information is 3232198092Srdivacky /// combined with the results of name lookup into the type of the object 3233198092Srdivacky /// expression itself (the class type of x). 3234198092Srdivacky NamedDecl *getFirstQualifierFoundInScope() const { 3235198092Srdivacky return FirstQualifierFoundInScope; 3236198092Srdivacky } 3237198092Srdivacky 3238193326Sed /// \brief Retrieve the name of the member that this expression 3239193326Sed /// refers to. 3240212904Sdim const DeclarationNameInfo &getMemberNameInfo() const { 3241212904Sdim return MemberNameInfo; 3242212904Sdim } 3243193326Sed 3244212904Sdim /// \brief Retrieve the name of the member that this expression 3245212904Sdim /// refers to. 3246212904Sdim DeclarationName getMember() const { return MemberNameInfo.getName(); } 3247212904Sdim 3248193326Sed // \brief Retrieve the location of the name of the member that this 3249193326Sed // expression refers to. 3250212904Sdim SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 3251193326Sed 3252235633Sdim /// \brief Retrieve the location of the template keyword preceding the 3253235633Sdim /// member name, if any. 3254235633Sdim SourceLocation getTemplateKeywordLoc() const { 3255235633Sdim if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3256235633Sdim return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 3257235633Sdim } 3258235633Sdim 3259235633Sdim /// \brief Retrieve the location of the left angle bracket starting the 3260235633Sdim /// explicit template argument list following the member name, if any. 3261235633Sdim SourceLocation getLAngleLoc() const { 3262235633Sdim if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3263235633Sdim return getTemplateKWAndArgsInfo()->LAngleLoc; 3264235633Sdim } 3265235633Sdim 3266235633Sdim /// \brief Retrieve the location of the right angle bracket ending the 3267235633Sdim /// explicit template argument list following the member name, if any. 3268235633Sdim SourceLocation getRAngleLoc() const { 3269235633Sdim if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3270235633Sdim return getTemplateKWAndArgsInfo()->RAngleLoc; 3271235633Sdim } 3272235633Sdim 3273235633Sdim /// Determines whether the member name was preceded by the template keyword. 3274235633Sdim bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 3275235633Sdim 3276198092Srdivacky /// \brief Determines whether this member expression actually had a C++ 3277198092Srdivacky /// template argument list explicitly specified, e.g., x.f<int>. 3278235633Sdim bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 3279198092Srdivacky 3280210299Sed /// \brief Retrieve the explicit template argument list that followed the 3281210299Sed /// member template name, if any. 3282226890Sdim ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 3283235633Sdim assert(hasExplicitTemplateArgs()); 3284226890Sdim return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 3285210299Sed } 3286210299Sed 3287210299Sed /// \brief Retrieve the explicit template argument list that followed the 3288210299Sed /// member template name, if any. 3289226890Sdim const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 3290210299Sed return const_cast<CXXDependentScopeMemberExpr *>(this) 3291212904Sdim ->getExplicitTemplateArgs(); 3292210299Sed } 3293210299Sed 3294212904Sdim /// \brief Retrieves the optional explicit template arguments. 3295263509Sdim /// 3296212904Sdim /// This points to the same data as getExplicitTemplateArgs(), but 3297212904Sdim /// returns null if there are no explicit template arguments. 3298252723Sdim const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 3299212904Sdim if (!hasExplicitTemplateArgs()) return 0; 3300212904Sdim return &getExplicitTemplateArgs(); 3301212904Sdim } 3302212904Sdim 3303199990Srdivacky /// \brief Copies the template arguments (if present) into the given 3304199990Srdivacky /// structure. 3305199990Srdivacky void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 3306212904Sdim getExplicitTemplateArgs().copyInto(List); 3307199990Srdivacky } 3308199990Srdivacky 3309210299Sed /// \brief Initializes the template arguments using the given structure. 3310210299Sed void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 3311212904Sdim getExplicitTemplateArgs().initializeFrom(List); 3312210299Sed } 3313210299Sed 3314198092Srdivacky /// \brief Retrieve the template arguments provided as part of this 3315198092Srdivacky /// template-id. 3316198893Srdivacky const TemplateArgumentLoc *getTemplateArgs() const { 3317212904Sdim return getExplicitTemplateArgs().getTemplateArgs(); 3318198092Srdivacky } 3319198092Srdivacky 3320198092Srdivacky /// \brief Retrieve the number of template arguments provided as part of this 3321198092Srdivacky /// template-id. 3322198092Srdivacky unsigned getNumTemplateArgs() const { 3323212904Sdim return getExplicitTemplateArgs().NumTemplateArgs; 3324198092Srdivacky } 3325198092Srdivacky 3326252723Sdim SourceLocation getLocStart() const LLVM_READONLY { 3327200583Srdivacky if (!isImplicitAccess()) 3328252723Sdim return Base->getLocStart(); 3329252723Sdim if (getQualifier()) 3330252723Sdim return getQualifierLoc().getBeginLoc(); 3331252723Sdim return MemberNameInfo.getBeginLoc(); 3332198092Srdivacky 3333252723Sdim } 3334252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { 3335200583Srdivacky if (hasExplicitTemplateArgs()) 3336252723Sdim return getRAngleLoc(); 3337252723Sdim return MemberNameInfo.getEndLoc(); 3338193326Sed } 3339198092Srdivacky 3340198092Srdivacky static bool classof(const Stmt *T) { 3341199990Srdivacky return T->getStmtClass() == CXXDependentScopeMemberExprClass; 3342193326Sed } 3343193326Sed 3344193326Sed // Iterators 3345218893Sdim child_range children() { 3346218893Sdim if (isImplicitAccess()) return child_range(); 3347218893Sdim return child_range(&Base, &Base + 1); 3348218893Sdim } 3349218893Sdim 3350218893Sdim friend class ASTStmtReader; 3351218893Sdim friend class ASTStmtWriter; 3352193326Sed}; 3353193326Sed 3354199990Srdivacky/// \brief Represents a C++ member access expression for which lookup 3355200583Srdivacky/// produced a set of overloaded functions. 3356200583Srdivacky/// 3357200583Srdivacky/// The member access may be explicit or implicit: 3358263509Sdim/// \code 3359200583Srdivacky/// struct A { 3360200583Srdivacky/// int a, b; 3361200583Srdivacky/// int explicitAccess() { return this->a + this->A::b; } 3362200583Srdivacky/// int implicitAccess() { return a + A::b; } 3363200583Srdivacky/// }; 3364263509Sdim/// \endcode 3365200583Srdivacky/// 3366200583Srdivacky/// In the final AST, an explicit access always becomes a MemberExpr. 3367200583Srdivacky/// An implicit access may become either a MemberExpr or a 3368200583Srdivacky/// DeclRefExpr, depending on whether the member is static. 3369203955Srdivackyclass UnresolvedMemberExpr : public OverloadExpr { 3370203955Srdivacky /// \brief Whether this member expression used the '->' operator or 3371203955Srdivacky /// the '.' operator. 3372203955Srdivacky bool IsArrow : 1; 3373199990Srdivacky 3374203955Srdivacky /// \brief Whether the lookup results contain an unresolved using 3375203955Srdivacky /// declaration. 3376203955Srdivacky bool HasUnresolvedUsing : 1; 3377203955Srdivacky 3378199990Srdivacky /// \brief The expression for the base pointer or class reference, 3379263509Sdim /// e.g., the \c x in x.f. 3380263509Sdim /// 3381263509Sdim /// This can be null if this is an 'unbased' member expression. 3382199990Srdivacky Stmt *Base; 3383199990Srdivacky 3384263509Sdim /// \brief The type of the base expression; never null. 3385200583Srdivacky QualType BaseType; 3386200583Srdivacky 3387199990Srdivacky /// \brief The location of the '->' or '.' operator. 3388199990Srdivacky SourceLocation OperatorLoc; 3389199990Srdivacky 3390263509Sdim UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing, 3391200583Srdivacky Expr *Base, QualType BaseType, bool IsArrow, 3392199990Srdivacky SourceLocation OperatorLoc, 3393221345Sdim NestedNameSpecifierLoc QualifierLoc, 3394235633Sdim SourceLocation TemplateKWLoc, 3395212904Sdim const DeclarationNameInfo &MemberNameInfo, 3396208600Srdivacky const TemplateArgumentListInfo *TemplateArgs, 3397208600Srdivacky UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3398235633Sdim 3399210299Sed UnresolvedMemberExpr(EmptyShell Empty) 3400210299Sed : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 3401210299Sed HasUnresolvedUsing(false), Base(0) { } 3402199990Srdivacky 3403221345Sdim friend class ASTStmtReader; 3404235633Sdim 3405199990Srdivackypublic: 3406199990Srdivacky static UnresolvedMemberExpr * 3407263509Sdim Create(const ASTContext &C, bool HasUnresolvedUsing, 3408200583Srdivacky Expr *Base, QualType BaseType, bool IsArrow, 3409199990Srdivacky SourceLocation OperatorLoc, 3410221345Sdim NestedNameSpecifierLoc QualifierLoc, 3411235633Sdim SourceLocation TemplateKWLoc, 3412212904Sdim const DeclarationNameInfo &MemberNameInfo, 3413208600Srdivacky const TemplateArgumentListInfo *TemplateArgs, 3414208600Srdivacky UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3415199990Srdivacky 3416210299Sed static UnresolvedMemberExpr * 3417263509Sdim CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo, 3418218893Sdim unsigned NumTemplateArgs); 3419210299Sed 3420263509Sdim /// \brief True if this is an implicit access, i.e., one in which the 3421263509Sdim /// member being accessed was not written in the source. 3422263509Sdim /// 3423263509Sdim /// The source location of the operator is invalid in this case. 3424221345Sdim bool isImplicitAccess() const; 3425200583Srdivacky 3426199990Srdivacky /// \brief Retrieve the base object of this member expressions, 3427199990Srdivacky /// e.g., the \c x in \c x.m. 3428200583Srdivacky Expr *getBase() { 3429200583Srdivacky assert(!isImplicitAccess()); 3430200583Srdivacky return cast<Expr>(Base); 3431200583Srdivacky } 3432203955Srdivacky const Expr *getBase() const { 3433203955Srdivacky assert(!isImplicitAccess()); 3434203955Srdivacky return cast<Expr>(Base); 3435203955Srdivacky } 3436199990Srdivacky 3437200583Srdivacky QualType getBaseType() const { return BaseType; } 3438200583Srdivacky 3439210299Sed /// \brief Determine whether the lookup results contain an unresolved using 3440210299Sed /// declaration. 3441210299Sed bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3442210299Sed 3443199990Srdivacky /// \brief Determine whether this member expression used the '->' 3444199990Srdivacky /// operator; otherwise, it used the '.' operator. 3445199990Srdivacky bool isArrow() const { return IsArrow; } 3446199990Srdivacky 3447199990Srdivacky /// \brief Retrieve the location of the '->' or '.' operator. 3448199990Srdivacky SourceLocation getOperatorLoc() const { return OperatorLoc; } 3449199990Srdivacky 3450263509Sdim /// \brief Retrieve the naming class of this lookup. 3451203955Srdivacky CXXRecordDecl *getNamingClass() const; 3452199990Srdivacky 3453212904Sdim /// \brief Retrieve the full name info for the member that this expression 3454212904Sdim /// refers to. 3455212904Sdim const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 3456212904Sdim 3457199990Srdivacky /// \brief Retrieve the name of the member that this expression 3458199990Srdivacky /// refers to. 3459203955Srdivacky DeclarationName getMemberName() const { return getName(); } 3460199990Srdivacky 3461199990Srdivacky // \brief Retrieve the location of the name of the member that this 3462199990Srdivacky // expression refers to. 3463203955Srdivacky SourceLocation getMemberLoc() const { return getNameLoc(); } 3464199990Srdivacky 3465263509Sdim // \brief Return the preferred location (the member name) for the arrow when 3466263509Sdim // diagnosing a problem with this expression. 3467263509Sdim SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); } 3468263509Sdim 3469252723Sdim SourceLocation getLocStart() const LLVM_READONLY { 3470200583Srdivacky if (!isImplicitAccess()) 3471252723Sdim return Base->getLocStart(); 3472252723Sdim if (NestedNameSpecifierLoc l = getQualifierLoc()) 3473252723Sdim return l.getBeginLoc(); 3474252723Sdim return getMemberNameInfo().getLocStart(); 3475252723Sdim } 3476252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { 3477199990Srdivacky if (hasExplicitTemplateArgs()) 3478252723Sdim return getRAngleLoc(); 3479252723Sdim return getMemberNameInfo().getLocEnd(); 3480199990Srdivacky } 3481199990Srdivacky 3482199990Srdivacky static bool classof(const Stmt *T) { 3483199990Srdivacky return T->getStmtClass() == UnresolvedMemberExprClass; 3484199990Srdivacky } 3485199990Srdivacky 3486199990Srdivacky // Iterators 3487218893Sdim child_range children() { 3488218893Sdim if (isImplicitAccess()) return child_range(); 3489218893Sdim return child_range(&Base, &Base + 1); 3490218893Sdim } 3491199990Srdivacky}; 3492199990Srdivacky 3493263509Sdim/// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]). 3494218893Sdim/// 3495218893Sdim/// The noexcept expression tests whether a given expression might throw. Its 3496218893Sdim/// result is a boolean constant. 3497218893Sdimclass CXXNoexceptExpr : public Expr { 3498218893Sdim bool Value : 1; 3499218893Sdim Stmt *Operand; 3500218893Sdim SourceRange Range; 3501218893Sdim 3502218893Sdim friend class ASTStmtReader; 3503218893Sdim 3504218893Sdimpublic: 3505218893Sdim CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 3506218893Sdim SourceLocation Keyword, SourceLocation RParen) 3507218893Sdim : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3508218893Sdim /*TypeDependent*/false, 3509218893Sdim /*ValueDependent*/Val == CT_Dependent, 3510224145Sdim Val == CT_Dependent || Operand->isInstantiationDependent(), 3511218893Sdim Operand->containsUnexpandedParameterPack()), 3512218893Sdim Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 3513218893Sdim { } 3514218893Sdim 3515218893Sdim CXXNoexceptExpr(EmptyShell Empty) 3516218893Sdim : Expr(CXXNoexceptExprClass, Empty) 3517218893Sdim { } 3518218893Sdim 3519218893Sdim Expr *getOperand() const { return static_cast<Expr*>(Operand); } 3520218893Sdim 3521252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 3522252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 3523235633Sdim SourceRange getSourceRange() const LLVM_READONLY { return Range; } 3524218893Sdim 3525218893Sdim bool getValue() const { return Value; } 3526218893Sdim 3527218893Sdim static bool classof(const Stmt *T) { 3528218893Sdim return T->getStmtClass() == CXXNoexceptExprClass; 3529218893Sdim } 3530218893Sdim 3531218893Sdim // Iterators 3532218893Sdim child_range children() { return child_range(&Operand, &Operand + 1); } 3533218893Sdim}; 3534218893Sdim 3535263509Sdim/// \brief Represents a C++11 pack expansion that produces a sequence of 3536218893Sdim/// expressions. 3537218893Sdim/// 3538218893Sdim/// A pack expansion expression contains a pattern (which itself is an 3539218893Sdim/// expression) followed by an ellipsis. For example: 3540218893Sdim/// 3541218893Sdim/// \code 3542218893Sdim/// template<typename F, typename ...Types> 3543218893Sdim/// void forward(F f, Types &&...args) { 3544218893Sdim/// f(static_cast<Types&&>(args)...); 3545218893Sdim/// } 3546218893Sdim/// \endcode 3547218893Sdim/// 3548218893Sdim/// Here, the argument to the function object \c f is a pack expansion whose 3549235633Sdim/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3550218893Sdim/// template is instantiated, the pack expansion will instantiate to zero or 3551218893Sdim/// or more function arguments to the function object \c f. 3552218893Sdimclass PackExpansionExpr : public Expr { 3553218893Sdim SourceLocation EllipsisLoc; 3554235633Sdim 3555218893Sdim /// \brief The number of expansions that will be produced by this pack 3556218893Sdim /// expansion expression, if known. 3557218893Sdim /// 3558218893Sdim /// When zero, the number of expansions is not known. Otherwise, this value 3559218893Sdim /// is the number of expansions + 1. 3560218893Sdim unsigned NumExpansions; 3561235633Sdim 3562218893Sdim Stmt *Pattern; 3563235633Sdim 3564218893Sdim friend class ASTStmtReader; 3565218893Sdim friend class ASTStmtWriter; 3566235633Sdim 3567218893Sdimpublic: 3568218893Sdim PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 3569252723Sdim Optional<unsigned> NumExpansions) 3570235633Sdim : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3571235633Sdim Pattern->getObjectKind(), /*TypeDependent=*/true, 3572224145Sdim /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3573224145Sdim /*ContainsUnexpandedParameterPack=*/false), 3574218893Sdim EllipsisLoc(EllipsisLoc), 3575218893Sdim NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3576218893Sdim Pattern(Pattern) { } 3577218893Sdim 3578218893Sdim PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3579235633Sdim 3580218893Sdim /// \brief Retrieve the pattern of the pack expansion. 3581218893Sdim Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3582218893Sdim 3583218893Sdim /// \brief Retrieve the pattern of the pack expansion. 3584218893Sdim const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3585218893Sdim 3586218893Sdim /// \brief Retrieve the location of the ellipsis that describes this pack 3587218893Sdim /// expansion. 3588218893Sdim SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3589235633Sdim 3590235633Sdim /// \brief Determine the number of expansions that will be produced when 3591218893Sdim /// this pack expansion is instantiated, if already known. 3592252723Sdim Optional<unsigned> getNumExpansions() const { 3593218893Sdim if (NumExpansions) 3594218893Sdim return NumExpansions - 1; 3595235633Sdim 3596252723Sdim return None; 3597218893Sdim } 3598235633Sdim 3599252723Sdim SourceLocation getLocStart() const LLVM_READONLY { 3600252723Sdim return Pattern->getLocStart(); 3601218893Sdim } 3602252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; } 3603218893Sdim 3604218893Sdim static bool classof(const Stmt *T) { 3605218893Sdim return T->getStmtClass() == PackExpansionExprClass; 3606218893Sdim } 3607235633Sdim 3608218893Sdim // Iterators 3609218893Sdim child_range children() { 3610218893Sdim return child_range(&Pattern, &Pattern + 1); 3611218893Sdim } 3612218893Sdim}; 3613235633Sdim 3614235633Sdiminline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3615235633Sdim if (!HasTemplateKWAndArgsInfo) return 0; 3616203955Srdivacky if (isa<UnresolvedLookupExpr>(this)) 3617235633Sdim return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3618235633Sdim (cast<UnresolvedLookupExpr>(this) + 1); 3619203955Srdivacky else 3620235633Sdim return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3621235633Sdim (cast<UnresolvedMemberExpr>(this) + 1); 3622203955Srdivacky} 3623203955Srdivacky 3624235633Sdim/// \brief Represents an expression that computes the length of a parameter 3625218893Sdim/// pack. 3626218893Sdim/// 3627218893Sdim/// \code 3628218893Sdim/// template<typename ...Types> 3629218893Sdim/// struct count { 3630218893Sdim/// static const unsigned value = sizeof...(Types); 3631218893Sdim/// }; 3632218893Sdim/// \endcode 3633218893Sdimclass SizeOfPackExpr : public Expr { 3634263509Sdim /// \brief The location of the \c sizeof keyword. 3635218893Sdim SourceLocation OperatorLoc; 3636235633Sdim 3637218893Sdim /// \brief The location of the name of the parameter pack. 3638218893Sdim SourceLocation PackLoc; 3639235633Sdim 3640218893Sdim /// \brief The location of the closing parenthesis. 3641218893Sdim SourceLocation RParenLoc; 3642235633Sdim 3643218893Sdim /// \brief The length of the parameter pack, if known. 3644218893Sdim /// 3645218893Sdim /// When this expression is value-dependent, the length of the parameter pack 3646218893Sdim /// is unknown. When this expression is not value-dependent, the length is 3647218893Sdim /// known. 3648218893Sdim unsigned Length; 3649235633Sdim 3650218893Sdim /// \brief The parameter pack itself. 3651218893Sdim NamedDecl *Pack; 3652235633Sdim 3653218893Sdim friend class ASTStmtReader; 3654218893Sdim friend class ASTStmtWriter; 3655235633Sdim 3656218893Sdimpublic: 3657263509Sdim /// \brief Create a value-dependent expression that computes the length of 3658218893Sdim /// the given parameter pack. 3659235633Sdim SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3660218893Sdim SourceLocation PackLoc, SourceLocation RParenLoc) 3661218893Sdim : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3662218893Sdim /*TypeDependent=*/false, /*ValueDependent=*/true, 3663224145Sdim /*InstantiationDependent=*/true, 3664218893Sdim /*ContainsUnexpandedParameterPack=*/false), 3665218893Sdim OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3666218893Sdim Length(0), Pack(Pack) { } 3667218893Sdim 3668263509Sdim /// \brief Create an expression that computes the length of 3669218893Sdim /// the given parameter pack, which is already known. 3670235633Sdim SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3671218893Sdim SourceLocation PackLoc, SourceLocation RParenLoc, 3672218893Sdim unsigned Length) 3673218893Sdim : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3674218893Sdim /*TypeDependent=*/false, /*ValueDependent=*/false, 3675224145Sdim /*InstantiationDependent=*/false, 3676218893Sdim /*ContainsUnexpandedParameterPack=*/false), 3677218893Sdim OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3678218893Sdim Length(Length), Pack(Pack) { } 3679218893Sdim 3680218893Sdim /// \brief Create an empty expression. 3681218893Sdim SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3682235633Sdim 3683218893Sdim /// \brief Determine the location of the 'sizeof' keyword. 3684218893Sdim SourceLocation getOperatorLoc() const { return OperatorLoc; } 3685218893Sdim 3686218893Sdim /// \brief Determine the location of the parameter pack. 3687218893Sdim SourceLocation getPackLoc() const { return PackLoc; } 3688235633Sdim 3689218893Sdim /// \brief Determine the location of the right parenthesis. 3690218893Sdim SourceLocation getRParenLoc() const { return RParenLoc; } 3691235633Sdim 3692218893Sdim /// \brief Retrieve the parameter pack. 3693218893Sdim NamedDecl *getPack() const { return Pack; } 3694235633Sdim 3695218893Sdim /// \brief Retrieve the length of the parameter pack. 3696218893Sdim /// 3697235633Sdim /// This routine may only be invoked when the expression is not 3698218893Sdim /// value-dependent. 3699218893Sdim unsigned getPackLength() const { 3700235633Sdim assert(!isValueDependent() && 3701218893Sdim "Cannot get the length of a value-dependent pack size expression"); 3702218893Sdim return Length; 3703218893Sdim } 3704235633Sdim 3705252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; } 3706252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 3707235633Sdim 3708218893Sdim static bool classof(const Stmt *T) { 3709218893Sdim return T->getStmtClass() == SizeOfPackExprClass; 3710218893Sdim } 3711235633Sdim 3712218893Sdim // Iterators 3713218893Sdim child_range children() { return child_range(); } 3714218893Sdim}; 3715218893Sdim 3716224145Sdim/// \brief Represents a reference to a non-type template parameter 3717224145Sdim/// that has been substituted with a template argument. 3718224145Sdimclass SubstNonTypeTemplateParmExpr : public Expr { 3719224145Sdim /// \brief The replaced parameter. 3720224145Sdim NonTypeTemplateParmDecl *Param; 3721224145Sdim 3722224145Sdim /// \brief The replacement expression. 3723224145Sdim Stmt *Replacement; 3724224145Sdim 3725224145Sdim /// \brief The location of the non-type template parameter reference. 3726224145Sdim SourceLocation NameLoc; 3727224145Sdim 3728224145Sdim friend class ASTReader; 3729224145Sdim friend class ASTStmtReader; 3730235633Sdim explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 3731224145Sdim : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 3732224145Sdim 3733224145Sdimpublic: 3734235633Sdim SubstNonTypeTemplateParmExpr(QualType type, 3735224145Sdim ExprValueKind valueKind, 3736224145Sdim SourceLocation loc, 3737224145Sdim NonTypeTemplateParmDecl *param, 3738224145Sdim Expr *replacement) 3739224145Sdim : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 3740224145Sdim replacement->isTypeDependent(), replacement->isValueDependent(), 3741224145Sdim replacement->isInstantiationDependent(), 3742224145Sdim replacement->containsUnexpandedParameterPack()), 3743224145Sdim Param(param), Replacement(replacement), NameLoc(loc) {} 3744224145Sdim 3745224145Sdim SourceLocation getNameLoc() const { return NameLoc; } 3746252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3747252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3748224145Sdim 3749224145Sdim Expr *getReplacement() const { return cast<Expr>(Replacement); } 3750235633Sdim 3751224145Sdim NonTypeTemplateParmDecl *getParameter() const { return Param; } 3752224145Sdim 3753224145Sdim static bool classof(const Stmt *s) { 3754224145Sdim return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 3755224145Sdim } 3756235633Sdim 3757224145Sdim // Iterators 3758224145Sdim child_range children() { return child_range(&Replacement, &Replacement+1); } 3759224145Sdim}; 3760224145Sdim 3761218893Sdim/// \brief Represents a reference to a non-type template parameter pack that 3762218893Sdim/// has been substituted with a non-template argument pack. 3763218893Sdim/// 3764218893Sdim/// When a pack expansion in the source code contains multiple parameter packs 3765218893Sdim/// and those parameter packs correspond to different levels of template 3766245431Sdim/// parameter lists, this node is used to represent a non-type template 3767218893Sdim/// parameter pack from an outer level, which has already had its argument pack 3768218893Sdim/// substituted but that still lives within a pack expansion that itself 3769218893Sdim/// could not be instantiated. When actually performing a substitution into 3770218893Sdim/// that pack expansion (e.g., when all template parameters have corresponding 3771218893Sdim/// arguments), this type will be replaced with the appropriate underlying 3772218893Sdim/// expression at the current pack substitution index. 3773218893Sdimclass SubstNonTypeTemplateParmPackExpr : public Expr { 3774218893Sdim /// \brief The non-type template parameter pack itself. 3775218893Sdim NonTypeTemplateParmDecl *Param; 3776235633Sdim 3777218893Sdim /// \brief A pointer to the set of template arguments that this 3778218893Sdim /// parameter pack is instantiated with. 3779218893Sdim const TemplateArgument *Arguments; 3780235633Sdim 3781218893Sdim /// \brief The number of template arguments in \c Arguments. 3782218893Sdim unsigned NumArguments; 3783235633Sdim 3784218893Sdim /// \brief The location of the non-type template parameter pack reference. 3785218893Sdim SourceLocation NameLoc; 3786235633Sdim 3787224145Sdim friend class ASTReader; 3788218893Sdim friend class ASTStmtReader; 3789235633Sdim explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 3790224145Sdim : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3791235633Sdim 3792218893Sdimpublic: 3793235633Sdim SubstNonTypeTemplateParmPackExpr(QualType T, 3794218893Sdim NonTypeTemplateParmDecl *Param, 3795218893Sdim SourceLocation NameLoc, 3796218893Sdim const TemplateArgument &ArgPack); 3797235633Sdim 3798218893Sdim /// \brief Retrieve the non-type template parameter pack being substituted. 3799218893Sdim NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3800218893Sdim 3801218893Sdim /// \brief Retrieve the location of the parameter pack name. 3802218893Sdim SourceLocation getParameterPackLocation() const { return NameLoc; } 3803235633Sdim 3804218893Sdim /// \brief Retrieve the template argument pack containing the substituted 3805218893Sdim /// template arguments. 3806218893Sdim TemplateArgument getArgumentPack() const; 3807218893Sdim 3808252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3809252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3810235633Sdim 3811218893Sdim static bool classof(const Stmt *T) { 3812218893Sdim return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3813218893Sdim } 3814235633Sdim 3815218893Sdim // Iterators 3816218893Sdim child_range children() { return child_range(); } 3817218893Sdim}; 3818224145Sdim 3819245431Sdim/// \brief Represents a reference to a function parameter pack that has been 3820245431Sdim/// substituted but not yet expanded. 3821245431Sdim/// 3822245431Sdim/// When a pack expansion contains multiple parameter packs at different levels, 3823245431Sdim/// this node is used to represent a function parameter pack at an outer level 3824245431Sdim/// which we have already substituted to refer to expanded parameters, but where 3825245431Sdim/// the containing pack expansion cannot yet be expanded. 3826245431Sdim/// 3827245431Sdim/// \code 3828245431Sdim/// template<typename...Ts> struct S { 3829245431Sdim/// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...)); 3830245431Sdim/// }; 3831245431Sdim/// template struct S<int, int>; 3832245431Sdim/// \endcode 3833245431Sdimclass FunctionParmPackExpr : public Expr { 3834245431Sdim /// \brief The function parameter pack which was referenced. 3835245431Sdim ParmVarDecl *ParamPack; 3836245431Sdim 3837245431Sdim /// \brief The location of the function parameter pack reference. 3838245431Sdim SourceLocation NameLoc; 3839245431Sdim 3840245431Sdim /// \brief The number of expansions of this pack. 3841245431Sdim unsigned NumParameters; 3842245431Sdim 3843245431Sdim FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, 3844245431Sdim SourceLocation NameLoc, unsigned NumParams, 3845245431Sdim Decl * const *Params); 3846245431Sdim 3847245431Sdim friend class ASTReader; 3848245431Sdim friend class ASTStmtReader; 3849245431Sdim 3850245431Sdimpublic: 3851263509Sdim static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, 3852245431Sdim ParmVarDecl *ParamPack, 3853245431Sdim SourceLocation NameLoc, 3854252723Sdim ArrayRef<Decl *> Params); 3855263509Sdim static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context, 3856245431Sdim unsigned NumParams); 3857245431Sdim 3858245431Sdim /// \brief Get the parameter pack which this expression refers to. 3859245431Sdim ParmVarDecl *getParameterPack() const { return ParamPack; } 3860245431Sdim 3861245431Sdim /// \brief Get the location of the parameter pack. 3862245431Sdim SourceLocation getParameterPackLocation() const { return NameLoc; } 3863245431Sdim 3864245431Sdim /// \brief Iterators over the parameters which the parameter pack expanded 3865245431Sdim /// into. 3866245431Sdim typedef ParmVarDecl * const *iterator; 3867245431Sdim iterator begin() const { return reinterpret_cast<iterator>(this+1); } 3868245431Sdim iterator end() const { return begin() + NumParameters; } 3869245431Sdim 3870245431Sdim /// \brief Get the number of parameters in this parameter pack. 3871245431Sdim unsigned getNumExpansions() const { return NumParameters; } 3872245431Sdim 3873245431Sdim /// \brief Get an expansion of the parameter pack by index. 3874245431Sdim ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; } 3875245431Sdim 3876252723Sdim SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3877252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3878245431Sdim 3879245431Sdim static bool classof(const Stmt *T) { 3880245431Sdim return T->getStmtClass() == FunctionParmPackExprClass; 3881245431Sdim } 3882245431Sdim 3883245431Sdim child_range children() { return child_range(); } 3884245431Sdim}; 3885245431Sdim 3886263509Sdim/// \brief Represents a prvalue temporary that is written into memory so that 3887224145Sdim/// a reference can bind to it. 3888224145Sdim/// 3889224145Sdim/// Prvalue expressions are materialized when they need to have an address 3890224145Sdim/// in memory for a reference to bind to. This happens when binding a 3891224145Sdim/// reference to the result of a conversion, e.g., 3892224145Sdim/// 3893224145Sdim/// \code 3894224145Sdim/// const int &r = 1.0; 3895224145Sdim/// \endcode 3896224145Sdim/// 3897224145Sdim/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 3898224145Sdim/// then materialized via a \c MaterializeTemporaryExpr, and the reference 3899224145Sdim/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 3900224145Sdim/// (either an lvalue or an xvalue, depending on the kind of reference binding 3901224145Sdim/// to it), maintaining the invariant that references always bind to glvalues. 3902263509Sdim/// 3903263509Sdim/// Reference binding and copy-elision can both extend the lifetime of a 3904263509Sdim/// temporary. When either happens, the expression will also track the 3905263509Sdim/// declaration which is responsible for the lifetime extension. 3906224145Sdimclass MaterializeTemporaryExpr : public Expr { 3907263509Sdimpublic: 3908224145Sdim /// \brief The temporary-generating expression whose value will be 3909224145Sdim /// materialized. 3910235633Sdim Stmt *Temporary; 3911235633Sdim 3912263509Sdim /// \brief The declaration which lifetime-extended this reference, if any. 3913263509Sdim /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl. 3914263509Sdim const ValueDecl *ExtendingDecl; 3915263509Sdim 3916224145Sdim friend class ASTStmtReader; 3917224145Sdim friend class ASTStmtWriter; 3918235633Sdim 3919224145Sdimpublic: 3920235633Sdim MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3921263509Sdim bool BoundToLvalueReference, 3922263509Sdim const ValueDecl *ExtendedBy) 3923224145Sdim : Expr(MaterializeTemporaryExprClass, T, 3924224145Sdim BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 3925224145Sdim Temporary->isTypeDependent(), Temporary->isValueDependent(), 3926224145Sdim Temporary->isInstantiationDependent(), 3927224145Sdim Temporary->containsUnexpandedParameterPack()), 3928263509Sdim Temporary(Temporary), ExtendingDecl(ExtendedBy) { 3929263509Sdim } 3930235633Sdim 3931235633Sdim MaterializeTemporaryExpr(EmptyShell Empty) 3932224145Sdim : Expr(MaterializeTemporaryExprClass, Empty) { } 3933235633Sdim 3934224145Sdim /// \brief Retrieve the temporary-generating subexpression whose value will 3935224145Sdim /// be materialized into a glvalue. 3936263509Sdim Expr *GetTemporaryExpr() const { return static_cast<Expr *>(Temporary); } 3937235633Sdim 3938263509Sdim /// \brief Retrieve the storage duration for the materialized temporary. 3939263509Sdim StorageDuration getStorageDuration() const { 3940263509Sdim if (!ExtendingDecl) 3941263509Sdim return SD_FullExpression; 3942263509Sdim // FIXME: This is not necessarily correct for a temporary materialized 3943263509Sdim // within a default initializer. 3944263509Sdim if (isa<FieldDecl>(ExtendingDecl)) 3945263509Sdim return SD_Automatic; 3946263509Sdim return cast<VarDecl>(ExtendingDecl)->getStorageDuration(); 3947263509Sdim } 3948263509Sdim 3949263509Sdim /// \brief Get the declaration which triggered the lifetime-extension of this 3950263509Sdim /// temporary, if any. 3951263509Sdim const ValueDecl *getExtendingDecl() const { return ExtendingDecl; } 3952263509Sdim 3953263509Sdim void setExtendingDecl(const ValueDecl *ExtendedBy) { 3954263509Sdim ExtendingDecl = ExtendedBy; 3955263509Sdim } 3956263509Sdim 3957224145Sdim /// \brief Determine whether this materialized temporary is bound to an 3958224145Sdim /// lvalue reference; otherwise, it's bound to an rvalue reference. 3959235633Sdim bool isBoundToLvalueReference() const { 3960224145Sdim return getValueKind() == VK_LValue; 3961224145Sdim } 3962235633Sdim 3963252723Sdim SourceLocation getLocStart() const LLVM_READONLY { 3964252723Sdim return Temporary->getLocStart(); 3965235633Sdim } 3966252723Sdim SourceLocation getLocEnd() const LLVM_READONLY { 3967252723Sdim return Temporary->getLocEnd(); 3968252723Sdim } 3969235633Sdim 3970224145Sdim static bool classof(const Stmt *T) { 3971224145Sdim return T->getStmtClass() == MaterializeTemporaryExprClass; 3972224145Sdim } 3973235633Sdim 3974224145Sdim // Iterators 3975224145Sdim child_range children() { return child_range(&Temporary, &Temporary + 1); } 3976224145Sdim}; 3977235633Sdim 3978193326Sed} // end namespace clang 3979193326Sed 3980193326Sed#endif 3981