1193323Sed//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed/// 10193323Sed/// \file 11193323Sed/// \brief Defines the clang::Expr interface and subclasses for C++ expressions. 12193323Sed/// 13193323Sed//===----------------------------------------------------------------------===// 14193323Sed 15193323Sed#ifndef LLVM_CLANG_AST_EXPRCXX_H 16193323Sed#define LLVM_CLANG_AST_EXPRCXX_H 17193323Sed 18193323Sed#include "clang/AST/Decl.h" 19193323Sed#include "clang/AST/Expr.h" 20193323Sed#include "clang/AST/TemplateBase.h" 21193323Sed#include "clang/AST/UnresolvedSet.h" 22193323Sed#include "clang/Basic/ExpressionTraits.h" 23193323Sed#include "clang/Basic/Lambda.h" 24193323Sed#include "clang/Basic/TypeTraits.h" 25193323Sed#include "llvm/Support/Compiler.h" 26193323Sed 27193323Sednamespace clang { 28193323Sed 29193323Sedclass CXXConstructorDecl; 30193323Sedclass CXXDestructorDecl; 31193323Sedclass CXXMethodDecl; 32193323Sedclass CXXTemporary; 33193323Sedclass MSPropertyDecl; 34193323Sedclass TemplateArgumentListInfo; 35193323Sedclass UuidAttr; 36193323Sed 37193323Sed//===--------------------------------------------------------------------===// 38193323Sed// C++ Expressions. 39193323Sed//===--------------------------------------------------------------------===// 40193323Sed 41193323Sed/// \brief A call to an overloaded operator written using operator 42193323Sed/// syntax. 43193323Sed/// 44193323Sed/// Represents a call to an overloaded operator written using operator 45193323Sed/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 46193323Sed/// normal call, this AST node provides better information about the 47193323Sed/// syntactic representation of the call. 48193323Sed/// 49193323Sed/// In a C++ template, this expression node kind will be used whenever 50193323Sed/// any of the arguments are type-dependent. In this case, the 51193323Sed/// function itself will be a (possibly empty) set of functions and 52193323Sed/// function templates that were found by name lookup at template 53193323Sed/// definition time. 54193323Sedclass CXXOperatorCallExpr : public CallExpr { 55193323Sed /// \brief The overloaded operator. 56193323Sed OverloadedOperatorKind Operator; 57193323Sed SourceRange Range; 58193323Sed 59193323Sed // Record the FP_CONTRACT state that applies to this operator call. Only 60193323Sed // meaningful for floating point types. For other types this value can be 61193323Sed // set to false. 62193323Sed unsigned FPContractable : 1; 63193323Sed 64193323Sed SourceRange getSourceRangeImpl() const LLVM_READONLY; 65193323Sedpublic: 66193323Sed CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 67193323Sed ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 68193323Sed SourceLocation operatorloc, bool fpContractable) 69193323Sed : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK, 70193323Sed operatorloc), 71193323Sed Operator(Op), FPContractable(fpContractable) { 72193323Sed Range = getSourceRangeImpl(); 73193323Sed } 74193323Sed explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 75193323Sed CallExpr(C, CXXOperatorCallExprClass, Empty) { } 76193323Sed 77193323Sed 78193323Sed /// \brief Returns the kind of overloaded operator that this 79193323Sed /// expression refers to. 80193323Sed OverloadedOperatorKind getOperator() const { return Operator; } 81193323Sed 82193323Sed /// \brief Returns the location of the operator symbol in the expression. 83193323Sed /// 84193323Sed /// When \c getOperator()==OO_Call, this is the location of the right 85193323Sed /// parentheses; when \c getOperator()==OO_Subscript, this is the location 86193323Sed /// of the right bracket. 87193323Sed SourceLocation getOperatorLoc() const { return getRParenLoc(); } 88193323Sed 89193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 90193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 91193323Sed SourceRange getSourceRange() const { return Range; } 92193323Sed 93193323Sed static bool classof(const Stmt *T) { 94193323Sed return T->getStmtClass() == CXXOperatorCallExprClass; 95193323Sed } 96193323Sed 97193323Sed // Set the FP contractability status of this operator. Only meaningful for 98193323Sed // operations on floating point types. 99193323Sed void setFPContractable(bool FPC) { FPContractable = FPC; } 100193323Sed 101193323Sed // Get the FP contractability status of this operator. Only meaningful for 102193323Sed // operations on floating point types. 103193323Sed bool isFPContractable() const { return FPContractable; } 104193323Sed 105193323Sed friend class ASTStmtReader; 106193323Sed friend class ASTStmtWriter; 107193323Sed}; 108193323Sed 109193323Sed/// Represents a call to a member function that 110193323Sed/// may be written either with member call syntax (e.g., "obj.func()" 111193323Sed/// or "objptr->func()") or with normal function-call syntax 112193323Sed/// ("func()") within a member function that ends up calling a member 113193323Sed/// function. The callee in either case is a MemberExpr that contains 114193323Sed/// both the object argument and the member function, while the 115193323Sed/// arguments are the arguments within the parentheses (not including 116193323Sed/// the object argument). 117193323Sedclass CXXMemberCallExpr : public CallExpr { 118193323Sedpublic: 119193323Sed CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args, 120193323Sed QualType t, ExprValueKind VK, SourceLocation RP) 121193323Sed : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {} 122193323Sed 123193323Sed CXXMemberCallExpr(ASTContext &C, EmptyShell Empty) 124193323Sed : CallExpr(C, CXXMemberCallExprClass, Empty) { } 125193323Sed 126193323Sed /// \brief Retrieves the implicit object argument for the member call. 127193323Sed /// 128193323Sed /// For example, in "x.f(5)", this returns the sub-expression "x". 129193323Sed Expr *getImplicitObjectArgument() const; 130193323Sed 131193323Sed /// \brief Retrieves the declaration of the called method. 132193323Sed CXXMethodDecl *getMethodDecl() const; 133193323Sed 134193323Sed /// \brief Retrieves the CXXRecordDecl for the underlying type of 135193323Sed /// the implicit object argument. 136193323Sed /// 137193323Sed /// Note that this is may not be the same declaration as that of the class 138193323Sed /// context of the CXXMethodDecl which this function is calling. 139193323Sed /// FIXME: Returns 0 for member pointer call exprs. 140193323Sed CXXRecordDecl *getRecordDecl() const; 141193323Sed 142193323Sed static bool classof(const Stmt *T) { 143193323Sed return T->getStmtClass() == CXXMemberCallExprClass; 144193323Sed } 145193323Sed}; 146193323Sed 147193323Sed/// \brief Represents a call to a CUDA kernel function. 148193323Sedclass CUDAKernelCallExpr : public CallExpr { 149193323Sedprivate: 150193323Sed enum { CONFIG, END_PREARG }; 151193323Sed 152193323Sedpublic: 153193323Sed CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config, 154193323Sed ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 155193323Sed SourceLocation RP) 156193323Sed : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) { 157193323Sed setConfig(Config); 158193323Sed } 159193323Sed 160193323Sed CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty) 161193323Sed : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { } 162193323Sed 163193323Sed const CallExpr *getConfig() const { 164193323Sed return cast_or_null<CallExpr>(getPreArg(CONFIG)); 165193323Sed } 166193323Sed CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } 167193323Sed void setConfig(CallExpr *E) { setPreArg(CONFIG, E); } 168193323Sed 169193323Sed static bool classof(const Stmt *T) { 170193323Sed return T->getStmtClass() == CUDAKernelCallExprClass; 171193323Sed } 172193323Sed}; 173193323Sed 174193323Sed/// \brief Abstract class common to all of the C++ "named"/"keyword" casts. 175193323Sed/// 176193323Sed/// This abstract class is inherited by all of the classes 177193323Sed/// representing "named" casts: CXXStaticCastExpr for \c static_cast, 178193323Sed/// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for 179193323Sed/// reinterpret_cast, and CXXConstCastExpr for \c const_cast. 180193323Sedclass CXXNamedCastExpr : public ExplicitCastExpr { 181193323Sedprivate: 182193323Sed SourceLocation Loc; // the location of the casting op 183193323Sed SourceLocation RParenLoc; // the location of the right parenthesis 184193323Sed SourceRange AngleBrackets; // range for '<' '>' 185193323Sed 186193323Sedprotected: 187193323Sed CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 188193323Sed CastKind kind, Expr *op, unsigned PathSize, 189193323Sed TypeSourceInfo *writtenTy, SourceLocation l, 190193323Sed SourceLocation RParenLoc, 191193323Sed SourceRange AngleBrackets) 192193323Sed : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l), 193193323Sed RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {} 194193323Sed 195193323Sed explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 196193323Sed : ExplicitCastExpr(SC, Shell, PathSize) { } 197193323Sed 198193323Sed friend class ASTStmtReader; 199193323Sed 200193323Sedpublic: 201193323Sed const char *getCastName() const; 202193323Sed 203193323Sed /// \brief Retrieve the location of the cast operator keyword, e.g., 204193323Sed /// \c static_cast. 205193323Sed SourceLocation getOperatorLoc() const { return Loc; } 206193323Sed 207193323Sed /// \brief Retrieve the location of the closing parenthesis. 208193323Sed SourceLocation getRParenLoc() const { return RParenLoc; } 209193323Sed 210193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 211193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 212193323Sed SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; } 213193323Sed 214193323Sed static bool classof(const Stmt *T) { 215193323Sed switch (T->getStmtClass()) { 216193323Sed case CXXStaticCastExprClass: 217193323Sed case CXXDynamicCastExprClass: 218193323Sed case CXXReinterpretCastExprClass: 219193323Sed case CXXConstCastExprClass: 220193323Sed return true; 221193323Sed default: 222193323Sed return false; 223193323Sed } 224193323Sed } 225193323Sed}; 226193323Sed 227193323Sed/// \brief A C++ \c static_cast expression (C++ [expr.static.cast]). 228193323Sed/// 229193323Sed/// This expression node represents a C++ static cast, e.g., 230193323Sed/// \c static_cast<int>(1.0). 231193323Sedclass CXXStaticCastExpr : public CXXNamedCastExpr { 232193323Sed CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, 233193323Sed unsigned pathSize, TypeSourceInfo *writtenTy, 234193323Sed SourceLocation l, SourceLocation RParenLoc, 235193323Sed SourceRange AngleBrackets) 236193323Sed : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, 237193323Sed writtenTy, l, RParenLoc, AngleBrackets) {} 238193323Sed 239193323Sed explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize) 240193323Sed : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { } 241193323Sed 242193323Sedpublic: 243193323Sed static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T, 244193323Sed ExprValueKind VK, CastKind K, Expr *Op, 245193323Sed const CXXCastPath *Path, 246193323Sed TypeSourceInfo *Written, SourceLocation L, 247193323Sed SourceLocation RParenLoc, 248193323Sed SourceRange AngleBrackets); 249193323Sed static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context, 250193323Sed unsigned PathSize); 251193323Sed 252193323Sed static bool classof(const Stmt *T) { 253193323Sed return T->getStmtClass() == CXXStaticCastExprClass; 254193323Sed } 255193323Sed}; 256193323Sed 257193323Sed/// \brief A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]). 258193323Sed/// 259193323Sed/// This expression node represents a dynamic cast, e.g., 260193323Sed/// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time 261193323Sed/// check to determine how to perform the type conversion. 262193323Sedclass CXXDynamicCastExpr : public CXXNamedCastExpr { 263193323Sed CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, 264193323Sed Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy, 265193323Sed SourceLocation l, SourceLocation RParenLoc, 266193323Sed SourceRange AngleBrackets) 267193323Sed : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, 268193323Sed writtenTy, l, RParenLoc, AngleBrackets) {} 269193323Sed 270193323Sed explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) 271193323Sed : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { } 272193323Sed 273193323Sedpublic: 274193323Sed static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T, 275193323Sed ExprValueKind VK, CastKind Kind, Expr *Op, 276193323Sed const CXXCastPath *Path, 277193323Sed TypeSourceInfo *Written, SourceLocation L, 278193323Sed SourceLocation RParenLoc, 279193323Sed SourceRange AngleBrackets); 280193323Sed 281193323Sed static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context, 282193323Sed unsigned pathSize); 283193323Sed 284193323Sed bool isAlwaysNull() const; 285193323Sed 286193323Sed static bool classof(const Stmt *T) { 287193323Sed return T->getStmtClass() == CXXDynamicCastExprClass; 288193323Sed } 289193323Sed}; 290193323Sed 291193323Sed/// \brief A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]). 292193323Sed/// 293193323Sed/// This expression node represents a reinterpret cast, e.g., 294193323Sed/// @c reinterpret_cast<int>(VoidPtr). 295193323Sed/// 296193323Sed/// A reinterpret_cast provides a differently-typed view of a value but 297193323Sed/// (in Clang, as in most C++ implementations) performs no actual work at 298193323Sed/// run time. 299193323Sedclass CXXReinterpretCastExpr : public CXXNamedCastExpr { 300193323Sed CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, 301193323Sed Expr *op, unsigned pathSize, 302193323Sed TypeSourceInfo *writtenTy, SourceLocation l, 303193323Sed SourceLocation RParenLoc, 304193323Sed SourceRange AngleBrackets) 305193323Sed : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, 306193323Sed pathSize, writtenTy, l, RParenLoc, AngleBrackets) {} 307193323Sed 308193323Sed CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) 309193323Sed : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { } 310193323Sed 311193323Sedpublic: 312193323Sed static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T, 313193323Sed ExprValueKind VK, CastKind Kind, 314193323Sed Expr *Op, const CXXCastPath *Path, 315193323Sed TypeSourceInfo *WrittenTy, SourceLocation L, 316193323Sed SourceLocation RParenLoc, 317193323Sed SourceRange AngleBrackets); 318193323Sed static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context, 319193323Sed unsigned pathSize); 320193323Sed 321193323Sed static bool classof(const Stmt *T) { 322193323Sed return T->getStmtClass() == CXXReinterpretCastExprClass; 323193323Sed } 324193323Sed}; 325193323Sed 326193323Sed/// \brief A C++ \c const_cast expression (C++ [expr.const.cast]). 327193323Sed/// 328193323Sed/// This expression node represents a const cast, e.g., 329193323Sed/// \c const_cast<char*>(PtrToConstChar). 330193323Sed/// 331193323Sed/// A const_cast can remove type qualifiers but does not change the underlying 332193323Sed/// value. 333193323Sedclass CXXConstCastExpr : public CXXNamedCastExpr { 334193323Sed CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, 335193323Sed TypeSourceInfo *writtenTy, SourceLocation l, 336193323Sed SourceLocation RParenLoc, SourceRange AngleBrackets) 337193323Sed : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 338193323Sed 0, writtenTy, l, RParenLoc, AngleBrackets) {} 339193323Sed 340193323Sed explicit CXXConstCastExpr(EmptyShell Empty) 341193323Sed : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { } 342193323Sed 343193323Sedpublic: 344193323Sed static CXXConstCastExpr *Create(const ASTContext &Context, QualType T, 345193323Sed ExprValueKind VK, Expr *Op, 346193323Sed TypeSourceInfo *WrittenTy, SourceLocation L, 347193323Sed SourceLocation RParenLoc, 348193323Sed SourceRange AngleBrackets); 349193323Sed static CXXConstCastExpr *CreateEmpty(const ASTContext &Context); 350193323Sed 351193323Sed static bool classof(const Stmt *T) { 352193323Sed return T->getStmtClass() == CXXConstCastExprClass; 353193323Sed } 354193323Sed}; 355193323Sed 356193323Sed/// \brief A call to a literal operator (C++11 [over.literal]) 357193323Sed/// written as a user-defined literal (C++11 [lit.ext]). 358193323Sed/// 359193323Sed/// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this 360193323Sed/// is semantically equivalent to a normal call, this AST node provides better 361193323Sed/// information about the syntactic representation of the literal. 362193323Sed/// 363193323Sed/// Since literal operators are never found by ADL and can only be declared at 364193323Sed/// namespace scope, a user-defined literal is never dependent. 365193323Sedclass UserDefinedLiteral : public CallExpr { 366193323Sed /// \brief The location of a ud-suffix within the literal. 367193323Sed SourceLocation UDSuffixLoc; 368193323Sed 369193323Sedpublic: 370193323Sed UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args, 371193323Sed QualType T, ExprValueKind VK, SourceLocation LitEndLoc, 372193323Sed SourceLocation SuffixLoc) 373193323Sed : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc), 374193323Sed UDSuffixLoc(SuffixLoc) {} 375193323Sed explicit UserDefinedLiteral(const ASTContext &C, EmptyShell Empty) 376193323Sed : CallExpr(C, UserDefinedLiteralClass, Empty) {} 377193323Sed 378193323Sed /// The kind of literal operator which is invoked. 379193323Sed enum LiteralOperatorKind { 380193323Sed LOK_Raw, ///< Raw form: operator "" X (const char *) 381193323Sed LOK_Template, ///< Raw form: operator "" X<cs...> () 382193323Sed LOK_Integer, ///< operator "" X (unsigned long long) 383193323Sed LOK_Floating, ///< operator "" X (long double) 384193323Sed LOK_String, ///< operator "" X (const CharT *, size_t) 385193323Sed LOK_Character ///< operator "" X (CharT) 386193323Sed }; 387193323Sed 388193323Sed /// \brief Returns the kind of literal operator invocation 389193323Sed /// which this expression represents. 390193323Sed LiteralOperatorKind getLiteralOperatorKind() const; 391193323Sed 392193323Sed /// \brief If this is not a raw user-defined literal, get the 393193323Sed /// underlying cooked literal (representing the literal with the suffix 394193323Sed /// removed). 395193323Sed Expr *getCookedLiteral(); 396193323Sed const Expr *getCookedLiteral() const { 397193323Sed return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral(); 398193323Sed } 399193323Sed 400193323Sed SourceLocation getLocStart() const { 401193323Sed if (getLiteralOperatorKind() == LOK_Template) 402193323Sed return getRParenLoc(); 403193323Sed return getArg(0)->getLocStart(); 404193323Sed } 405193323Sed SourceLocation getLocEnd() const { return getRParenLoc(); } 406193323Sed 407193323Sed 408193323Sed /// \brief Returns the location of a ud-suffix in the expression. 409193323Sed /// 410193323Sed /// For a string literal, there may be multiple identical suffixes. This 411193323Sed /// returns the first. 412193323Sed SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; } 413193323Sed 414193323Sed /// \brief Returns the ud-suffix specified for this literal. 415193323Sed const IdentifierInfo *getUDSuffix() const; 416193323Sed 417193323Sed static bool classof(const Stmt *S) { 418193323Sed return S->getStmtClass() == UserDefinedLiteralClass; 419193323Sed } 420193323Sed 421193323Sed friend class ASTStmtReader; 422193323Sed friend class ASTStmtWriter; 423193323Sed}; 424193323Sed 425193323Sed/// \brief A boolean literal, per ([C++ lex.bool] Boolean literals). 426193323Sed/// 427193323Sedclass CXXBoolLiteralExpr : public Expr { 428193323Sed bool Value; 429193323Sed SourceLocation Loc; 430193323Sedpublic: 431193323Sed CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 432193323Sed Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 433193323Sed false, false), 434193323Sed Value(val), Loc(l) {} 435193323Sed 436193323Sed explicit CXXBoolLiteralExpr(EmptyShell Empty) 437193323Sed : Expr(CXXBoolLiteralExprClass, Empty) { } 438193323Sed 439193323Sed bool getValue() const { return Value; } 440193323Sed void setValue(bool V) { Value = V; } 441193323Sed 442193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 443193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 444193323Sed 445193323Sed SourceLocation getLocation() const { return Loc; } 446193323Sed void setLocation(SourceLocation L) { Loc = L; } 447193323Sed 448193323Sed static bool classof(const Stmt *T) { 449193323Sed return T->getStmtClass() == CXXBoolLiteralExprClass; 450193323Sed } 451193323Sed 452193323Sed // Iterators 453193323Sed child_range children() { return child_range(); } 454193323Sed}; 455193323Sed 456193323Sed/// \brief The null pointer literal (C++11 [lex.nullptr]) 457193323Sed/// 458193323Sed/// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr. 459193323Sedclass CXXNullPtrLiteralExpr : public Expr { 460193323Sed SourceLocation Loc; 461193323Sedpublic: 462193323Sed CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 463193323Sed Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 464193323Sed false, false), 465193323Sed Loc(l) {} 466193323Sed 467193323Sed explicit CXXNullPtrLiteralExpr(EmptyShell Empty) 468193323Sed : Expr(CXXNullPtrLiteralExprClass, Empty) { } 469193323Sed 470193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 471193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 472193323Sed 473193323Sed SourceLocation getLocation() const { return Loc; } 474193323Sed void setLocation(SourceLocation L) { Loc = L; } 475193323Sed 476193323Sed static bool classof(const Stmt *T) { 477193323Sed return T->getStmtClass() == CXXNullPtrLiteralExprClass; 478193323Sed } 479193323Sed 480193323Sed child_range children() { return child_range(); } 481193323Sed}; 482193323Sed 483193323Sed/// \brief Implicit construction of a std::initializer_list<T> object from an 484193323Sed/// array temporary within list-initialization (C++11 [dcl.init.list]p5). 485193323Sedclass CXXStdInitializerListExpr : public Expr { 486193323Sed Stmt *SubExpr; 487193323Sed 488193323Sed CXXStdInitializerListExpr(EmptyShell Empty) 489193323Sed : Expr(CXXStdInitializerListExprClass, Empty), SubExpr(0) {} 490193323Sed 491193323Sedpublic: 492193323Sed CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr) 493193323Sed : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary, 494193323Sed Ty->isDependentType(), SubExpr->isValueDependent(), 495193323Sed SubExpr->isInstantiationDependent(), 496193323Sed SubExpr->containsUnexpandedParameterPack()), 497193323Sed SubExpr(SubExpr) {} 498193323Sed 499193323Sed Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); } 500193323Sed const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); } 501193323Sed 502193323Sed SourceLocation getLocStart() const LLVM_READONLY { 503193323Sed return SubExpr->getLocStart(); 504193323Sed } 505193323Sed SourceLocation getLocEnd() const LLVM_READONLY { 506193323Sed return SubExpr->getLocEnd(); 507193323Sed } 508193323Sed SourceRange getSourceRange() const LLVM_READONLY { 509193323Sed return SubExpr->getSourceRange(); 510193323Sed } 511193323Sed 512193323Sed static bool classof(const Stmt *S) { 513193323Sed return S->getStmtClass() == CXXStdInitializerListExprClass; 514193323Sed } 515193323Sed 516193323Sed child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 517193323Sed 518193323Sed friend class ASTReader; 519193323Sed friend class ASTStmtReader; 520193323Sed}; 521193323Sed 522193323Sed/// A C++ \c typeid expression (C++ [expr.typeid]), which gets 523193323Sed/// the \c type_info that corresponds to the supplied type, or the (possibly 524193323Sed/// dynamic) type of the supplied expression. 525193323Sed/// 526193323Sed/// This represents code like \c typeid(int) or \c typeid(*objPtr) 527193323Sedclass CXXTypeidExpr : public Expr { 528193323Sedprivate: 529193323Sed llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 530193323Sed SourceRange Range; 531193323Sed 532193323Sedpublic: 533193323Sed CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 534193323Sed : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 535193323Sed // typeid is never type-dependent (C++ [temp.dep.expr]p4) 536193323Sed false, 537193323Sed // typeid is value-dependent if the type or expression are dependent 538193323Sed Operand->getType()->isDependentType(), 539193323Sed Operand->getType()->isInstantiationDependentType(), 540193323Sed Operand->getType()->containsUnexpandedParameterPack()), 541193323Sed Operand(Operand), Range(R) { } 542193323Sed 543193323Sed CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) 544193323Sed : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 545193323Sed // typeid is never type-dependent (C++ [temp.dep.expr]p4) 546193323Sed false, 547193323Sed // typeid is value-dependent if the type or expression are dependent 548193323Sed Operand->isTypeDependent() || Operand->isValueDependent(), 549193323Sed Operand->isInstantiationDependent(), 550193323Sed Operand->containsUnexpandedParameterPack()), 551193323Sed Operand(Operand), Range(R) { } 552193323Sed 553193323Sed CXXTypeidExpr(EmptyShell Empty, bool isExpr) 554193323Sed : Expr(CXXTypeidExprClass, Empty) { 555193323Sed if (isExpr) 556193323Sed Operand = (Expr*)0; 557193323Sed else 558193323Sed Operand = (TypeSourceInfo*)0; 559193323Sed } 560193323Sed 561193323Sed /// Determine whether this typeid has a type operand which is potentially 562193323Sed /// evaluated, per C++11 [expr.typeid]p3. 563193323Sed bool isPotentiallyEvaluated() const; 564193323Sed 565193323Sed bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 566193323Sed 567193323Sed /// \brief Retrieves the type operand of this typeid() expression after 568193323Sed /// various required adjustments (removing reference types, cv-qualifiers). 569193323Sed QualType getTypeOperand(ASTContext &Context) const; 570193323Sed 571193323Sed /// \brief Retrieve source information for the type operand. 572193323Sed TypeSourceInfo *getTypeOperandSourceInfo() const { 573193323Sed assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 574193323Sed return Operand.get<TypeSourceInfo *>(); 575193323Sed } 576193323Sed 577193323Sed void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 578193323Sed assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 579193323Sed Operand = TSI; 580193323Sed } 581193323Sed 582193323Sed Expr *getExprOperand() const { 583193323Sed assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 584193323Sed return static_cast<Expr*>(Operand.get<Stmt *>()); 585193323Sed } 586193323Sed 587193323Sed void setExprOperand(Expr *E) { 588193323Sed assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 589193323Sed Operand = E; 590193323Sed } 591193323Sed 592193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 593193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 594193323Sed SourceRange getSourceRange() const LLVM_READONLY { return Range; } 595193323Sed void setSourceRange(SourceRange R) { Range = R; } 596193323Sed 597193323Sed static bool classof(const Stmt *T) { 598193323Sed return T->getStmtClass() == CXXTypeidExprClass; 599193323Sed } 600193323Sed 601193323Sed // Iterators 602193323Sed child_range children() { 603193323Sed if (isTypeOperand()) return child_range(); 604193323Sed Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 605193323Sed return child_range(begin, begin + 1); 606193323Sed } 607193323Sed}; 608193323Sed 609193323Sed/// \brief A member reference to an MSPropertyDecl. 610193323Sed/// 611193323Sed/// This expression always has pseudo-object type, and therefore it is 612193323Sed/// typically not encountered in a fully-typechecked expression except 613193323Sed/// within the syntactic form of a PseudoObjectExpr. 614193323Sedclass MSPropertyRefExpr : public Expr { 615193323Sed Expr *BaseExpr; 616193323Sed MSPropertyDecl *TheDecl; 617193323Sed SourceLocation MemberLoc; 618193323Sed bool IsArrow; 619193323Sed NestedNameSpecifierLoc QualifierLoc; 620193323Sed 621193323Sedpublic: 622193323Sed MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow, 623193323Sed QualType ty, ExprValueKind VK, 624193323Sed NestedNameSpecifierLoc qualifierLoc, 625193323Sed SourceLocation nameLoc) 626193323Sed : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary, 627193323Sed /*type-dependent*/ false, baseExpr->isValueDependent(), 628193323Sed baseExpr->isInstantiationDependent(), 629193323Sed baseExpr->containsUnexpandedParameterPack()), 630193323Sed BaseExpr(baseExpr), TheDecl(decl), 631193323Sed MemberLoc(nameLoc), IsArrow(isArrow), 632193323Sed QualifierLoc(qualifierLoc) {} 633193323Sed 634193323Sed MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {} 635193323Sed 636193323Sed SourceRange getSourceRange() const LLVM_READONLY { 637193323Sed return SourceRange(getLocStart(), getLocEnd()); 638193323Sed } 639193323Sed bool isImplicitAccess() const { 640193323Sed return getBaseExpr() && getBaseExpr()->isImplicitCXXThis(); 641193323Sed } 642193323Sed SourceLocation getLocStart() const { 643193323Sed if (!isImplicitAccess()) 644193323Sed return BaseExpr->getLocStart(); 645193323Sed else if (QualifierLoc) 646193323Sed return QualifierLoc.getBeginLoc(); 647193323Sed else 648193323Sed return MemberLoc; 649193323Sed } 650193323Sed SourceLocation getLocEnd() const { return getMemberLoc(); } 651193323Sed 652193323Sed child_range children() { 653193323Sed return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1); 654193323Sed } 655193323Sed static bool classof(const Stmt *T) { 656193323Sed return T->getStmtClass() == MSPropertyRefExprClass; 657193323Sed } 658193323Sed 659193323Sed Expr *getBaseExpr() const { return BaseExpr; } 660193323Sed MSPropertyDecl *getPropertyDecl() const { return TheDecl; } 661193323Sed bool isArrow() const { return IsArrow; } 662193323Sed SourceLocation getMemberLoc() const { return MemberLoc; } 663193323Sed NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 664193323Sed 665193323Sed friend class ASTStmtReader; 666193323Sed}; 667193323Sed 668193323Sed/// A Microsoft C++ @c __uuidof expression, which gets 669193323Sed/// the _GUID that corresponds to the supplied type or expression. 670193323Sed/// 671193323Sed/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) 672193323Sedclass CXXUuidofExpr : public Expr { 673193323Sedprivate: 674193323Sed llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 675193323Sed SourceRange Range; 676193323Sed 677193323Sedpublic: 678193323Sed CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 679193323Sed : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 680193323Sed false, Operand->getType()->isDependentType(), 681193323Sed Operand->getType()->isInstantiationDependentType(), 682193323Sed Operand->getType()->containsUnexpandedParameterPack()), 683193323Sed Operand(Operand), Range(R) { } 684193323Sed 685193323Sed CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R) 686193323Sed : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 687193323Sed false, Operand->isTypeDependent(), 688193323Sed Operand->isInstantiationDependent(), 689193323Sed Operand->containsUnexpandedParameterPack()), 690193323Sed Operand(Operand), Range(R) { } 691193323Sed 692193323Sed CXXUuidofExpr(EmptyShell Empty, bool isExpr) 693193323Sed : Expr(CXXUuidofExprClass, Empty) { 694193323Sed if (isExpr) 695193323Sed Operand = (Expr*)0; 696193323Sed else 697193323Sed Operand = (TypeSourceInfo*)0; 698193323Sed } 699193323Sed 700193323Sed bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 701193323Sed 702193323Sed /// \brief Retrieves the type operand of this __uuidof() expression after 703193323Sed /// various required adjustments (removing reference types, cv-qualifiers). 704193323Sed QualType getTypeOperand(ASTContext &Context) const; 705193323Sed 706193323Sed /// \brief Retrieve source information for the type operand. 707193323Sed TypeSourceInfo *getTypeOperandSourceInfo() const { 708193323Sed assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 709193323Sed return Operand.get<TypeSourceInfo *>(); 710193323Sed } 711193323Sed 712193323Sed void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 713193323Sed assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 714193323Sed Operand = TSI; 715193323Sed } 716193323Sed 717193323Sed Expr *getExprOperand() const { 718193323Sed assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 719193323Sed return static_cast<Expr*>(Operand.get<Stmt *>()); 720193323Sed } 721193323Sed 722193323Sed void setExprOperand(Expr *E) { 723194612Sed assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 724193323Sed Operand = E; 725193323Sed } 726193323Sed 727193323Sed StringRef getUuidAsStringRef(ASTContext &Context) const; 728193323Sed 729193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 730193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 731193323Sed SourceRange getSourceRange() const LLVM_READONLY { return Range; } 732193323Sed void setSourceRange(SourceRange R) { Range = R; } 733193323Sed 734193323Sed static bool classof(const Stmt *T) { 735193323Sed return T->getStmtClass() == CXXUuidofExprClass; 736193323Sed } 737193323Sed 738193323Sed /// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to 739193323Sed /// a single GUID. 740193323Sed static UuidAttr *GetUuidAttrOfType(QualType QT, 741193323Sed bool *HasMultipleGUIDsPtr = 0); 742193323Sed 743193323Sed // Iterators 744193323Sed child_range children() { 745193323Sed if (isTypeOperand()) return child_range(); 746193323Sed Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 747193323Sed return child_range(begin, begin + 1); 748193323Sed } 749193323Sed}; 750193323Sed 751193323Sed/// \brief Represents the \c this expression in C++. 752193323Sed/// 753193323Sed/// This is a pointer to the object on which the current member function is 754193323Sed/// executing (C++ [expr.prim]p3). Example: 755193323Sed/// 756193323Sed/// \code 757193323Sed/// class Foo { 758193323Sed/// public: 759193323Sed/// void bar(); 760193323Sed/// void test() { this->bar(); } 761193323Sed/// }; 762193323Sed/// \endcode 763193323Sedclass CXXThisExpr : public Expr { 764193323Sed SourceLocation Loc; 765193323Sed bool Implicit : 1; 766193323Sed 767193323Sedpublic: 768193323Sed CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 769193323Sed : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, 770193323Sed // 'this' is type-dependent if the class type of the enclosing 771193323Sed // member function is dependent (C++ [temp.dep.expr]p2) 772193323Sed Type->isDependentType(), Type->isDependentType(), 773193323Sed Type->isInstantiationDependentType(), 774193323Sed /*ContainsUnexpandedParameterPack=*/false), 775193323Sed Loc(L), Implicit(isImplicit) { } 776193323Sed 777193323Sed CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} 778193323Sed 779193323Sed SourceLocation getLocation() const { return Loc; } 780193323Sed void setLocation(SourceLocation L) { Loc = L; } 781193323Sed 782193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 783193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 784193323Sed 785193323Sed bool isImplicit() const { return Implicit; } 786193323Sed void setImplicit(bool I) { Implicit = I; } 787193323Sed 788193323Sed static bool classof(const Stmt *T) { 789193323Sed return T->getStmtClass() == CXXThisExprClass; 790193323Sed } 791193323Sed 792193323Sed // Iterators 793193323Sed child_range children() { return child_range(); } 794193323Sed}; 795193323Sed 796193323Sed/// \brief A C++ throw-expression (C++ [except.throw]). 797193323Sed/// 798193323Sed/// This handles 'throw' (for re-throwing the current exception) and 799193323Sed/// 'throw' assignment-expression. When assignment-expression isn't 800193323Sed/// present, Op will be null. 801193323Sedclass CXXThrowExpr : public Expr { 802193323Sed Stmt *Op; 803193323Sed SourceLocation ThrowLoc; 804193323Sed /// \brief Whether the thrown variable (if any) is in scope. 805193323Sed unsigned IsThrownVariableInScope : 1; 806193323Sed 807193323Sed friend class ASTStmtReader; 808193323Sed 809193323Sedpublic: 810193323Sed // \p Ty is the void type which is used as the result type of the 811193323Sed // expression. The \p l is the location of the throw keyword. \p expr 812193323Sed // can by null, if the optional expression to throw isn't present. 813193323Sed CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l, 814193323Sed bool IsThrownVariableInScope) : 815193323Sed Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 816193323Sed expr && expr->isInstantiationDependent(), 817193323Sed expr && expr->containsUnexpandedParameterPack()), 818193323Sed Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {} 819193323Sed CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} 820193323Sed 821193323Sed const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 822193323Sed Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 823193323Sed 824193323Sed SourceLocation getThrowLoc() const { return ThrowLoc; } 825193323Sed 826193323Sed /// \brief Determines whether the variable thrown by this expression (if any!) 827193323Sed /// is within the innermost try block. 828193323Sed /// 829193323Sed /// This information is required to determine whether the NRVO can apply to 830193323Sed /// this variable. 831193323Sed bool isThrownVariableInScope() const { return IsThrownVariableInScope; } 832193323Sed 833193323Sed SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; } 834193323Sed SourceLocation getLocEnd() const LLVM_READONLY { 835193323Sed if (getSubExpr() == 0) 836194612Sed return ThrowLoc; 837194612Sed return getSubExpr()->getLocEnd(); 838193323Sed } 839193323Sed 840193323Sed static bool classof(const Stmt *T) { 841193323Sed return T->getStmtClass() == CXXThrowExprClass; 842193323Sed } 843193323Sed 844193323Sed // Iterators 845193323Sed child_range children() { 846193323Sed return child_range(&Op, Op ? &Op+1 : &Op); 847193323Sed } 848193323Sed}; 849193323Sed 850193323Sed/// \brief A default argument (C++ [dcl.fct.default]). 851193323Sed/// 852193323Sed/// This wraps up a function call argument that was created from the 853193323Sed/// corresponding parameter's default argument, when the call did not 854193323Sed/// explicitly supply arguments for all of the parameters. 855193323Sedclass CXXDefaultArgExpr : public Expr { 856193323Sed /// \brief The parameter whose default is being used. 857193323Sed /// 858193323Sed /// When the bit is set, the subexpression is stored after the 859193323Sed /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 860193323Sed /// actual default expression is the subexpression. 861193323Sed llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 862193323Sed 863193323Sed /// \brief The location where the default argument expression was used. 864193323Sed SourceLocation Loc; 865193323Sed 866193323Sed CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 867193323Sed : Expr(SC, 868193323Sed param->hasUnparsedDefaultArg() 869193323Sed ? param->getType().getNonReferenceType() 870193323Sed : param->getDefaultArg()->getType(), 871193323Sed param->getDefaultArg()->getValueKind(), 872193323Sed param->getDefaultArg()->getObjectKind(), false, false, false, false), 873193323Sed Param(param, false), Loc(Loc) { } 874193323Sed 875193323Sed CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 876193323Sed Expr *SubExpr) 877193323Sed : Expr(SC, SubExpr->getType(), 878193323Sed SubExpr->getValueKind(), SubExpr->getObjectKind(), 879193323Sed false, false, false, false), 880193323Sed Param(param, true), Loc(Loc) { 881193323Sed *reinterpret_cast<Expr **>(this + 1) = SubExpr; 882193323Sed } 883193323Sed 884193323Sedpublic: 885193323Sed CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} 886193323Sed 887193323Sed // \p Param is the parameter whose default argument is used by this 888193323Sed // expression. 889193323Sed static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc, 890193323Sed ParmVarDecl *Param) { 891193323Sed return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 892193323Sed } 893193323Sed 894193323Sed // \p Param is the parameter whose default argument is used by this 895193323Sed // expression, and \p SubExpr is the expression that will actually be used. 896193323Sed static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc, 897193323Sed ParmVarDecl *Param, Expr *SubExpr); 898193323Sed 899193323Sed // Retrieve the parameter that the argument was created from. 900193323Sed const ParmVarDecl *getParam() const { return Param.getPointer(); } 901193323Sed ParmVarDecl *getParam() { return Param.getPointer(); } 902193323Sed 903193323Sed // Retrieve the actual argument to the function call. 904193323Sed const Expr *getExpr() const { 905193323Sed if (Param.getInt()) 906193323Sed return *reinterpret_cast<Expr const * const*> (this + 1); 907193323Sed return getParam()->getDefaultArg(); 908193323Sed } 909193323Sed Expr *getExpr() { 910193323Sed if (Param.getInt()) 911193323Sed return *reinterpret_cast<Expr **> (this + 1); 912193323Sed return getParam()->getDefaultArg(); 913193323Sed } 914193323Sed 915193323Sed /// \brief Retrieve the location where this default argument was actually 916193323Sed /// used. 917193323Sed SourceLocation getUsedLocation() const { return Loc; } 918193323Sed 919193323Sed /// Default argument expressions have no representation in the 920193323Sed /// source, so they have an empty source range. 921193323Sed SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } 922193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } 923193323Sed 924193323Sed SourceLocation getExprLoc() const LLVM_READONLY { return Loc; } 925193323Sed 926193323Sed static bool classof(const Stmt *T) { 927193323Sed return T->getStmtClass() == CXXDefaultArgExprClass; 928193323Sed } 929193323Sed 930193323Sed // Iterators 931193323Sed child_range children() { return child_range(); } 932193323Sed 933193323Sed friend class ASTStmtReader; 934193323Sed friend class ASTStmtWriter; 935193323Sed}; 936193323Sed 937193323Sed/// \brief A use of a default initializer in a constructor or in aggregate 938193323Sed/// initialization. 939193323Sed/// 940193323Sed/// This wraps a use of a C++ default initializer (technically, 941193323Sed/// a brace-or-equal-initializer for a non-static data member) when it 942193323Sed/// is implicitly used in a mem-initializer-list in a constructor 943193323Sed/// (C++11 [class.base.init]p8) or in aggregate initialization 944193323Sed/// (C++1y [dcl.init.aggr]p7). 945193323Sedclass CXXDefaultInitExpr : public Expr { 946193323Sed /// \brief The field whose default is being used. 947193323Sed FieldDecl *Field; 948193323Sed 949193323Sed /// \brief The location where the default initializer expression was used. 950193323Sed SourceLocation Loc; 951193323Sed 952193323Sed CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field, 953193323Sed QualType T); 954193323Sed 955193323Sed CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {} 956193323Sed 957193323Sedpublic: 958193323Sed /// \p Field is the non-static data member whose default initializer is used 959193323Sed /// by this expression. 960193323Sed static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc, 961193323Sed FieldDecl *Field) { 962193323Sed return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType()); 963193323Sed } 964193323Sed 965193323Sed /// \brief Get the field whose initializer will be used. 966193323Sed FieldDecl *getField() { return Field; } 967193323Sed const FieldDecl *getField() const { return Field; } 968193323Sed 969193323Sed /// \brief Get the initialization expression that will be used. 970193323Sed const Expr *getExpr() const { return Field->getInClassInitializer(); } 971193323Sed Expr *getExpr() { return Field->getInClassInitializer(); } 972193323Sed 973193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 974193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 975193323Sed 976193323Sed static bool classof(const Stmt *T) { 977193323Sed return T->getStmtClass() == CXXDefaultInitExprClass; 978193323Sed } 979193323Sed 980193323Sed // Iterators 981193323Sed child_range children() { return child_range(); } 982193323Sed 983193323Sed friend class ASTReader; 984193323Sed friend class ASTStmtReader; 985193323Sed}; 986193323Sed 987193323Sed/// \brief Represents a C++ temporary. 988193323Sedclass CXXTemporary { 989193323Sed /// \brief The destructor that needs to be called. 990193323Sed const CXXDestructorDecl *Destructor; 991193323Sed 992193323Sed explicit CXXTemporary(const CXXDestructorDecl *destructor) 993193323Sed : Destructor(destructor) { } 994193323Sed 995193323Sedpublic: 996193323Sed static CXXTemporary *Create(const ASTContext &C, 997193323Sed const CXXDestructorDecl *Destructor); 998193323Sed 999193323Sed const CXXDestructorDecl *getDestructor() const { return Destructor; } 1000193323Sed void setDestructor(const CXXDestructorDecl *Dtor) { 1001193323Sed Destructor = Dtor; 1002193323Sed } 1003193323Sed}; 1004193323Sed 1005193323Sed/// \brief Represents binding an expression to a temporary. 1006193323Sed/// 1007193323Sed/// This ensures the destructor is called for the temporary. It should only be 1008193323Sed/// needed for non-POD, non-trivially destructable class types. For example: 1009193323Sed/// 1010193323Sed/// \code 1011193323Sed/// struct S { 1012193323Sed/// S() { } // User defined constructor makes S non-POD. 1013193323Sed/// ~S() { } // User defined destructor makes it non-trivial. 1014193323Sed/// }; 1015193323Sed/// void test() { 1016193323Sed/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 1017193323Sed/// } 1018193323Sed/// \endcode 1019193323Sedclass CXXBindTemporaryExpr : public Expr { 1020193323Sed CXXTemporary *Temp; 1021193323Sed 1022193323Sed Stmt *SubExpr; 1023193323Sed 1024193323Sed CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 1025193323Sed : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 1026193323Sed VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 1027193323Sed SubExpr->isValueDependent(), 1028193323Sed SubExpr->isInstantiationDependent(), 1029193323Sed SubExpr->containsUnexpandedParameterPack()), 1030193323Sed Temp(temp), SubExpr(SubExpr) { } 1031193323Sed 1032193323Sedpublic: 1033193323Sed CXXBindTemporaryExpr(EmptyShell Empty) 1034193323Sed : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 1035193323Sed 1036193323Sed static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp, 1037193323Sed Expr* SubExpr); 1038193323Sed 1039193323Sed CXXTemporary *getTemporary() { return Temp; } 1040193323Sed const CXXTemporary *getTemporary() const { return Temp; } 1041193323Sed void setTemporary(CXXTemporary *T) { Temp = T; } 1042193323Sed 1043193323Sed const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1044193323Sed Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1045193323Sed void setSubExpr(Expr *E) { SubExpr = E; } 1046193323Sed 1047193323Sed SourceLocation getLocStart() const LLVM_READONLY { 1048193323Sed return SubExpr->getLocStart(); 1049193323Sed } 1050193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 1051193323Sed 1052193323Sed // Implement isa/cast/dyncast/etc. 1053193323Sed static bool classof(const Stmt *T) { 1054193323Sed return T->getStmtClass() == CXXBindTemporaryExprClass; 1055193323Sed } 1056193323Sed 1057193323Sed // Iterators 1058193323Sed child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 1059193323Sed}; 1060193323Sed 1061193323Sed/// \brief Represents a call to a C++ constructor. 1062193323Sedclass CXXConstructExpr : public Expr { 1063193323Sedpublic: 1064193323Sed enum ConstructionKind { 1065193323Sed CK_Complete, 1066193323Sed CK_NonVirtualBase, 1067193323Sed CK_VirtualBase, 1068193323Sed CK_Delegating 1069193323Sed }; 1070193323Sed 1071193323Sedprivate: 1072193323Sed CXXConstructorDecl *Constructor; 1073193323Sed 1074193323Sed SourceLocation Loc; 1075193323Sed SourceRange ParenOrBraceRange; 1076193323Sed unsigned NumArgs : 16; 1077193323Sed bool Elidable : 1; 1078193323Sed bool HadMultipleCandidates : 1; 1079193323Sed bool ListInitialization : 1; 1080193323Sed bool ZeroInitialization : 1; 1081193323Sed unsigned ConstructKind : 2; 1082193323Sed Stmt **Args; 1083193323Sed 1084193323Sedprotected: 1085193323Sed CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T, 1086193323Sed SourceLocation Loc, 1087193323Sed CXXConstructorDecl *d, bool elidable, 1088193323Sed ArrayRef<Expr *> Args, 1089193323Sed bool HadMultipleCandidates, 1090193323Sed bool ListInitialization, 1091193323Sed bool ZeroInitialization, 1092193323Sed ConstructionKind ConstructKind, 1093193323Sed SourceRange ParenOrBraceRange); 1094193323Sed 1095193323Sed /// \brief Construct an empty C++ construction expression. 1096193323Sed CXXConstructExpr(StmtClass SC, EmptyShell Empty) 1097193323Sed : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 1098193323Sed HadMultipleCandidates(false), ListInitialization(false), 1099193323Sed ZeroInitialization(false), ConstructKind(0), Args(0) 1100193323Sed { } 1101193323Sed 1102193323Sedpublic: 1103193323Sed /// \brief Construct an empty C++ construction expression. 1104193323Sed explicit CXXConstructExpr(EmptyShell Empty) 1105193323Sed : Expr(CXXConstructExprClass, Empty), Constructor(0), 1106193323Sed NumArgs(0), Elidable(false), HadMultipleCandidates(false), 1107193323Sed ListInitialization(false), ZeroInitialization(false), 1108193323Sed ConstructKind(0), Args(0) 1109193323Sed { } 1110193323Sed 1111193323Sed static CXXConstructExpr *Create(const ASTContext &C, QualType T, 1112193323Sed SourceLocation Loc, 1113193323Sed CXXConstructorDecl *D, bool Elidable, 1114193323Sed ArrayRef<Expr *> Args, 1115193323Sed bool HadMultipleCandidates, 1116193323Sed bool ListInitialization, 1117193323Sed bool ZeroInitialization, 1118193323Sed ConstructionKind ConstructKind, 1119193323Sed SourceRange ParenOrBraceRange); 1120193323Sed 1121193323Sed CXXConstructorDecl* getConstructor() const { return Constructor; } 1122193323Sed void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 1123193323Sed 1124193323Sed SourceLocation getLocation() const { return Loc; } 1125193323Sed void setLocation(SourceLocation Loc) { this->Loc = Loc; } 1126193323Sed 1127193323Sed /// \brief Whether this construction is elidable. 1128193323Sed bool isElidable() const { return Elidable; } 1129193323Sed void setElidable(bool E) { Elidable = E; } 1130193323Sed 1131193323Sed /// \brief Whether the referred constructor was resolved from 1132193323Sed /// an overloaded set having size greater than 1. 1133193323Sed bool hadMultipleCandidates() const { return HadMultipleCandidates; } 1134193323Sed void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 1135193323Sed 1136193323Sed /// \brief Whether this constructor call was written as list-initialization. 1137193323Sed bool isListInitialization() const { return ListInitialization; } 1138193323Sed void setListInitialization(bool V) { ListInitialization = V; } 1139193323Sed 1140193323Sed /// \brief Whether this construction first requires 1141193323Sed /// zero-initialization before the initializer is called. 1142193323Sed bool requiresZeroInitialization() const { return ZeroInitialization; } 1143193323Sed void setRequiresZeroInitialization(bool ZeroInit) { 1144193323Sed ZeroInitialization = ZeroInit; 1145193323Sed } 1146193323Sed 1147193323Sed /// \brief Determine whether this constructor is actually constructing 1148193323Sed /// a base class (rather than a complete object). 1149193323Sed ConstructionKind getConstructionKind() const { 1150193323Sed return (ConstructionKind)ConstructKind; 1151193323Sed } 1152193323Sed void setConstructionKind(ConstructionKind CK) { 1153193323Sed ConstructKind = CK; 1154193323Sed } 1155193323Sed 1156193323Sed typedef ExprIterator arg_iterator; 1157193323Sed typedef ConstExprIterator const_arg_iterator; 1158193323Sed 1159193323Sed arg_iterator arg_begin() { return Args; } 1160193323Sed arg_iterator arg_end() { return Args + NumArgs; } 1161193323Sed const_arg_iterator arg_begin() const { return Args; } 1162193323Sed const_arg_iterator arg_end() const { return Args + NumArgs; } 1163193323Sed 1164193323Sed Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 1165193323Sed unsigned getNumArgs() const { return NumArgs; } 1166193323Sed 1167193323Sed /// \brief Return the specified argument. 1168193323Sed Expr *getArg(unsigned Arg) { 1169193323Sed assert(Arg < NumArgs && "Arg access out of range!"); 1170193323Sed return cast<Expr>(Args[Arg]); 1171193323Sed } 1172193323Sed const Expr *getArg(unsigned Arg) const { 1173193323Sed assert(Arg < NumArgs && "Arg access out of range!"); 1174193323Sed return cast<Expr>(Args[Arg]); 1175193323Sed } 1176193323Sed 1177193323Sed /// \brief Set the specified argument. 1178193323Sed void setArg(unsigned Arg, Expr *ArgExpr) { 1179193323Sed assert(Arg < NumArgs && "Arg access out of range!"); 1180193323Sed Args[Arg] = ArgExpr; 1181193323Sed } 1182193323Sed 1183193323Sed SourceLocation getLocStart() const LLVM_READONLY; 1184193323Sed SourceLocation getLocEnd() const LLVM_READONLY; 1185193323Sed SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; } 1186193323Sed void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; } 1187193323Sed 1188193323Sed static bool classof(const Stmt *T) { 1189193323Sed return T->getStmtClass() == CXXConstructExprClass || 1190193323Sed T->getStmtClass() == CXXTemporaryObjectExprClass; 1191193323Sed } 1192193323Sed 1193193323Sed // Iterators 1194193323Sed child_range children() { 1195193323Sed return child_range(&Args[0], &Args[0]+NumArgs); 1196193323Sed } 1197193323Sed 1198193323Sed friend class ASTStmtReader; 1199193323Sed}; 1200193323Sed 1201193323Sed/// \brief Represents an explicit C++ type conversion that uses "functional" 1202193323Sed/// notation (C++ [expr.type.conv]). 1203193323Sed/// 1204193323Sed/// Example: 1205193323Sed/// \code 1206193323Sed/// x = int(0.5); 1207193323Sed/// \endcode 1208193323Sedclass CXXFunctionalCastExpr : public ExplicitCastExpr { 1209193323Sed SourceLocation LParenLoc; 1210193323Sed SourceLocation RParenLoc; 1211193323Sed 1212193323Sed CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 1213193323Sed TypeSourceInfo *writtenTy, 1214193323Sed CastKind kind, Expr *castExpr, unsigned pathSize, 1215193323Sed SourceLocation lParenLoc, SourceLocation rParenLoc) 1216193323Sed : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 1217193323Sed castExpr, pathSize, writtenTy), 1218193323Sed LParenLoc(lParenLoc), RParenLoc(rParenLoc) {} 1219193323Sed 1220193323Sed explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 1221193323Sed : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 1222193323Sed 1223193323Sedpublic: 1224193323Sed static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T, 1225193323Sed ExprValueKind VK, 1226193323Sed TypeSourceInfo *Written, 1227193323Sed CastKind Kind, Expr *Op, 1228193323Sed const CXXCastPath *Path, 1229193323Sed SourceLocation LPLoc, 1230193323Sed SourceLocation RPLoc); 1231193323Sed static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context, 1232193323Sed unsigned PathSize); 1233193323Sed 1234193323Sed SourceLocation getLParenLoc() const { return LParenLoc; } 1235193323Sed void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1236193323Sed SourceLocation getRParenLoc() const { return RParenLoc; } 1237193323Sed void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1238193323Sed 1239193323Sed SourceLocation getLocStart() const LLVM_READONLY; 1240193323Sed SourceLocation getLocEnd() const LLVM_READONLY; 1241193323Sed 1242193323Sed static bool classof(const Stmt *T) { 1243193323Sed return T->getStmtClass() == CXXFunctionalCastExprClass; 1244193323Sed } 1245193323Sed}; 1246193323Sed 1247193323Sed/// @brief Represents a C++ functional cast expression that builds a 1248193323Sed/// temporary object. 1249193323Sed/// 1250193323Sed/// This expression type represents a C++ "functional" cast 1251193323Sed/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 1252193323Sed/// constructor to build a temporary object. With N == 1 arguments the 1253193323Sed/// functional cast expression will be represented by CXXFunctionalCastExpr. 1254193323Sed/// Example: 1255193323Sed/// \code 1256193323Sed/// struct X { X(int, float); } 1257193323Sed/// 1258193323Sed/// X create_X() { 1259193323Sed/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 1260193323Sed/// }; 1261193323Sed/// \endcode 1262193323Sedclass CXXTemporaryObjectExpr : public CXXConstructExpr { 1263193323Sed TypeSourceInfo *Type; 1264193323Sed 1265193323Sedpublic: 1266193323Sed CXXTemporaryObjectExpr(const ASTContext &C, CXXConstructorDecl *Cons, 1267193323Sed TypeSourceInfo *Type, 1268193323Sed ArrayRef<Expr *> Args, 1269193323Sed SourceRange ParenOrBraceRange, 1270193323Sed bool HadMultipleCandidates, 1271193323Sed bool ListInitialization, 1272193323Sed bool ZeroInitialization); 1273193323Sed explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1274193323Sed : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1275193323Sed 1276193323Sed TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1277193323Sed 1278193323Sed SourceLocation getLocStart() const LLVM_READONLY; 1279193323Sed SourceLocation getLocEnd() const LLVM_READONLY; 1280193323Sed 1281193323Sed static bool classof(const Stmt *T) { 1282193323Sed return T->getStmtClass() == CXXTemporaryObjectExprClass; 1283193323Sed } 1284193323Sed 1285193323Sed friend class ASTStmtReader; 1286193323Sed}; 1287193323Sed 1288193323Sed/// \brief A C++ lambda expression, which produces a function object 1289193323Sed/// (of unspecified type) that can be invoked later. 1290193323Sed/// 1291193323Sed/// Example: 1292193323Sed/// \code 1293193323Sed/// void low_pass_filter(std::vector<double> &values, double cutoff) { 1294193323Sed/// values.erase(std::remove_if(values.begin(), values.end(), 1295193323Sed/// [=](double value) { return value > cutoff; }); 1296193323Sed/// } 1297193323Sed/// \endcode 1298193323Sed/// 1299193323Sed/// C++11 lambda expressions can capture local variables, either by copying 1300193323Sed/// the values of those local variables at the time the function 1301193323Sed/// object is constructed (not when it is called!) or by holding a 1302193323Sed/// reference to the local variable. These captures can occur either 1303193323Sed/// implicitly or can be written explicitly between the square 1304193323Sed/// brackets ([...]) that start the lambda expression. 1305193323Sed/// 1306193323Sed/// C++1y introduces a new form of "capture" called an init-capture that 1307193323Sed/// includes an initializing expression (rather than capturing a variable), 1308193323Sed/// and which can never occur implicitly. 1309193323Sedclass LambdaExpr : public Expr { 1310193323Sed enum { 1311193323Sed /// \brief Flag used by the Capture class to indicate that the given 1312193323Sed /// capture was implicit. 1313193323Sed Capture_Implicit = 0x01, 1314193323Sed 1315193323Sed /// \brief Flag used by the Capture class to indicate that the 1316193323Sed /// given capture was by-copy. 1317193323Sed /// 1318193323Sed /// This includes the case of a non-reference init-capture. 1319193323Sed Capture_ByCopy = 0x02 1320193323Sed }; 1321193323Sed 1322193323Sed /// \brief The source range that covers the lambda introducer ([...]). 1323193323Sed SourceRange IntroducerRange; 1324193323Sed 1325193323Sed /// \brief The source location of this lambda's capture-default ('=' or '&'). 1326193323Sed SourceLocation CaptureDefaultLoc; 1327193323Sed 1328193323Sed /// \brief The number of captures. 1329193323Sed unsigned NumCaptures : 16; 1330193323Sed 1331193323Sed /// \brief The default capture kind, which is a value of type 1332193323Sed /// LambdaCaptureDefault. 1333193323Sed unsigned CaptureDefault : 2; 1334193323Sed 1335193323Sed /// \brief Whether this lambda had an explicit parameter list vs. an 1336193323Sed /// implicit (and empty) parameter list. 1337193323Sed unsigned ExplicitParams : 1; 1338193323Sed 1339193323Sed /// \brief Whether this lambda had the result type explicitly specified. 1340193323Sed unsigned ExplicitResultType : 1; 1341193323Sed 1342193323Sed /// \brief Whether there are any array index variables stored at the end of 1343193323Sed /// this lambda expression. 1344193323Sed unsigned HasArrayIndexVars : 1; 1345193323Sed 1346193323Sed /// \brief The location of the closing brace ('}') that completes 1347193323Sed /// the lambda. 1348193323Sed /// 1349193323Sed /// The location of the brace is also available by looking up the 1350193323Sed /// function call operator in the lambda class. However, it is 1351193323Sed /// stored here to improve the performance of getSourceRange(), and 1352193323Sed /// to avoid having to deserialize the function call operator from a 1353193323Sed /// module file just to determine the source range. 1354193323Sed SourceLocation ClosingBrace; 1355193323Sed 1356193323Sed // Note: The capture initializers are stored directly after the lambda 1357193323Sed // expression, along with the index variables used to initialize by-copy 1358193323Sed // array captures. 1359193323Sed 1360193323Sedpublic: 1361193323Sed /// \brief Describes the capture of a variable or of \c this, or of a 1362193323Sed /// C++1y init-capture. 1363193323Sed class Capture { 1364193323Sed llvm::PointerIntPair<Decl *, 2> DeclAndBits; 1365193323Sed SourceLocation Loc; 1366193323Sed SourceLocation EllipsisLoc; 1367193323Sed 1368193323Sed friend class ASTStmtReader; 1369193323Sed friend class ASTStmtWriter; 1370193323Sed 1371193323Sed public: 1372193323Sed /// \brief Create a new capture of a variable or of \c this. 1373193323Sed /// 1374193323Sed /// \param Loc The source location associated with this capture. 1375193323Sed /// 1376193323Sed /// \param Kind The kind of capture (this, byref, bycopy), which must 1377193323Sed /// not be init-capture. 1378193323Sed /// 1379193323Sed /// \param Implicit Whether the capture was implicit or explicit. 1380193323Sed /// 1381193323Sed /// \param Var The local variable being captured, or null if capturing 1382193323Sed /// \c this. 1383193323Sed /// 1384193323Sed /// \param EllipsisLoc The location of the ellipsis (...) for a 1385193323Sed /// capture that is a pack expansion, or an invalid source 1386193323Sed /// location to indicate that this is not a pack expansion. 1387193323Sed Capture(SourceLocation Loc, bool Implicit, 1388193323Sed LambdaCaptureKind Kind, VarDecl *Var = 0, 1389193323Sed SourceLocation EllipsisLoc = SourceLocation()); 1390193323Sed 1391193323Sed /// \brief Determine the kind of capture. 1392193323Sed LambdaCaptureKind getCaptureKind() const; 1393193323Sed 1394193323Sed /// \brief Determine whether this capture handles the C++ \c this 1395193323Sed /// pointer. 1396193323Sed bool capturesThis() const { return DeclAndBits.getPointer() == 0; } 1397193323Sed 1398193323Sed /// \brief Determine whether this capture handles a variable. 1399193323Sed bool capturesVariable() const { 1400193323Sed return dyn_cast_or_null<VarDecl>(DeclAndBits.getPointer()); 1401193323Sed } 1402193323Sed 1403193323Sed /// \brief Determine whether this is an init-capture. 1404193323Sed bool isInitCapture() const { 1405193323Sed return capturesVariable() && getCapturedVar()->isInitCapture(); 1406193323Sed } 1407193323Sed 1408193323Sed /// \brief Retrieve the declaration of the local variable being 1409193323Sed /// captured. 1410193323Sed /// 1411193323Sed /// This operation is only valid if this capture is a variable capture 1412193323Sed /// (other than a capture of \c this). 1413193323Sed VarDecl *getCapturedVar() const { 1414193323Sed assert(capturesVariable() && "No variable available for 'this' capture"); 1415193323Sed return cast<VarDecl>(DeclAndBits.getPointer()); 1416193323Sed } 1417193323Sed 1418193323Sed /// \brief Determine whether this was an implicit capture (not 1419193323Sed /// written between the square brackets introducing the lambda). 1420193323Sed bool isImplicit() const { return DeclAndBits.getInt() & Capture_Implicit; } 1421193323Sed 1422193323Sed /// \brief Determine whether this was an explicit capture (written 1423193323Sed /// between the square brackets introducing the lambda). 1424193323Sed bool isExplicit() const { return !isImplicit(); } 1425193323Sed 1426193323Sed /// \brief Retrieve the source location of the capture. 1427193323Sed /// 1428193323Sed /// For an explicit capture, this returns the location of the 1429193323Sed /// explicit capture in the source. For an implicit capture, this 1430193323Sed /// returns the location at which the variable or \c this was first 1431193323Sed /// used. 1432193323Sed SourceLocation getLocation() const { return Loc; } 1433193323Sed 1434193323Sed /// \brief Determine whether this capture is a pack expansion, 1435193323Sed /// which captures a function parameter pack. 1436193323Sed bool isPackExpansion() const { return EllipsisLoc.isValid(); } 1437193323Sed 1438193323Sed /// \brief Retrieve the location of the ellipsis for a capture 1439193323Sed /// that is a pack expansion. 1440193323Sed SourceLocation getEllipsisLoc() const { 1441193323Sed assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 1442193323Sed return EllipsisLoc; 1443193323Sed } 1444193323Sed }; 1445193323Sed 1446193323Sedprivate: 1447193323Sed /// \brief Construct a lambda expression. 1448193323Sed LambdaExpr(QualType T, SourceRange IntroducerRange, 1449193323Sed LambdaCaptureDefault CaptureDefault, 1450193323Sed SourceLocation CaptureDefaultLoc, 1451193323Sed ArrayRef<Capture> Captures, 1452193323Sed bool ExplicitParams, 1453193323Sed bool ExplicitResultType, 1454193323Sed ArrayRef<Expr *> CaptureInits, 1455193323Sed ArrayRef<VarDecl *> ArrayIndexVars, 1456193323Sed ArrayRef<unsigned> ArrayIndexStarts, 1457193323Sed SourceLocation ClosingBrace, 1458193323Sed bool ContainsUnexpandedParameterPack); 1459193323Sed 1460193323Sed /// \brief Construct an empty lambda expression. 1461193323Sed LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars) 1462193323Sed : Expr(LambdaExprClass, Empty), 1463193323Sed NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false), 1464193323Sed ExplicitResultType(false), HasArrayIndexVars(true) { 1465193323Sed getStoredStmts()[NumCaptures] = 0; 1466193323Sed } 1467193323Sed 1468193323Sed Stmt **getStoredStmts() const { 1469193323Sed return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1); 1470193323Sed } 1471193323Sed 1472193323Sed /// \brief Retrieve the mapping from captures to the first array index 1473193323Sed /// variable. 1474193323Sed unsigned *getArrayIndexStarts() const { 1475193323Sed return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1); 1476193323Sed } 1477193323Sed 1478193323Sed /// \brief Retrieve the complete set of array-index variables. 1479193323Sed VarDecl **getArrayIndexVars() const { 1480193323Sed unsigned ArrayIndexSize = 1481193323Sed llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1), 1482193323Sed llvm::alignOf<VarDecl*>()); 1483193323Sed return reinterpret_cast<VarDecl **>( 1484193323Sed reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize); 1485193323Sed } 1486193323Sed 1487193323Sedpublic: 1488193323Sed /// \brief Construct a new lambda expression. 1489193323Sed static LambdaExpr *Create(const ASTContext &C, 1490193323Sed CXXRecordDecl *Class, 1491193323Sed SourceRange IntroducerRange, 1492193323Sed LambdaCaptureDefault CaptureDefault, 1493193323Sed SourceLocation CaptureDefaultLoc, 1494193323Sed ArrayRef<Capture> Captures, 1495193323Sed bool ExplicitParams, 1496193323Sed bool ExplicitResultType, 1497193323Sed ArrayRef<Expr *> CaptureInits, 1498193323Sed ArrayRef<VarDecl *> ArrayIndexVars, 1499193323Sed ArrayRef<unsigned> ArrayIndexStarts, 1500193323Sed SourceLocation ClosingBrace, 1501193323Sed bool ContainsUnexpandedParameterPack); 1502193323Sed 1503193323Sed /// \brief Construct a new lambda expression that will be deserialized from 1504193323Sed /// an external source. 1505193323Sed static LambdaExpr *CreateDeserialized(const ASTContext &C, 1506193323Sed unsigned NumCaptures, 1507193323Sed unsigned NumArrayIndexVars); 1508193323Sed 1509193323Sed /// \brief Determine the default capture kind for this lambda. 1510193323Sed LambdaCaptureDefault getCaptureDefault() const { 1511193323Sed return static_cast<LambdaCaptureDefault>(CaptureDefault); 1512193323Sed } 1513193323Sed 1514193323Sed /// \brief Retrieve the location of this lambda's capture-default, if any. 1515193323Sed SourceLocation getCaptureDefaultLoc() const { 1516193323Sed return CaptureDefaultLoc; 1517193323Sed } 1518193323Sed 1519193323Sed /// \brief An iterator that walks over the captures of the lambda, 1520193323Sed /// both implicit and explicit. 1521193323Sed typedef const Capture *capture_iterator; 1522193323Sed 1523193323Sed /// \brief Retrieve an iterator pointing to the first lambda capture. 1524193323Sed capture_iterator capture_begin() const; 1525193323Sed 1526193323Sed /// \brief Retrieve an iterator pointing past the end of the 1527193323Sed /// sequence of lambda captures. 1528193323Sed capture_iterator capture_end() const; 1529193323Sed 1530193323Sed /// \brief Determine the number of captures in this lambda. 1531193323Sed unsigned capture_size() const { return NumCaptures; } 1532193323Sed 1533193323Sed /// \brief Retrieve an iterator pointing to the first explicit 1534193323Sed /// lambda capture. 1535193323Sed capture_iterator explicit_capture_begin() const; 1536193323Sed 1537193323Sed /// \brief Retrieve an iterator pointing past the end of the sequence of 1538193323Sed /// explicit lambda captures. 1539193323Sed capture_iterator explicit_capture_end() const; 1540193323Sed 1541193323Sed /// \brief Retrieve an iterator pointing to the first implicit 1542193323Sed /// lambda capture. 1543193323Sed capture_iterator implicit_capture_begin() const; 1544193323Sed 1545193323Sed /// \brief Retrieve an iterator pointing past the end of the sequence of 1546193323Sed /// implicit lambda captures. 1547193323Sed capture_iterator implicit_capture_end() const; 1548193323Sed 1549193323Sed /// \brief Iterator that walks over the capture initialization 1550193323Sed /// arguments. 1551193323Sed typedef Expr **capture_init_iterator; 1552193323Sed 1553193323Sed /// \brief Retrieve the first initialization argument for this 1554193323Sed /// lambda expression (which initializes the first capture field). 1555193323Sed capture_init_iterator capture_init_begin() const { 1556193323Sed return reinterpret_cast<Expr **>(getStoredStmts()); 1557193323Sed } 1558193323Sed 1559193323Sed /// \brief Retrieve the iterator pointing one past the last 1560193323Sed /// initialization argument for this lambda expression. 1561193323Sed capture_init_iterator capture_init_end() const { 1562193323Sed return capture_init_begin() + NumCaptures; 1563193323Sed } 1564193323Sed 1565193323Sed /// \brief Retrieve the set of index variables used in the capture 1566193323Sed /// initializer of an array captured by copy. 1567193323Sed /// 1568193323Sed /// \param Iter The iterator that points at the capture initializer for 1569193323Sed /// which we are extracting the corresponding index variables. 1570193323Sed ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const; 1571193323Sed 1572193323Sed /// \brief Retrieve the source range covering the lambda introducer, 1573193323Sed /// which contains the explicit capture list surrounded by square 1574193323Sed /// brackets ([...]). 1575193323Sed SourceRange getIntroducerRange() const { return IntroducerRange; } 1576193323Sed 1577193323Sed /// \brief Retrieve the class that corresponds to the lambda. 1578193323Sed /// 1579193323Sed /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the 1580193323Sed /// captures in its fields and provides the various operations permitted 1581193323Sed /// on a lambda (copying, calling). 1582193323Sed CXXRecordDecl *getLambdaClass() const; 1583193323Sed 1584193323Sed /// \brief Retrieve the function call operator associated with this 1585193323Sed /// lambda expression. 1586193323Sed CXXMethodDecl *getCallOperator() const; 1587193323Sed 1588193323Sed /// \brief If this is a generic lambda expression, retrieve the template 1589193323Sed /// parameter list associated with it, or else return null. 1590193323Sed TemplateParameterList *getTemplateParameterList() const; 1591193323Sed 1592193323Sed /// \brief Whether this is a generic lambda. 1593193323Sed bool isGenericLambda() const { return getTemplateParameterList(); } 1594193323Sed 1595193323Sed /// \brief Retrieve the body of the lambda. 1596193323Sed CompoundStmt *getBody() const; 1597193323Sed 1598193323Sed /// \brief Determine whether the lambda is mutable, meaning that any 1599193323Sed /// captures values can be modified. 1600193323Sed bool isMutable() const; 1601193323Sed 1602193323Sed /// \brief Determine whether this lambda has an explicit parameter 1603193323Sed /// list vs. an implicit (empty) parameter list. 1604193323Sed bool hasExplicitParameters() const { return ExplicitParams; } 1605193323Sed 1606193323Sed /// \brief Whether this lambda had its result type explicitly specified. 1607193323Sed bool hasExplicitResultType() const { return ExplicitResultType; } 1608193323Sed 1609193323Sed static bool classof(const Stmt *T) { 1610193323Sed return T->getStmtClass() == LambdaExprClass; 1611193323Sed } 1612193323Sed 1613193323Sed SourceLocation getLocStart() const LLVM_READONLY { 1614193323Sed return IntroducerRange.getBegin(); 1615193323Sed } 1616193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; } 1617193323Sed 1618193323Sed child_range children() { 1619193323Sed return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); 1620193323Sed } 1621193323Sed 1622193323Sed friend class ASTStmtReader; 1623193323Sed friend class ASTStmtWriter; 1624193323Sed}; 1625193323Sed 1626193323Sed/// An expression "T()" which creates a value-initialized rvalue of type 1627193323Sed/// T, which is a non-class type. See (C++98 [5.2.3p2]). 1628193323Sedclass CXXScalarValueInitExpr : public Expr { 1629193323Sed SourceLocation RParenLoc; 1630193323Sed TypeSourceInfo *TypeInfo; 1631193323Sed 1632193323Sed friend class ASTStmtReader; 1633193323Sed 1634193323Sedpublic: 1635193323Sed /// \brief Create an explicitly-written scalar-value initialization 1636193323Sed /// expression. 1637193323Sed CXXScalarValueInitExpr(QualType Type, 1638193323Sed TypeSourceInfo *TypeInfo, 1639193323Sed SourceLocation rParenLoc ) : 1640193323Sed Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 1641193323Sed false, false, Type->isInstantiationDependentType(), false), 1642193323Sed RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 1643193323Sed 1644193323Sed explicit CXXScalarValueInitExpr(EmptyShell Shell) 1645193323Sed : Expr(CXXScalarValueInitExprClass, Shell) { } 1646193323Sed 1647193323Sed TypeSourceInfo *getTypeSourceInfo() const { 1648193323Sed return TypeInfo; 1649193323Sed } 1650193323Sed 1651193323Sed SourceLocation getRParenLoc() const { return RParenLoc; } 1652193323Sed 1653193323Sed SourceLocation getLocStart() const LLVM_READONLY; 1654193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 1655193323Sed 1656193323Sed static bool classof(const Stmt *T) { 1657193323Sed return T->getStmtClass() == CXXScalarValueInitExprClass; 1658193323Sed } 1659193323Sed 1660193323Sed // Iterators 1661193323Sed child_range children() { return child_range(); } 1662193323Sed}; 1663193323Sed 1664193323Sed/// \brief Represents a new-expression for memory allocation and constructor 1665193323Sed/// calls, e.g: "new CXXNewExpr(foo)". 1666193323Sedclass CXXNewExpr : public Expr { 1667193323Sed /// Contains an optional array size expression, an optional initialization 1668193323Sed /// expression, and any number of optional placement arguments, in that order. 1669193323Sed Stmt **SubExprs; 1670193323Sed /// \brief Points to the allocation function used. 1671193323Sed FunctionDecl *OperatorNew; 1672193323Sed /// \brief Points to the deallocation function used in case of error. May be 1673193323Sed /// null. 1674193323Sed FunctionDecl *OperatorDelete; 1675193323Sed 1676193323Sed /// \brief The allocated type-source information, as written in the source. 1677193323Sed TypeSourceInfo *AllocatedTypeInfo; 1678193323Sed 1679193323Sed /// \brief If the allocated type was expressed as a parenthesized type-id, 1680193323Sed /// the source range covering the parenthesized type-id. 1681193323Sed SourceRange TypeIdParens; 1682193323Sed 1683193323Sed /// \brief Range of the entire new expression. 1684193323Sed SourceRange Range; 1685193323Sed 1686193323Sed /// \brief Source-range of a paren-delimited initializer. 1687193323Sed SourceRange DirectInitRange; 1688193323Sed 1689193323Sed /// Was the usage ::new, i.e. is the global new to be used? 1690193323Sed bool GlobalNew : 1; 1691193323Sed /// Do we allocate an array? If so, the first SubExpr is the size expression. 1692193323Sed bool Array : 1; 1693193323Sed /// If this is an array allocation, does the usual deallocation 1694193323Sed /// function for the allocated type want to know the allocated size? 1695193323Sed bool UsualArrayDeleteWantsSize : 1; 1696193323Sed /// The number of placement new arguments. 1697193323Sed unsigned NumPlacementArgs : 13; 1698193323Sed /// What kind of initializer do we have? Could be none, parens, or braces. 1699193323Sed /// In storage, we distinguish between "none, and no initializer expr", and 1700193323Sed /// "none, but an implicit initializer expr". 1701193323Sed unsigned StoredInitializationStyle : 2; 1702193323Sed 1703193323Sed friend class ASTStmtReader; 1704193323Sed friend class ASTStmtWriter; 1705193323Sedpublic: 1706193323Sed enum InitializationStyle { 1707193323Sed NoInit, ///< New-expression has no initializer as written. 1708193323Sed CallInit, ///< New-expression has a C++98 paren-delimited initializer. 1709193323Sed ListInit ///< New-expression has a C++11 list-initializer. 1710193323Sed }; 1711193323Sed 1712193323Sed CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 1713193323Sed FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, 1714193323Sed ArrayRef<Expr*> placementArgs, 1715193323Sed SourceRange typeIdParens, Expr *arraySize, 1716193323Sed InitializationStyle initializationStyle, Expr *initializer, 1717193323Sed QualType ty, TypeSourceInfo *AllocatedTypeInfo, 1718193323Sed SourceRange Range, SourceRange directInitRange); 1719193323Sed explicit CXXNewExpr(EmptyShell Shell) 1720193323Sed : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 1721193323Sed 1722193323Sed void AllocateArgsArray(const ASTContext &C, bool isArray, 1723193323Sed unsigned numPlaceArgs, bool hasInitializer); 1724193323Sed 1725193323Sed QualType getAllocatedType() const { 1726193323Sed assert(getType()->isPointerType()); 1727193323Sed return getType()->getAs<PointerType>()->getPointeeType(); 1728193323Sed } 1729193323Sed 1730193323Sed TypeSourceInfo *getAllocatedTypeSourceInfo() const { 1731193323Sed return AllocatedTypeInfo; 1732193323Sed } 1733193323Sed 1734193323Sed /// \brief True if the allocation result needs to be null-checked. 1735193323Sed /// 1736193323Sed /// C++11 [expr.new]p13: 1737193323Sed /// If the allocation function returns null, initialization shall 1738193323Sed /// not be done, the deallocation function shall not be called, 1739193323Sed /// and the value of the new-expression shall be null. 1740193323Sed /// 1741193323Sed /// An allocation function is not allowed to return null unless it 1742193323Sed /// has a non-throwing exception-specification. The '03 rule is 1743193323Sed /// identical except that the definition of a non-throwing 1744193323Sed /// exception specification is just "is it throw()?". 1745193323Sed bool shouldNullCheckAllocation(const ASTContext &Ctx) const; 1746193323Sed 1747193323Sed FunctionDecl *getOperatorNew() const { return OperatorNew; } 1748193323Sed void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 1749193323Sed FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1750193323Sed void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 1751193323Sed 1752193323Sed bool isArray() const { return Array; } 1753193323Sed Expr *getArraySize() { 1754193323Sed return Array ? cast<Expr>(SubExprs[0]) : 0; 1755193323Sed } 1756193323Sed const Expr *getArraySize() const { 1757193323Sed return Array ? cast<Expr>(SubExprs[0]) : 0; 1758193323Sed } 1759193323Sed 1760193323Sed unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1761193323Sed Expr **getPlacementArgs() { 1762193323Sed return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer()); 1763193323Sed } 1764193323Sed 1765193323Sed Expr *getPlacementArg(unsigned i) { 1766193323Sed assert(i < NumPlacementArgs && "Index out of range"); 1767193323Sed return getPlacementArgs()[i]; 1768193323Sed } 1769193323Sed const Expr *getPlacementArg(unsigned i) const { 1770193323Sed assert(i < NumPlacementArgs && "Index out of range"); 1771193323Sed return const_cast<CXXNewExpr*>(this)->getPlacementArg(i); 1772193323Sed } 1773193323Sed 1774193323Sed bool isParenTypeId() const { return TypeIdParens.isValid(); } 1775193323Sed SourceRange getTypeIdParens() const { return TypeIdParens; } 1776193323Sed 1777193323Sed bool isGlobalNew() const { return GlobalNew; } 1778193323Sed 1779193323Sed /// \brief Whether this new-expression has any initializer at all. 1780193323Sed bool hasInitializer() const { return StoredInitializationStyle > 0; } 1781193323Sed 1782193323Sed /// \brief The kind of initializer this new-expression has. 1783193323Sed InitializationStyle getInitializationStyle() const { 1784193323Sed if (StoredInitializationStyle == 0) 1785193323Sed return NoInit; 1786193323Sed return static_cast<InitializationStyle>(StoredInitializationStyle-1); 1787193323Sed } 1788193323Sed 1789193323Sed /// \brief The initializer of this new-expression. 1790193323Sed Expr *getInitializer() { 1791193323Sed return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 1792193323Sed } 1793193323Sed const Expr *getInitializer() const { 1794193323Sed return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 1795193323Sed } 1796193323Sed 1797193323Sed /// \brief Returns the CXXConstructExpr from this new-expression, or null. 1798193323Sed const CXXConstructExpr* getConstructExpr() const { 1799193323Sed return dyn_cast_or_null<CXXConstructExpr>(getInitializer()); 1800193323Sed } 1801193323Sed 1802193323Sed /// Answers whether the usual array deallocation function for the 1803193323Sed /// allocated type expects the size of the allocation as a 1804193323Sed /// parameter. 1805193323Sed bool doesUsualArrayDeleteWantSize() const { 1806193323Sed return UsualArrayDeleteWantsSize; 1807193323Sed } 1808193323Sed 1809193323Sed typedef ExprIterator arg_iterator; 1810193323Sed typedef ConstExprIterator const_arg_iterator; 1811193323Sed 1812193323Sed arg_iterator placement_arg_begin() { 1813193323Sed return SubExprs + Array + hasInitializer(); 1814193323Sed } 1815193323Sed arg_iterator placement_arg_end() { 1816193323Sed return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1817193323Sed } 1818193323Sed const_arg_iterator placement_arg_begin() const { 1819193323Sed return SubExprs + Array + hasInitializer(); 1820193323Sed } 1821193323Sed const_arg_iterator placement_arg_end() const { 1822193323Sed return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1823193323Sed } 1824193323Sed 1825193323Sed typedef Stmt **raw_arg_iterator; 1826193323Sed raw_arg_iterator raw_arg_begin() { return SubExprs; } 1827193323Sed raw_arg_iterator raw_arg_end() { 1828193323Sed return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1829193323Sed } 1830193323Sed const_arg_iterator raw_arg_begin() const { return SubExprs; } 1831193323Sed const_arg_iterator raw_arg_end() const { 1832193323Sed return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1833193323Sed } 1834193323Sed 1835193323Sed SourceLocation getStartLoc() const { return Range.getBegin(); } 1836193323Sed SourceLocation getEndLoc() const { return Range.getEnd(); } 1837193323Sed 1838193323Sed SourceRange getDirectInitRange() const { return DirectInitRange; } 1839193323Sed 1840193323Sed SourceRange getSourceRange() const LLVM_READONLY { 1841193323Sed return Range; 1842193323Sed } 1843193323Sed SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); } 1844193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 1845193323Sed 1846193323Sed static bool classof(const Stmt *T) { 1847193323Sed return T->getStmtClass() == CXXNewExprClass; 1848193323Sed } 1849193323Sed 1850193323Sed // Iterators 1851193323Sed child_range children() { 1852193323Sed return child_range(raw_arg_begin(), raw_arg_end()); 1853193323Sed } 1854193323Sed}; 1855193323Sed 1856193323Sed/// \brief Represents a \c delete expression for memory deallocation and 1857193323Sed/// destructor calls, e.g. "delete[] pArray". 1858193323Sedclass CXXDeleteExpr : public Expr { 1859193323Sed /// Points to the operator delete overload that is used. Could be a member. 1860193323Sed FunctionDecl *OperatorDelete; 1861193323Sed /// The pointer expression to be deleted. 1862193323Sed Stmt *Argument; 1863193323Sed /// Location of the expression. 1864193323Sed SourceLocation Loc; 1865193323Sed /// Is this a forced global delete, i.e. "::delete"? 1866193323Sed bool GlobalDelete : 1; 1867193323Sed /// Is this the array form of delete, i.e. "delete[]"? 1868193323Sed bool ArrayForm : 1; 1869193323Sed /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 1870193323Sed /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 1871193323Sed /// will be true). 1872193323Sed bool ArrayFormAsWritten : 1; 1873193323Sed /// Does the usual deallocation function for the element type require 1874193323Sed /// a size_t argument? 1875193323Sed bool UsualArrayDeleteWantsSize : 1; 1876193323Sedpublic: 1877193323Sed CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 1878193323Sed bool arrayFormAsWritten, bool usualArrayDeleteWantsSize, 1879193323Sed FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1880193323Sed : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1881193323Sed arg->isInstantiationDependent(), 1882193323Sed arg->containsUnexpandedParameterPack()), 1883193323Sed OperatorDelete(operatorDelete), Argument(arg), Loc(loc), 1884193323Sed GlobalDelete(globalDelete), 1885193323Sed ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 1886193323Sed UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { } 1887193323Sed explicit CXXDeleteExpr(EmptyShell Shell) 1888193323Sed : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 1889193323Sed 1890193323Sed bool isGlobalDelete() const { return GlobalDelete; } 1891193323Sed bool isArrayForm() const { return ArrayForm; } 1892193323Sed bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 1893193323Sed 1894193323Sed /// Answers whether the usual array deallocation function for the 1895193323Sed /// allocated type expects the size of the allocation as a 1896193323Sed /// parameter. This can be true even if the actual deallocation 1897193323Sed /// function that we're using doesn't want a size. 1898193323Sed bool doesUsualArrayDeleteWantSize() const { 1899193323Sed return UsualArrayDeleteWantsSize; 1900193323Sed } 1901193323Sed 1902193323Sed FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1903193323Sed 1904193323Sed Expr *getArgument() { return cast<Expr>(Argument); } 1905193323Sed const Expr *getArgument() const { return cast<Expr>(Argument); } 1906193323Sed 1907193323Sed /// \brief Retrieve the type being destroyed. 1908193323Sed /// 1909193323Sed /// If the type being destroyed is a dependent type which may or may not 1910193323Sed /// be a pointer, return an invalid type. 1911193323Sed QualType getDestroyedType() const; 1912193323Sed 1913193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 1914193323Sed SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();} 1915193323Sed 1916193323Sed static bool classof(const Stmt *T) { 1917193323Sed return T->getStmtClass() == CXXDeleteExprClass; 1918193323Sed } 1919193323Sed 1920193323Sed // Iterators 1921193323Sed child_range children() { return child_range(&Argument, &Argument+1); } 1922193323Sed 1923193323Sed friend class ASTStmtReader; 1924193323Sed}; 1925193323Sed 1926193323Sed/// \brief Stores the type being destroyed by a pseudo-destructor expression. 1927193323Sedclass PseudoDestructorTypeStorage { 1928193323Sed /// \brief Either the type source information or the name of the type, if 1929193323Sed /// it couldn't be resolved due to type-dependence. 1930193323Sed llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1931193323Sed 1932193323Sed /// \brief The starting source location of the pseudo-destructor type. 1933193323Sed SourceLocation Location; 1934193323Sed 1935193323Sedpublic: 1936193323Sed PseudoDestructorTypeStorage() { } 1937193323Sed 1938193323Sed PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1939193323Sed : Type(II), Location(Loc) { } 1940193323Sed 1941193323Sed PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1942193323Sed 1943193323Sed TypeSourceInfo *getTypeSourceInfo() const { 1944193323Sed return Type.dyn_cast<TypeSourceInfo *>(); 1945193323Sed } 1946193323Sed 1947193323Sed IdentifierInfo *getIdentifier() const { 1948193323Sed return Type.dyn_cast<IdentifierInfo *>(); 1949193323Sed } 1950193323Sed 1951193323Sed SourceLocation getLocation() const { return Location; } 1952193323Sed}; 1953193323Sed 1954193323Sed/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1955193323Sed/// 1956193323Sed/// A pseudo-destructor is an expression that looks like a member access to a 1957193323Sed/// destructor of a scalar type, except that scalar types don't have 1958193323Sed/// destructors. For example: 1959193323Sed/// 1960193323Sed/// \code 1961193323Sed/// typedef int T; 1962193323Sed/// void f(int *p) { 1963193323Sed/// p->T::~T(); 1964193323Sed/// } 1965193323Sed/// \endcode 1966193323Sed/// 1967193323Sed/// Pseudo-destructors typically occur when instantiating templates such as: 1968193323Sed/// 1969193323Sed/// \code 1970193323Sed/// template<typename T> 1971193323Sed/// void destroy(T* ptr) { 1972193323Sed/// ptr->T::~T(); 1973193323Sed/// } 1974193323Sed/// \endcode 1975193323Sed/// 1976193323Sed/// for scalar types. A pseudo-destructor expression has no run-time semantics 1977193323Sed/// beyond evaluating the base expression. 1978193323Sedclass CXXPseudoDestructorExpr : public Expr { 1979193323Sed /// \brief The base expression (that is being destroyed). 1980193323Sed Stmt *Base; 1981193323Sed 1982193323Sed /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1983193323Sed /// period ('.'). 1984193323Sed bool IsArrow : 1; 1985193323Sed 1986193323Sed /// \brief The location of the '.' or '->' operator. 1987193323Sed SourceLocation OperatorLoc; 1988193323Sed 1989193323Sed /// \brief The nested-name-specifier that follows the operator, if present. 1990193323Sed NestedNameSpecifierLoc QualifierLoc; 1991193323Sed 1992193323Sed /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1993193323Sed /// expression. 1994193323Sed TypeSourceInfo *ScopeType; 1995193323Sed 1996193323Sed /// \brief The location of the '::' in a qualified pseudo-destructor 1997193323Sed /// expression. 1998193323Sed SourceLocation ColonColonLoc; 1999193323Sed 2000193323Sed /// \brief The location of the '~'. 2001193323Sed SourceLocation TildeLoc; 2002193323Sed 2003193323Sed /// \brief The type being destroyed, or its name if we were unable to 2004193323Sed /// resolve the name. 2005193323Sed PseudoDestructorTypeStorage DestroyedType; 2006193323Sed 2007193323Sed friend class ASTStmtReader; 2008193323Sed 2009193323Sedpublic: 2010194178Sed CXXPseudoDestructorExpr(const ASTContext &Context, 2011194178Sed Expr *Base, bool isArrow, SourceLocation OperatorLoc, 2012193323Sed NestedNameSpecifierLoc QualifierLoc, 2013194178Sed TypeSourceInfo *ScopeType, 2014194178Sed SourceLocation ColonColonLoc, 2015194178Sed SourceLocation TildeLoc, 2016194178Sed PseudoDestructorTypeStorage DestroyedType); 2017194178Sed 2018194178Sed explicit CXXPseudoDestructorExpr(EmptyShell Shell) 2019194178Sed : Expr(CXXPseudoDestructorExprClass, Shell), 2020194178Sed Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { } 2021194178Sed 2022194178Sed Expr *getBase() const { return cast<Expr>(Base); } 2023194178Sed 2024194178Sed /// \brief Determines whether this member expression actually had 2025194178Sed /// a C++ nested-name-specifier prior to the name of the member, e.g., 2026194178Sed /// x->Base::foo. 2027194178Sed bool hasQualifier() const { return QualifierLoc.hasQualifier(); } 2028194178Sed 2029194178Sed /// \brief Retrieves the nested-name-specifier that qualifies the type name, 2030194178Sed /// with source-location information. 2031194178Sed NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2032193323Sed 2033193323Sed /// \brief If the member name was qualified, retrieves the 2034193323Sed /// nested-name-specifier that precedes the member name. Otherwise, returns 2035193323Sed /// null. 2036193323Sed NestedNameSpecifier *getQualifier() const { 2037193323Sed return QualifierLoc.getNestedNameSpecifier(); 2038193323Sed } 2039193323Sed 2040193323Sed /// \brief Determine whether this pseudo-destructor expression was written 2041193323Sed /// using an '->' (otherwise, it used a '.'). 2042193323Sed bool isArrow() const { return IsArrow; } 2043193323Sed 2044193323Sed /// \brief Retrieve the location of the '.' or '->' operator. 2045193323Sed SourceLocation getOperatorLoc() const { return OperatorLoc; } 2046193323Sed 2047193323Sed /// \brief Retrieve the scope type in a qualified pseudo-destructor 2048193323Sed /// expression. 2049193323Sed /// 2050193323Sed /// Pseudo-destructor expressions can have extra qualification within them 2051193323Sed /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 2052193323Sed /// Here, if the object type of the expression is (or may be) a scalar type, 2053193323Sed /// \p T may also be a scalar type and, therefore, cannot be part of a 2054193323Sed /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 2055193323Sed /// destructor expression. 2056193323Sed TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 2057193323Sed 2058193323Sed /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 2059193323Sed /// expression. 2060193323Sed SourceLocation getColonColonLoc() const { return ColonColonLoc; } 2061193323Sed 2062193323Sed /// \brief Retrieve the location of the '~'. 2063193323Sed SourceLocation getTildeLoc() const { return TildeLoc; } 2064193323Sed 2065193323Sed /// \brief Retrieve the source location information for the type 2066193323Sed /// being destroyed. 2067193323Sed /// 2068193323Sed /// This type-source information is available for non-dependent 2069193323Sed /// pseudo-destructor expressions and some dependent pseudo-destructor 2070193323Sed /// expressions. Returns null if we only have the identifier for a 2071193323Sed /// dependent pseudo-destructor expression. 2072193323Sed TypeSourceInfo *getDestroyedTypeInfo() const { 2073193323Sed return DestroyedType.getTypeSourceInfo(); 2074193323Sed } 2075193323Sed 2076193323Sed /// \brief In a dependent pseudo-destructor expression for which we do not 2077193323Sed /// have full type information on the destroyed type, provides the name 2078193323Sed /// of the destroyed type. 2079193323Sed IdentifierInfo *getDestroyedTypeIdentifier() const { 2080193323Sed return DestroyedType.getIdentifier(); 2081193323Sed } 2082193323Sed 2083193323Sed /// \brief Retrieve the type being destroyed. 2084193323Sed QualType getDestroyedType() const; 2085193323Sed 2086193323Sed /// \brief Retrieve the starting location of the type being destroyed. 2087193323Sed SourceLocation getDestroyedTypeLoc() const { 2088193323Sed return DestroyedType.getLocation(); 2089193323Sed } 2090193323Sed 2091193323Sed /// \brief Set the name of destroyed type for a dependent pseudo-destructor 2092193323Sed /// expression. 2093193323Sed void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 2094193323Sed DestroyedType = PseudoDestructorTypeStorage(II, Loc); 2095193323Sed } 2096193323Sed 2097193323Sed /// \brief Set the destroyed type. 2098193323Sed void setDestroyedType(TypeSourceInfo *Info) { 2099193323Sed DestroyedType = PseudoDestructorTypeStorage(Info); 2100193323Sed } 2101193323Sed 2102193323Sed SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();} 2103193323Sed SourceLocation getLocEnd() const LLVM_READONLY; 2104193323Sed 2105193323Sed static bool classof(const Stmt *T) { 2106193323Sed return T->getStmtClass() == CXXPseudoDestructorExprClass; 2107193323Sed } 2108193323Sed 2109193323Sed // Iterators 2110193323Sed child_range children() { return child_range(&Base, &Base + 1); } 2111193323Sed}; 2112193323Sed 2113193323Sed/// \brief Represents a GCC or MS unary type trait, as used in the 2114193323Sed/// implementation of TR1/C++11 type trait templates. 2115193323Sed/// 2116193323Sed/// Example: 2117193323Sed/// \code 2118193323Sed/// __is_pod(int) == true 2119193323Sed/// __is_enum(std::string) == false 2120193323Sed/// \endcode 2121193323Sedclass UnaryTypeTraitExpr : public Expr { 2122193323Sed /// \brief The trait. A UnaryTypeTrait enum in MSVC compatible unsigned. 2123193323Sed unsigned UTT : 31; 2124193323Sed /// The value of the type trait. Unspecified if dependent. 2125193323Sed bool Value : 1; 2126193323Sed 2127193323Sed /// \brief The location of the type trait keyword. 2128193323Sed SourceLocation Loc; 2129193323Sed 2130193323Sed /// \brief The location of the closing paren. 2131193323Sed SourceLocation RParen; 2132193323Sed 2133193323Sed /// \brief The type being queried. 2134193323Sed TypeSourceInfo *QueriedType; 2135193323Sed 2136193323Sedpublic: 2137193323Sed UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 2138193323Sed TypeSourceInfo *queried, bool value, 2139193323Sed SourceLocation rparen, QualType ty) 2140193323Sed : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 2141193323Sed false, queried->getType()->isDependentType(), 2142193323Sed queried->getType()->isInstantiationDependentType(), 2143193323Sed queried->getType()->containsUnexpandedParameterPack()), 2144193323Sed UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 2145193323Sed 2146193323Sed explicit UnaryTypeTraitExpr(EmptyShell Empty) 2147193323Sed : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 2148193323Sed QueriedType() { } 2149193323Sed 2150193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2151193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2152193323Sed 2153193323Sed UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 2154193323Sed 2155193323Sed QualType getQueriedType() const { return QueriedType->getType(); } 2156193323Sed 2157193323Sed TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 2158193323Sed 2159193323Sed bool getValue() const { return Value; } 2160193323Sed 2161193323Sed static bool classof(const Stmt *T) { 2162193323Sed return T->getStmtClass() == UnaryTypeTraitExprClass; 2163193323Sed } 2164193323Sed 2165193323Sed // Iterators 2166193323Sed child_range children() { return child_range(); } 2167193323Sed 2168193323Sed friend class ASTStmtReader; 2169193323Sed}; 2170193323Sed 2171193323Sed/// \brief Represents a GCC or MS binary type trait, as used in the 2172193323Sed/// implementation of TR1/C++11 type trait templates. 2173193323Sed/// 2174193323Sed/// Example: 2175193323Sed/// \code 2176193323Sed/// __is_base_of(Base, Derived) == true 2177193323Sed/// \endcode 2178193323Sedclass BinaryTypeTraitExpr : public Expr { 2179193323Sed /// \brief The trait. A BinaryTypeTrait enum in MSVC compatible unsigned. 2180193323Sed unsigned BTT : 8; 2181193323Sed 2182193323Sed /// The value of the type trait. Unspecified if dependent. 2183193323Sed bool Value : 1; 2184193323Sed 2185193323Sed /// \brief The location of the type trait keyword. 2186193323Sed SourceLocation Loc; 2187193323Sed 2188193323Sed /// \brief The location of the closing paren. 2189193323Sed SourceLocation RParen; 2190193323Sed 2191193323Sed /// \brief The lhs type being queried. 2192193323Sed TypeSourceInfo *LhsType; 2193193323Sed 2194193323Sed /// \brief The rhs type being queried. 2195193323Sed TypeSourceInfo *RhsType; 2196193323Sed 2197193323Sedpublic: 2198193323Sed BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 2199193323Sed TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 2200193323Sed bool value, SourceLocation rparen, QualType ty) 2201193323Sed : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 2202193323Sed lhsType->getType()->isDependentType() || 2203193323Sed rhsType->getType()->isDependentType(), 2204193323Sed (lhsType->getType()->isInstantiationDependentType() || 2205193323Sed rhsType->getType()->isInstantiationDependentType()), 2206193323Sed (lhsType->getType()->containsUnexpandedParameterPack() || 2207193323Sed rhsType->getType()->containsUnexpandedParameterPack())), 2208193323Sed BTT(btt), Value(value), Loc(loc), RParen(rparen), 2209193323Sed LhsType(lhsType), RhsType(rhsType) { } 2210193323Sed 2211193323Sed 2212193323Sed explicit BinaryTypeTraitExpr(EmptyShell Empty) 2213193323Sed : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 2214193323Sed LhsType(), RhsType() { } 2215193323Sed 2216193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2217193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2218193323Sed 2219193323Sed BinaryTypeTrait getTrait() const { 2220193323Sed return static_cast<BinaryTypeTrait>(BTT); 2221193323Sed } 2222193323Sed 2223193323Sed QualType getLhsType() const { return LhsType->getType(); } 2224193323Sed QualType getRhsType() const { return RhsType->getType(); } 2225193323Sed 2226193323Sed TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 2227193323Sed TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 2228193323Sed 2229193323Sed bool getValue() const { assert(!isTypeDependent()); return Value; } 2230193323Sed 2231193323Sed static bool classof(const Stmt *T) { 2232193323Sed return T->getStmtClass() == BinaryTypeTraitExprClass; 2233193323Sed } 2234193323Sed 2235193323Sed // Iterators 2236193323Sed child_range children() { return child_range(); } 2237193323Sed 2238193323Sed friend class ASTStmtReader; 2239193323Sed}; 2240193323Sed 2241193323Sed/// \brief A type trait used in the implementation of various C++11 and 2242193323Sed/// Library TR1 trait templates. 2243193323Sed/// 2244193323Sed/// \code 2245193323Sed/// __is_trivially_constructible(vector<int>, int*, int*) 2246193323Sed/// \endcode 2247193323Sedclass TypeTraitExpr : public Expr { 2248193323Sed /// \brief The location of the type trait keyword. 2249193323Sed SourceLocation Loc; 2250193323Sed 2251193323Sed /// \brief The location of the closing parenthesis. 2252193323Sed SourceLocation RParenLoc; 2253193323Sed 2254193323Sed // Note: The TypeSourceInfos for the arguments are allocated after the 2255193323Sed // TypeTraitExpr. 2256193323Sed 2257193323Sed TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, 2258193323Sed ArrayRef<TypeSourceInfo *> Args, 2259193323Sed SourceLocation RParenLoc, 2260193323Sed bool Value); 2261193323Sed 2262193323Sed TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { } 2263193323Sed 2264193323Sed /// \brief Retrieve the argument types. 2265193323Sed TypeSourceInfo **getTypeSourceInfos() { 2266193323Sed return reinterpret_cast<TypeSourceInfo **>(this+1); 2267193323Sed } 2268193323Sed 2269193323Sed /// \brief Retrieve the argument types. 2270193323Sed TypeSourceInfo * const *getTypeSourceInfos() const { 2271193323Sed return reinterpret_cast<TypeSourceInfo * const*>(this+1); 2272193323Sed } 2273193323Sed 2274193323Sedpublic: 2275193323Sed /// \brief Create a new type trait expression. 2276193323Sed static TypeTraitExpr *Create(const ASTContext &C, QualType T, 2277193323Sed SourceLocation Loc, TypeTrait Kind, 2278193323Sed ArrayRef<TypeSourceInfo *> Args, 2279193323Sed SourceLocation RParenLoc, 2280193323Sed bool Value); 2281193323Sed 2282193323Sed static TypeTraitExpr *CreateDeserialized(const ASTContext &C, 2283193323Sed unsigned NumArgs); 2284193323Sed 2285193323Sed /// \brief Determine which type trait this expression uses. 2286193323Sed TypeTrait getTrait() const { 2287193323Sed return static_cast<TypeTrait>(TypeTraitExprBits.Kind); 2288193323Sed } 2289193323Sed 2290193323Sed bool getValue() const { 2291193323Sed assert(!isValueDependent()); 2292193323Sed return TypeTraitExprBits.Value; 2293193323Sed } 2294193323Sed 2295193323Sed /// \brief Determine the number of arguments to this type trait. 2296193323Sed unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; } 2297193323Sed 2298193323Sed /// \brief Retrieve the Ith argument. 2299193323Sed TypeSourceInfo *getArg(unsigned I) const { 2300193323Sed assert(I < getNumArgs() && "Argument out-of-range"); 2301193323Sed return getArgs()[I]; 2302193323Sed } 2303193323Sed 2304193323Sed /// \brief Retrieve the argument types. 2305193323Sed ArrayRef<TypeSourceInfo *> getArgs() const { 2306193323Sed return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs()); 2307193323Sed } 2308193323Sed 2309193323Sed typedef TypeSourceInfo **arg_iterator; 2310193323Sed arg_iterator arg_begin() { 2311193323Sed return getTypeSourceInfos(); 2312193323Sed } 2313193323Sed arg_iterator arg_end() { 2314193323Sed return getTypeSourceInfos() + getNumArgs(); 2315193323Sed } 2316193323Sed 2317193323Sed typedef TypeSourceInfo const * const *arg_const_iterator; 2318193323Sed arg_const_iterator arg_begin() const { return getTypeSourceInfos(); } 2319193323Sed arg_const_iterator arg_end() const { 2320193323Sed return getTypeSourceInfos() + getNumArgs(); 2321193323Sed } 2322193323Sed 2323193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2324193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 2325193323Sed 2326193323Sed static bool classof(const Stmt *T) { 2327193323Sed return T->getStmtClass() == TypeTraitExprClass; 2328193323Sed } 2329193323Sed 2330193323Sed // Iterators 2331193323Sed child_range children() { return child_range(); } 2332193323Sed 2333193323Sed friend class ASTStmtReader; 2334193323Sed friend class ASTStmtWriter; 2335193323Sed 2336193323Sed}; 2337193323Sed 2338193323Sed/// \brief An Embarcadero array type trait, as used in the implementation of 2339193323Sed/// __array_rank and __array_extent. 2340193323Sed/// 2341193323Sed/// Example: 2342193323Sed/// \code 2343193323Sed/// __array_rank(int[10][20]) == 2 2344193323Sed/// __array_extent(int, 1) == 20 2345193323Sed/// \endcode 2346193323Sedclass ArrayTypeTraitExpr : public Expr { 2347193323Sed virtual void anchor(); 2348193323Sed 2349193323Sed /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 2350193323Sed unsigned ATT : 2; 2351193323Sed 2352193323Sed /// \brief The value of the type trait. Unspecified if dependent. 2353193323Sed uint64_t Value; 2354193323Sed 2355193323Sed /// \brief The array dimension being queried, or -1 if not used. 2356193323Sed Expr *Dimension; 2357193323Sed 2358193323Sed /// \brief The location of the type trait keyword. 2359193323Sed SourceLocation Loc; 2360193323Sed 2361193323Sed /// \brief The location of the closing paren. 2362193323Sed SourceLocation RParen; 2363193323Sed 2364193323Sed /// \brief The type being queried. 2365193323Sed TypeSourceInfo *QueriedType; 2366193323Sed 2367193323Sedpublic: 2368193323Sed ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 2369193323Sed TypeSourceInfo *queried, uint64_t value, 2370193323Sed Expr *dimension, SourceLocation rparen, QualType ty) 2371193323Sed : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 2372193323Sed false, queried->getType()->isDependentType(), 2373193323Sed (queried->getType()->isInstantiationDependentType() || 2374193323Sed (dimension && dimension->isInstantiationDependent())), 2375193323Sed queried->getType()->containsUnexpandedParameterPack()), 2376193323Sed ATT(att), Value(value), Dimension(dimension), 2377193323Sed Loc(loc), RParen(rparen), QueriedType(queried) { } 2378193323Sed 2379193323Sed 2380193323Sed explicit ArrayTypeTraitExpr(EmptyShell Empty) 2381193323Sed : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 2382193323Sed QueriedType() { } 2383193323Sed 2384193323Sed virtual ~ArrayTypeTraitExpr() { } 2385193323Sed 2386193323Sed SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2387193323Sed SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2388193323Sed 2389193323Sed ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 2390193323Sed 2391193323Sed QualType getQueriedType() const { return QueriedType->getType(); } 2392193323Sed 2393193323Sed TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 2394193323Sed 2395193323Sed uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 2396193323Sed 2397193323Sed Expr *getDimensionExpression() const { return Dimension; } 2398193323Sed 2399193323Sed static bool classof(const Stmt *T) { 2400193323Sed return T->getStmtClass() == ArrayTypeTraitExprClass; 2401193323Sed } 2402193323Sed 2403193323Sed // Iterators 2404193323Sed child_range children() { return child_range(); } 2405193323Sed 2406193323Sed friend class ASTStmtReader; 2407193323Sed}; 2408193323Sed 2409193323Sed/// \brief An expression trait intrinsic. 2410193323Sed/// 2411193323Sed/// Example: 2412193323Sed/// \code 2413193323Sed/// __is_lvalue_expr(std::cout) == true 2414193323Sed/// __is_lvalue_expr(1) == false 2415/// \endcode 2416class ExpressionTraitExpr : public Expr { 2417 /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned. 2418 unsigned ET : 31; 2419 /// \brief The value of the type trait. Unspecified if dependent. 2420 bool Value : 1; 2421 2422 /// \brief The location of the type trait keyword. 2423 SourceLocation Loc; 2424 2425 /// \brief The location of the closing paren. 2426 SourceLocation RParen; 2427 2428 /// \brief The expression being queried. 2429 Expr* QueriedExpression; 2430public: 2431 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2432 Expr *queried, bool value, 2433 SourceLocation rparen, QualType resultType) 2434 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2435 false, // Not type-dependent 2436 // Value-dependent if the argument is type-dependent. 2437 queried->isTypeDependent(), 2438 queried->isInstantiationDependent(), 2439 queried->containsUnexpandedParameterPack()), 2440 ET(et), Value(value), Loc(loc), RParen(rparen), 2441 QueriedExpression(queried) { } 2442 2443 explicit ExpressionTraitExpr(EmptyShell Empty) 2444 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2445 QueriedExpression() { } 2446 2447 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2448 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2449 2450 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2451 2452 Expr *getQueriedExpression() const { return QueriedExpression; } 2453 2454 bool getValue() const { return Value; } 2455 2456 static bool classof(const Stmt *T) { 2457 return T->getStmtClass() == ExpressionTraitExprClass; 2458 } 2459 2460 // Iterators 2461 child_range children() { return child_range(); } 2462 2463 friend class ASTStmtReader; 2464}; 2465 2466 2467/// \brief A reference to an overloaded function set, either an 2468/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr. 2469class OverloadExpr : public Expr { 2470 /// \brief The common name of these declarations. 2471 DeclarationNameInfo NameInfo; 2472 2473 /// \brief The nested-name-specifier that qualifies the name, if any. 2474 NestedNameSpecifierLoc QualifierLoc; 2475 2476 /// The results. These are undesugared, which is to say, they may 2477 /// include UsingShadowDecls. Access is relative to the naming 2478 /// class. 2479 // FIXME: Allocate this data after the OverloadExpr subclass. 2480 DeclAccessPair *Results; 2481 unsigned NumResults; 2482 2483protected: 2484 /// \brief Whether the name includes info for explicit template 2485 /// keyword and arguments. 2486 bool HasTemplateKWAndArgsInfo; 2487 2488 /// \brief Return the optional template keyword and arguments info. 2489 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2490 2491 /// \brief Return the optional template keyword and arguments info. 2492 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2493 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2494 } 2495 2496 OverloadExpr(StmtClass K, const ASTContext &C, 2497 NestedNameSpecifierLoc QualifierLoc, 2498 SourceLocation TemplateKWLoc, 2499 const DeclarationNameInfo &NameInfo, 2500 const TemplateArgumentListInfo *TemplateArgs, 2501 UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2502 bool KnownDependent, 2503 bool KnownInstantiationDependent, 2504 bool KnownContainsUnexpandedParameterPack); 2505 2506 OverloadExpr(StmtClass K, EmptyShell Empty) 2507 : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0), 2508 HasTemplateKWAndArgsInfo(false) { } 2509 2510 void initializeResults(const ASTContext &C, 2511 UnresolvedSetIterator Begin, 2512 UnresolvedSetIterator End); 2513 2514public: 2515 struct FindResult { 2516 OverloadExpr *Expression; 2517 bool IsAddressOfOperand; 2518 bool HasFormOfMemberPointer; 2519 }; 2520 2521 /// \brief Finds the overloaded expression in the given expression \p E of 2522 /// OverloadTy. 2523 /// 2524 /// \return the expression (which must be there) and true if it has 2525 /// the particular form of a member pointer expression 2526 static FindResult find(Expr *E) { 2527 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 2528 2529 FindResult Result; 2530 2531 E = E->IgnoreParens(); 2532 if (isa<UnaryOperator>(E)) { 2533 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 2534 E = cast<UnaryOperator>(E)->getSubExpr(); 2535 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 2536 2537 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 2538 Result.IsAddressOfOperand = true; 2539 Result.Expression = Ovl; 2540 } else { 2541 Result.HasFormOfMemberPointer = false; 2542 Result.IsAddressOfOperand = false; 2543 Result.Expression = cast<OverloadExpr>(E); 2544 } 2545 2546 return Result; 2547 } 2548 2549 /// \brief Gets the naming class of this lookup, if any. 2550 CXXRecordDecl *getNamingClass() const; 2551 2552 typedef UnresolvedSetImpl::iterator decls_iterator; 2553 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2554 decls_iterator decls_end() const { 2555 return UnresolvedSetIterator(Results + NumResults); 2556 } 2557 2558 /// \brief Gets the number of declarations in the unresolved set. 2559 unsigned getNumDecls() const { return NumResults; } 2560 2561 /// \brief Gets the full name info. 2562 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2563 2564 /// \brief Gets the name looked up. 2565 DeclarationName getName() const { return NameInfo.getName(); } 2566 2567 /// \brief Gets the location of the name. 2568 SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 2569 2570 /// \brief Fetches the nested-name qualifier, if one was given. 2571 NestedNameSpecifier *getQualifier() const { 2572 return QualifierLoc.getNestedNameSpecifier(); 2573 } 2574 2575 /// \brief Fetches the nested-name qualifier with source-location 2576 /// information, if one was given. 2577 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2578 2579 /// \brief Retrieve the location of the template keyword preceding 2580 /// this name, if any. 2581 SourceLocation getTemplateKeywordLoc() const { 2582 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2583 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2584 } 2585 2586 /// \brief Retrieve the location of the left angle bracket starting the 2587 /// explicit template argument list following the name, if any. 2588 SourceLocation getLAngleLoc() const { 2589 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2590 return getTemplateKWAndArgsInfo()->LAngleLoc; 2591 } 2592 2593 /// \brief Retrieve the location of the right angle bracket ending the 2594 /// explicit template argument list following the name, if any. 2595 SourceLocation getRAngleLoc() const { 2596 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2597 return getTemplateKWAndArgsInfo()->RAngleLoc; 2598 } 2599 2600 /// \brief Determines whether the name was preceded by the template keyword. 2601 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2602 2603 /// \brief Determines whether this expression had explicit template arguments. 2604 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2605 2606 // Note that, inconsistently with the explicit-template-argument AST 2607 // nodes, users are *forbidden* from calling these methods on objects 2608 // without explicit template arguments. 2609 2610 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2611 assert(hasExplicitTemplateArgs()); 2612 return *getTemplateKWAndArgsInfo(); 2613 } 2614 2615 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2616 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 2617 } 2618 2619 TemplateArgumentLoc const *getTemplateArgs() const { 2620 return getExplicitTemplateArgs().getTemplateArgs(); 2621 } 2622 2623 unsigned getNumTemplateArgs() const { 2624 return getExplicitTemplateArgs().NumTemplateArgs; 2625 } 2626 2627 /// \brief Copies the template arguments into the given structure. 2628 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2629 getExplicitTemplateArgs().copyInto(List); 2630 } 2631 2632 /// \brief Retrieves the optional explicit template arguments. 2633 /// 2634 /// This points to the same data as getExplicitTemplateArgs(), but 2635 /// returns null if there are no explicit template arguments. 2636 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2637 if (!hasExplicitTemplateArgs()) return 0; 2638 return &getExplicitTemplateArgs(); 2639 } 2640 2641 static bool classof(const Stmt *T) { 2642 return T->getStmtClass() == UnresolvedLookupExprClass || 2643 T->getStmtClass() == UnresolvedMemberExprClass; 2644 } 2645 2646 friend class ASTStmtReader; 2647 friend class ASTStmtWriter; 2648}; 2649 2650/// \brief A reference to a name which we were able to look up during 2651/// parsing but could not resolve to a specific declaration. 2652/// 2653/// This arises in several ways: 2654/// * we might be waiting for argument-dependent lookup; 2655/// * the name might resolve to an overloaded function; 2656/// and eventually: 2657/// * the lookup might have included a function template. 2658/// 2659/// These never include UnresolvedUsingValueDecls, which are always class 2660/// members and therefore appear only in UnresolvedMemberLookupExprs. 2661class UnresolvedLookupExpr : public OverloadExpr { 2662 /// True if these lookup results should be extended by 2663 /// argument-dependent lookup if this is the operand of a function 2664 /// call. 2665 bool RequiresADL; 2666 2667 /// True if these lookup results are overloaded. This is pretty 2668 /// trivially rederivable if we urgently need to kill this field. 2669 bool Overloaded; 2670 2671 /// The naming class (C++ [class.access.base]p5) of the lookup, if 2672 /// any. This can generally be recalculated from the context chain, 2673 /// but that can be fairly expensive for unqualified lookups. If we 2674 /// want to improve memory use here, this could go in a union 2675 /// against the qualified-lookup bits. 2676 CXXRecordDecl *NamingClass; 2677 2678 UnresolvedLookupExpr(const ASTContext &C, 2679 CXXRecordDecl *NamingClass, 2680 NestedNameSpecifierLoc QualifierLoc, 2681 SourceLocation TemplateKWLoc, 2682 const DeclarationNameInfo &NameInfo, 2683 bool RequiresADL, bool Overloaded, 2684 const TemplateArgumentListInfo *TemplateArgs, 2685 UnresolvedSetIterator Begin, UnresolvedSetIterator End) 2686 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2687 NameInfo, TemplateArgs, Begin, End, false, false, false), 2688 RequiresADL(RequiresADL), 2689 Overloaded(Overloaded), NamingClass(NamingClass) 2690 {} 2691 2692 UnresolvedLookupExpr(EmptyShell Empty) 2693 : OverloadExpr(UnresolvedLookupExprClass, Empty), 2694 RequiresADL(false), Overloaded(false), NamingClass(0) 2695 {} 2696 2697 friend class ASTStmtReader; 2698 2699public: 2700 static UnresolvedLookupExpr *Create(const ASTContext &C, 2701 CXXRecordDecl *NamingClass, 2702 NestedNameSpecifierLoc QualifierLoc, 2703 const DeclarationNameInfo &NameInfo, 2704 bool ADL, bool Overloaded, 2705 UnresolvedSetIterator Begin, 2706 UnresolvedSetIterator End) { 2707 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2708 SourceLocation(), NameInfo, 2709 ADL, Overloaded, 0, Begin, End); 2710 } 2711 2712 static UnresolvedLookupExpr *Create(const ASTContext &C, 2713 CXXRecordDecl *NamingClass, 2714 NestedNameSpecifierLoc QualifierLoc, 2715 SourceLocation TemplateKWLoc, 2716 const DeclarationNameInfo &NameInfo, 2717 bool ADL, 2718 const TemplateArgumentListInfo *Args, 2719 UnresolvedSetIterator Begin, 2720 UnresolvedSetIterator End); 2721 2722 static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C, 2723 bool HasTemplateKWAndArgsInfo, 2724 unsigned NumTemplateArgs); 2725 2726 /// True if this declaration should be extended by 2727 /// argument-dependent lookup. 2728 bool requiresADL() const { return RequiresADL; } 2729 2730 /// True if this lookup is overloaded. 2731 bool isOverloaded() const { return Overloaded; } 2732 2733 /// Gets the 'naming class' (in the sense of C++0x 2734 /// [class.access.base]p5) of the lookup. This is the scope 2735 /// that was looked in to find these results. 2736 CXXRecordDecl *getNamingClass() const { return NamingClass; } 2737 2738 SourceLocation getLocStart() const LLVM_READONLY { 2739 if (NestedNameSpecifierLoc l = getQualifierLoc()) 2740 return l.getBeginLoc(); 2741 return getNameInfo().getLocStart(); 2742 } 2743 SourceLocation getLocEnd() const LLVM_READONLY { 2744 if (hasExplicitTemplateArgs()) 2745 return getRAngleLoc(); 2746 return getNameInfo().getLocEnd(); 2747 } 2748 2749 child_range children() { return child_range(); } 2750 2751 static bool classof(const Stmt *T) { 2752 return T->getStmtClass() == UnresolvedLookupExprClass; 2753 } 2754}; 2755 2756/// \brief A qualified reference to a name whose declaration cannot 2757/// yet be resolved. 2758/// 2759/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2760/// it expresses a reference to a declaration such as 2761/// X<T>::value. The difference, however, is that an 2762/// DependentScopeDeclRefExpr node is used only within C++ templates when 2763/// the qualification (e.g., X<T>::) refers to a dependent type. In 2764/// this case, X<T>::value cannot resolve to a declaration because the 2765/// declaration will differ from one instantiation of X<T> to the 2766/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2767/// qualifier (X<T>::) and the name of the entity being referenced 2768/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2769/// declaration can be found. 2770class DependentScopeDeclRefExpr : public Expr { 2771 /// \brief The nested-name-specifier that qualifies this unresolved 2772 /// declaration name. 2773 NestedNameSpecifierLoc QualifierLoc; 2774 2775 /// \brief The name of the entity we will be referencing. 2776 DeclarationNameInfo NameInfo; 2777 2778 /// \brief Whether the name includes info for explicit template 2779 /// keyword and arguments. 2780 bool HasTemplateKWAndArgsInfo; 2781 2782 /// \brief Return the optional template keyword and arguments info. 2783 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2784 if (!HasTemplateKWAndArgsInfo) return 0; 2785 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2786 } 2787 /// \brief Return the optional template keyword and arguments info. 2788 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2789 return const_cast<DependentScopeDeclRefExpr*>(this) 2790 ->getTemplateKWAndArgsInfo(); 2791 } 2792 2793 DependentScopeDeclRefExpr(QualType T, 2794 NestedNameSpecifierLoc QualifierLoc, 2795 SourceLocation TemplateKWLoc, 2796 const DeclarationNameInfo &NameInfo, 2797 const TemplateArgumentListInfo *Args); 2798 2799public: 2800 static DependentScopeDeclRefExpr *Create(const ASTContext &C, 2801 NestedNameSpecifierLoc QualifierLoc, 2802 SourceLocation TemplateKWLoc, 2803 const DeclarationNameInfo &NameInfo, 2804 const TemplateArgumentListInfo *TemplateArgs); 2805 2806 static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C, 2807 bool HasTemplateKWAndArgsInfo, 2808 unsigned NumTemplateArgs); 2809 2810 /// \brief Retrieve the name that this expression refers to. 2811 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2812 2813 /// \brief Retrieve the name that this expression refers to. 2814 DeclarationName getDeclName() const { return NameInfo.getName(); } 2815 2816 /// \brief Retrieve the location of the name within the expression. 2817 /// 2818 /// For example, in "X<T>::value" this is the location of "value". 2819 SourceLocation getLocation() const { return NameInfo.getLoc(); } 2820 2821 /// \brief Retrieve the nested-name-specifier that qualifies the 2822 /// name, with source location information. 2823 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2824 2825 /// \brief Retrieve the nested-name-specifier that qualifies this 2826 /// declaration. 2827 NestedNameSpecifier *getQualifier() const { 2828 return QualifierLoc.getNestedNameSpecifier(); 2829 } 2830 2831 /// \brief Retrieve the location of the template keyword preceding 2832 /// this name, if any. 2833 SourceLocation getTemplateKeywordLoc() const { 2834 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2835 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2836 } 2837 2838 /// \brief Retrieve the location of the left angle bracket starting the 2839 /// explicit template argument list following the name, if any. 2840 SourceLocation getLAngleLoc() const { 2841 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2842 return getTemplateKWAndArgsInfo()->LAngleLoc; 2843 } 2844 2845 /// \brief Retrieve the location of the right angle bracket ending the 2846 /// explicit template argument list following the name, if any. 2847 SourceLocation getRAngleLoc() const { 2848 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2849 return getTemplateKWAndArgsInfo()->RAngleLoc; 2850 } 2851 2852 /// Determines whether the name was preceded by the template keyword. 2853 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2854 2855 /// Determines whether this lookup had explicit template arguments. 2856 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2857 2858 // Note that, inconsistently with the explicit-template-argument AST 2859 // nodes, users are *forbidden* from calling these methods on objects 2860 // without explicit template arguments. 2861 2862 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2863 assert(hasExplicitTemplateArgs()); 2864 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 2865 } 2866 2867 /// Gets a reference to the explicit template argument list. 2868 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2869 assert(hasExplicitTemplateArgs()); 2870 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2871 } 2872 2873 /// \brief Retrieves the optional explicit template arguments. 2874 /// 2875 /// This points to the same data as getExplicitTemplateArgs(), but 2876 /// returns null if there are no explicit template arguments. 2877 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2878 if (!hasExplicitTemplateArgs()) return 0; 2879 return &getExplicitTemplateArgs(); 2880 } 2881 2882 /// \brief Copies the template arguments (if present) into the given 2883 /// structure. 2884 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2885 getExplicitTemplateArgs().copyInto(List); 2886 } 2887 2888 TemplateArgumentLoc const *getTemplateArgs() const { 2889 return getExplicitTemplateArgs().getTemplateArgs(); 2890 } 2891 2892 unsigned getNumTemplateArgs() const { 2893 return getExplicitTemplateArgs().NumTemplateArgs; 2894 } 2895 2896 /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr, 2897 /// and differs from getLocation().getStart(). 2898 SourceLocation getLocStart() const LLVM_READONLY { 2899 return QualifierLoc.getBeginLoc(); 2900 } 2901 SourceLocation getLocEnd() const LLVM_READONLY { 2902 if (hasExplicitTemplateArgs()) 2903 return getRAngleLoc(); 2904 return getLocation(); 2905 } 2906 2907 static bool classof(const Stmt *T) { 2908 return T->getStmtClass() == DependentScopeDeclRefExprClass; 2909 } 2910 2911 child_range children() { return child_range(); } 2912 2913 friend class ASTStmtReader; 2914 friend class ASTStmtWriter; 2915}; 2916 2917/// Represents an expression -- generally a full-expression -- that 2918/// introduces cleanups to be run at the end of the sub-expression's 2919/// evaluation. The most common source of expression-introduced 2920/// cleanups is temporary objects in C++, but several other kinds of 2921/// expressions can create cleanups, including basically every 2922/// call in ARC that returns an Objective-C pointer. 2923/// 2924/// This expression also tracks whether the sub-expression contains a 2925/// potentially-evaluated block literal. The lifetime of a block 2926/// literal is the extent of the enclosing scope. 2927class ExprWithCleanups : public Expr { 2928public: 2929 /// The type of objects that are kept in the cleanup. 2930 /// It's useful to remember the set of blocks; we could also 2931 /// remember the set of temporaries, but there's currently 2932 /// no need. 2933 typedef BlockDecl *CleanupObject; 2934 2935private: 2936 Stmt *SubExpr; 2937 2938 ExprWithCleanups(EmptyShell, unsigned NumObjects); 2939 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 2940 2941 CleanupObject *getObjectsBuffer() { 2942 return reinterpret_cast<CleanupObject*>(this + 1); 2943 } 2944 const CleanupObject *getObjectsBuffer() const { 2945 return reinterpret_cast<const CleanupObject*>(this + 1); 2946 } 2947 friend class ASTStmtReader; 2948 2949public: 2950 static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty, 2951 unsigned numObjects); 2952 2953 static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr, 2954 ArrayRef<CleanupObject> objects); 2955 2956 ArrayRef<CleanupObject> getObjects() const { 2957 return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2958 } 2959 2960 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 2961 2962 CleanupObject getObject(unsigned i) const { 2963 assert(i < getNumObjects() && "Index out of range"); 2964 return getObjects()[i]; 2965 } 2966 2967 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2968 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 2969 2970 /// As with any mutator of the AST, be very careful 2971 /// when modifying an existing AST to preserve its invariants. 2972 void setSubExpr(Expr *E) { SubExpr = E; } 2973 2974 SourceLocation getLocStart() const LLVM_READONLY { 2975 return SubExpr->getLocStart(); 2976 } 2977 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 2978 2979 // Implement isa/cast/dyncast/etc. 2980 static bool classof(const Stmt *T) { 2981 return T->getStmtClass() == ExprWithCleanupsClass; 2982 } 2983 2984 // Iterators 2985 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 2986}; 2987 2988/// \brief Describes an explicit type conversion that uses functional 2989/// notion but could not be resolved because one or more arguments are 2990/// type-dependent. 2991/// 2992/// The explicit type conversions expressed by 2993/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>, 2994/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and 2995/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is 2996/// type-dependent. For example, this would occur in a template such 2997/// as: 2998/// 2999/// \code 3000/// template<typename T, typename A1> 3001/// inline T make_a(const A1& a1) { 3002/// return T(a1); 3003/// } 3004/// \endcode 3005/// 3006/// When the returned expression is instantiated, it may resolve to a 3007/// constructor call, conversion function call, or some kind of type 3008/// conversion. 3009class CXXUnresolvedConstructExpr : public Expr { 3010 /// \brief The type being constructed. 3011 TypeSourceInfo *Type; 3012 3013 /// \brief The location of the left parentheses ('('). 3014 SourceLocation LParenLoc; 3015 3016 /// \brief The location of the right parentheses (')'). 3017 SourceLocation RParenLoc; 3018 3019 /// \brief The number of arguments used to construct the type. 3020 unsigned NumArgs; 3021 3022 CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 3023 SourceLocation LParenLoc, 3024 ArrayRef<Expr*> Args, 3025 SourceLocation RParenLoc); 3026 3027 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 3028 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 3029 3030 friend class ASTStmtReader; 3031 3032public: 3033 static CXXUnresolvedConstructExpr *Create(const ASTContext &C, 3034 TypeSourceInfo *Type, 3035 SourceLocation LParenLoc, 3036 ArrayRef<Expr*> Args, 3037 SourceLocation RParenLoc); 3038 3039 static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C, 3040 unsigned NumArgs); 3041 3042 /// \brief Retrieve the type that is being constructed, as specified 3043 /// in the source code. 3044 QualType getTypeAsWritten() const { return Type->getType(); } 3045 3046 /// \brief Retrieve the type source information for the type being 3047 /// constructed. 3048 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 3049 3050 /// \brief Retrieve the location of the left parentheses ('(') that 3051 /// precedes the argument list. 3052 SourceLocation getLParenLoc() const { return LParenLoc; } 3053 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 3054 3055 /// \brief Retrieve the location of the right parentheses (')') that 3056 /// follows the argument list. 3057 SourceLocation getRParenLoc() const { return RParenLoc; } 3058 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3059 3060 /// \brief Retrieve the number of arguments. 3061 unsigned arg_size() const { return NumArgs; } 3062 3063 typedef Expr** arg_iterator; 3064 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 3065 arg_iterator arg_end() { return arg_begin() + NumArgs; } 3066 3067 typedef const Expr* const * const_arg_iterator; 3068 const_arg_iterator arg_begin() const { 3069 return reinterpret_cast<const Expr* const *>(this + 1); 3070 } 3071 const_arg_iterator arg_end() const { 3072 return arg_begin() + NumArgs; 3073 } 3074 3075 Expr *getArg(unsigned I) { 3076 assert(I < NumArgs && "Argument index out-of-range"); 3077 return *(arg_begin() + I); 3078 } 3079 3080 const Expr *getArg(unsigned I) const { 3081 assert(I < NumArgs && "Argument index out-of-range"); 3082 return *(arg_begin() + I); 3083 } 3084 3085 void setArg(unsigned I, Expr *E) { 3086 assert(I < NumArgs && "Argument index out-of-range"); 3087 *(arg_begin() + I) = E; 3088 } 3089 3090 SourceLocation getLocStart() const LLVM_READONLY; 3091 SourceLocation getLocEnd() const LLVM_READONLY { 3092 assert(RParenLoc.isValid() || NumArgs == 1); 3093 return RParenLoc.isValid() ? RParenLoc : getArg(0)->getLocEnd(); 3094 } 3095 3096 static bool classof(const Stmt *T) { 3097 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 3098 } 3099 3100 // Iterators 3101 child_range children() { 3102 Stmt **begin = reinterpret_cast<Stmt**>(this+1); 3103 return child_range(begin, begin + NumArgs); 3104 } 3105}; 3106 3107/// \brief Represents a C++ member access expression where the actual 3108/// member referenced could not be resolved because the base 3109/// expression or the member name was dependent. 3110/// 3111/// Like UnresolvedMemberExprs, these can be either implicit or 3112/// explicit accesses. It is only possible to get one of these with 3113/// an implicit access if a qualifier is provided. 3114class CXXDependentScopeMemberExpr : public Expr { 3115 /// \brief The expression for the base pointer or class reference, 3116 /// e.g., the \c x in x.f. Can be null in implicit accesses. 3117 Stmt *Base; 3118 3119 /// \brief The type of the base expression. Never null, even for 3120 /// implicit accesses. 3121 QualType BaseType; 3122 3123 /// \brief Whether this member expression used the '->' operator or 3124 /// the '.' operator. 3125 bool IsArrow : 1; 3126 3127 /// \brief Whether this member expression has info for explicit template 3128 /// keyword and arguments. 3129 bool HasTemplateKWAndArgsInfo : 1; 3130 3131 /// \brief The location of the '->' or '.' operator. 3132 SourceLocation OperatorLoc; 3133 3134 /// \brief The nested-name-specifier that precedes the member name, if any. 3135 NestedNameSpecifierLoc QualifierLoc; 3136 3137 /// \brief In a qualified member access expression such as t->Base::f, this 3138 /// member stores the resolves of name lookup in the context of the member 3139 /// access expression, to be used at instantiation time. 3140 /// 3141 /// FIXME: This member, along with the QualifierLoc, could 3142 /// be stuck into a structure that is optionally allocated at the end of 3143 /// the CXXDependentScopeMemberExpr, to save space in the common case. 3144 NamedDecl *FirstQualifierFoundInScope; 3145 3146 /// \brief The member to which this member expression refers, which 3147 /// can be name, overloaded operator, or destructor. 3148 /// 3149 /// FIXME: could also be a template-id 3150 DeclarationNameInfo MemberNameInfo; 3151 3152 /// \brief Return the optional template keyword and arguments info. 3153 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 3154 if (!HasTemplateKWAndArgsInfo) return 0; 3155 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 3156 } 3157 /// \brief Return the optional template keyword and arguments info. 3158 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 3159 return const_cast<CXXDependentScopeMemberExpr*>(this) 3160 ->getTemplateKWAndArgsInfo(); 3161 } 3162 3163 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base, 3164 QualType BaseType, bool IsArrow, 3165 SourceLocation OperatorLoc, 3166 NestedNameSpecifierLoc QualifierLoc, 3167 SourceLocation TemplateKWLoc, 3168 NamedDecl *FirstQualifierFoundInScope, 3169 DeclarationNameInfo MemberNameInfo, 3170 const TemplateArgumentListInfo *TemplateArgs); 3171 3172public: 3173 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base, 3174 QualType BaseType, bool IsArrow, 3175 SourceLocation OperatorLoc, 3176 NestedNameSpecifierLoc QualifierLoc, 3177 NamedDecl *FirstQualifierFoundInScope, 3178 DeclarationNameInfo MemberNameInfo); 3179 3180 static CXXDependentScopeMemberExpr * 3181 Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow, 3182 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, 3183 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, 3184 DeclarationNameInfo MemberNameInfo, 3185 const TemplateArgumentListInfo *TemplateArgs); 3186 3187 static CXXDependentScopeMemberExpr * 3188 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo, 3189 unsigned NumTemplateArgs); 3190 3191 /// \brief True if this is an implicit access, i.e. one in which the 3192 /// member being accessed was not written in the source. The source 3193 /// location of the operator is invalid in this case. 3194 bool isImplicitAccess() const; 3195 3196 /// \brief Retrieve the base object of this member expressions, 3197 /// e.g., the \c x in \c x.m. 3198 Expr *getBase() const { 3199 assert(!isImplicitAccess()); 3200 return cast<Expr>(Base); 3201 } 3202 3203 QualType getBaseType() const { return BaseType; } 3204 3205 /// \brief Determine whether this member expression used the '->' 3206 /// operator; otherwise, it used the '.' operator. 3207 bool isArrow() const { return IsArrow; } 3208 3209 /// \brief Retrieve the location of the '->' or '.' operator. 3210 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3211 3212 /// \brief Retrieve the nested-name-specifier that qualifies the member 3213 /// name. 3214 NestedNameSpecifier *getQualifier() const { 3215 return QualifierLoc.getNestedNameSpecifier(); 3216 } 3217 3218 /// \brief Retrieve the nested-name-specifier that qualifies the member 3219 /// name, with source location information. 3220 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 3221 3222 3223 /// \brief Retrieve the first part of the nested-name-specifier that was 3224 /// found in the scope of the member access expression when the member access 3225 /// was initially parsed. 3226 /// 3227 /// This function only returns a useful result when member access expression 3228 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 3229 /// returned by this function describes what was found by unqualified name 3230 /// lookup for the identifier "Base" within the scope of the member access 3231 /// expression itself. At template instantiation time, this information is 3232 /// combined with the results of name lookup into the type of the object 3233 /// expression itself (the class type of x). 3234 NamedDecl *getFirstQualifierFoundInScope() const { 3235 return FirstQualifierFoundInScope; 3236 } 3237 3238 /// \brief Retrieve the name of the member that this expression 3239 /// refers to. 3240 const DeclarationNameInfo &getMemberNameInfo() const { 3241 return MemberNameInfo; 3242 } 3243 3244 /// \brief Retrieve the name of the member that this expression 3245 /// refers to. 3246 DeclarationName getMember() const { return MemberNameInfo.getName(); } 3247 3248 // \brief Retrieve the location of the name of the member that this 3249 // expression refers to. 3250 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 3251 3252 /// \brief Retrieve the location of the template keyword preceding the 3253 /// member name, if any. 3254 SourceLocation getTemplateKeywordLoc() const { 3255 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3256 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 3257 } 3258 3259 /// \brief Retrieve the location of the left angle bracket starting the 3260 /// explicit template argument list following the member name, if any. 3261 SourceLocation getLAngleLoc() const { 3262 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3263 return getTemplateKWAndArgsInfo()->LAngleLoc; 3264 } 3265 3266 /// \brief Retrieve the location of the right angle bracket ending the 3267 /// explicit template argument list following the member name, if any. 3268 SourceLocation getRAngleLoc() const { 3269 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3270 return getTemplateKWAndArgsInfo()->RAngleLoc; 3271 } 3272 3273 /// Determines whether the member name was preceded by the template keyword. 3274 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 3275 3276 /// \brief Determines whether this member expression actually had a C++ 3277 /// template argument list explicitly specified, e.g., x.f<int>. 3278 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 3279 3280 /// \brief Retrieve the explicit template argument list that followed the 3281 /// member template name, if any. 3282 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 3283 assert(hasExplicitTemplateArgs()); 3284 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 3285 } 3286 3287 /// \brief Retrieve the explicit template argument list that followed the 3288 /// member template name, if any. 3289 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 3290 return const_cast<CXXDependentScopeMemberExpr *>(this) 3291 ->getExplicitTemplateArgs(); 3292 } 3293 3294 /// \brief Retrieves the optional explicit template arguments. 3295 /// 3296 /// This points to the same data as getExplicitTemplateArgs(), but 3297 /// returns null if there are no explicit template arguments. 3298 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 3299 if (!hasExplicitTemplateArgs()) return 0; 3300 return &getExplicitTemplateArgs(); 3301 } 3302 3303 /// \brief Copies the template arguments (if present) into the given 3304 /// structure. 3305 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 3306 getExplicitTemplateArgs().copyInto(List); 3307 } 3308 3309 /// \brief Initializes the template arguments using the given structure. 3310 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 3311 getExplicitTemplateArgs().initializeFrom(List); 3312 } 3313 3314 /// \brief Retrieve the template arguments provided as part of this 3315 /// template-id. 3316 const TemplateArgumentLoc *getTemplateArgs() const { 3317 return getExplicitTemplateArgs().getTemplateArgs(); 3318 } 3319 3320 /// \brief Retrieve the number of template arguments provided as part of this 3321 /// template-id. 3322 unsigned getNumTemplateArgs() const { 3323 return getExplicitTemplateArgs().NumTemplateArgs; 3324 } 3325 3326 SourceLocation getLocStart() const LLVM_READONLY { 3327 if (!isImplicitAccess()) 3328 return Base->getLocStart(); 3329 if (getQualifier()) 3330 return getQualifierLoc().getBeginLoc(); 3331 return MemberNameInfo.getBeginLoc(); 3332 3333 } 3334 SourceLocation getLocEnd() const LLVM_READONLY { 3335 if (hasExplicitTemplateArgs()) 3336 return getRAngleLoc(); 3337 return MemberNameInfo.getEndLoc(); 3338 } 3339 3340 static bool classof(const Stmt *T) { 3341 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 3342 } 3343 3344 // Iterators 3345 child_range children() { 3346 if (isImplicitAccess()) return child_range(); 3347 return child_range(&Base, &Base + 1); 3348 } 3349 3350 friend class ASTStmtReader; 3351 friend class ASTStmtWriter; 3352}; 3353 3354/// \brief Represents a C++ member access expression for which lookup 3355/// produced a set of overloaded functions. 3356/// 3357/// The member access may be explicit or implicit: 3358/// \code 3359/// struct A { 3360/// int a, b; 3361/// int explicitAccess() { return this->a + this->A::b; } 3362/// int implicitAccess() { return a + A::b; } 3363/// }; 3364/// \endcode 3365/// 3366/// In the final AST, an explicit access always becomes a MemberExpr. 3367/// An implicit access may become either a MemberExpr or a 3368/// DeclRefExpr, depending on whether the member is static. 3369class UnresolvedMemberExpr : public OverloadExpr { 3370 /// \brief Whether this member expression used the '->' operator or 3371 /// the '.' operator. 3372 bool IsArrow : 1; 3373 3374 /// \brief Whether the lookup results contain an unresolved using 3375 /// declaration. 3376 bool HasUnresolvedUsing : 1; 3377 3378 /// \brief The expression for the base pointer or class reference, 3379 /// e.g., the \c x in x.f. 3380 /// 3381 /// This can be null if this is an 'unbased' member expression. 3382 Stmt *Base; 3383 3384 /// \brief The type of the base expression; never null. 3385 QualType BaseType; 3386 3387 /// \brief The location of the '->' or '.' operator. 3388 SourceLocation OperatorLoc; 3389 3390 UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing, 3391 Expr *Base, QualType BaseType, bool IsArrow, 3392 SourceLocation OperatorLoc, 3393 NestedNameSpecifierLoc QualifierLoc, 3394 SourceLocation TemplateKWLoc, 3395 const DeclarationNameInfo &MemberNameInfo, 3396 const TemplateArgumentListInfo *TemplateArgs, 3397 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3398 3399 UnresolvedMemberExpr(EmptyShell Empty) 3400 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 3401 HasUnresolvedUsing(false), Base(0) { } 3402 3403 friend class ASTStmtReader; 3404 3405public: 3406 static UnresolvedMemberExpr * 3407 Create(const ASTContext &C, bool HasUnresolvedUsing, 3408 Expr *Base, QualType BaseType, bool IsArrow, 3409 SourceLocation OperatorLoc, 3410 NestedNameSpecifierLoc QualifierLoc, 3411 SourceLocation TemplateKWLoc, 3412 const DeclarationNameInfo &MemberNameInfo, 3413 const TemplateArgumentListInfo *TemplateArgs, 3414 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3415 3416 static UnresolvedMemberExpr * 3417 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo, 3418 unsigned NumTemplateArgs); 3419 3420 /// \brief True if this is an implicit access, i.e., one in which the 3421 /// member being accessed was not written in the source. 3422 /// 3423 /// The source location of the operator is invalid in this case. 3424 bool isImplicitAccess() const; 3425 3426 /// \brief Retrieve the base object of this member expressions, 3427 /// e.g., the \c x in \c x.m. 3428 Expr *getBase() { 3429 assert(!isImplicitAccess()); 3430 return cast<Expr>(Base); 3431 } 3432 const Expr *getBase() const { 3433 assert(!isImplicitAccess()); 3434 return cast<Expr>(Base); 3435 } 3436 3437 QualType getBaseType() const { return BaseType; } 3438 3439 /// \brief Determine whether the lookup results contain an unresolved using 3440 /// declaration. 3441 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3442 3443 /// \brief Determine whether this member expression used the '->' 3444 /// operator; otherwise, it used the '.' operator. 3445 bool isArrow() const { return IsArrow; } 3446 3447 /// \brief Retrieve the location of the '->' or '.' operator. 3448 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3449 3450 /// \brief Retrieve the naming class of this lookup. 3451 CXXRecordDecl *getNamingClass() const; 3452 3453 /// \brief Retrieve the full name info for the member that this expression 3454 /// refers to. 3455 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 3456 3457 /// \brief Retrieve the name of the member that this expression 3458 /// refers to. 3459 DeclarationName getMemberName() const { return getName(); } 3460 3461 // \brief Retrieve the location of the name of the member that this 3462 // expression refers to. 3463 SourceLocation getMemberLoc() const { return getNameLoc(); } 3464 3465 // \brief Return the preferred location (the member name) for the arrow when 3466 // diagnosing a problem with this expression. 3467 SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); } 3468 3469 SourceLocation getLocStart() const LLVM_READONLY { 3470 if (!isImplicitAccess()) 3471 return Base->getLocStart(); 3472 if (NestedNameSpecifierLoc l = getQualifierLoc()) 3473 return l.getBeginLoc(); 3474 return getMemberNameInfo().getLocStart(); 3475 } 3476 SourceLocation getLocEnd() const LLVM_READONLY { 3477 if (hasExplicitTemplateArgs()) 3478 return getRAngleLoc(); 3479 return getMemberNameInfo().getLocEnd(); 3480 } 3481 3482 static bool classof(const Stmt *T) { 3483 return T->getStmtClass() == UnresolvedMemberExprClass; 3484 } 3485 3486 // Iterators 3487 child_range children() { 3488 if (isImplicitAccess()) return child_range(); 3489 return child_range(&Base, &Base + 1); 3490 } 3491}; 3492 3493/// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]). 3494/// 3495/// The noexcept expression tests whether a given expression might throw. Its 3496/// result is a boolean constant. 3497class CXXNoexceptExpr : public Expr { 3498 bool Value : 1; 3499 Stmt *Operand; 3500 SourceRange Range; 3501 3502 friend class ASTStmtReader; 3503 3504public: 3505 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 3506 SourceLocation Keyword, SourceLocation RParen) 3507 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3508 /*TypeDependent*/false, 3509 /*ValueDependent*/Val == CT_Dependent, 3510 Val == CT_Dependent || Operand->isInstantiationDependent(), 3511 Operand->containsUnexpandedParameterPack()), 3512 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 3513 { } 3514 3515 CXXNoexceptExpr(EmptyShell Empty) 3516 : Expr(CXXNoexceptExprClass, Empty) 3517 { } 3518 3519 Expr *getOperand() const { return static_cast<Expr*>(Operand); } 3520 3521 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 3522 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 3523 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 3524 3525 bool getValue() const { return Value; } 3526 3527 static bool classof(const Stmt *T) { 3528 return T->getStmtClass() == CXXNoexceptExprClass; 3529 } 3530 3531 // Iterators 3532 child_range children() { return child_range(&Operand, &Operand + 1); } 3533}; 3534 3535/// \brief Represents a C++11 pack expansion that produces a sequence of 3536/// expressions. 3537/// 3538/// A pack expansion expression contains a pattern (which itself is an 3539/// expression) followed by an ellipsis. For example: 3540/// 3541/// \code 3542/// template<typename F, typename ...Types> 3543/// void forward(F f, Types &&...args) { 3544/// f(static_cast<Types&&>(args)...); 3545/// } 3546/// \endcode 3547/// 3548/// Here, the argument to the function object \c f is a pack expansion whose 3549/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3550/// template is instantiated, the pack expansion will instantiate to zero or 3551/// or more function arguments to the function object \c f. 3552class PackExpansionExpr : public Expr { 3553 SourceLocation EllipsisLoc; 3554 3555 /// \brief The number of expansions that will be produced by this pack 3556 /// expansion expression, if known. 3557 /// 3558 /// When zero, the number of expansions is not known. Otherwise, this value 3559 /// is the number of expansions + 1. 3560 unsigned NumExpansions; 3561 3562 Stmt *Pattern; 3563 3564 friend class ASTStmtReader; 3565 friend class ASTStmtWriter; 3566 3567public: 3568 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 3569 Optional<unsigned> NumExpansions) 3570 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3571 Pattern->getObjectKind(), /*TypeDependent=*/true, 3572 /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3573 /*ContainsUnexpandedParameterPack=*/false), 3574 EllipsisLoc(EllipsisLoc), 3575 NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3576 Pattern(Pattern) { } 3577 3578 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3579 3580 /// \brief Retrieve the pattern of the pack expansion. 3581 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3582 3583 /// \brief Retrieve the pattern of the pack expansion. 3584 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3585 3586 /// \brief Retrieve the location of the ellipsis that describes this pack 3587 /// expansion. 3588 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3589 3590 /// \brief Determine the number of expansions that will be produced when 3591 /// this pack expansion is instantiated, if already known. 3592 Optional<unsigned> getNumExpansions() const { 3593 if (NumExpansions) 3594 return NumExpansions - 1; 3595 3596 return None; 3597 } 3598 3599 SourceLocation getLocStart() const LLVM_READONLY { 3600 return Pattern->getLocStart(); 3601 } 3602 SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; } 3603 3604 static bool classof(const Stmt *T) { 3605 return T->getStmtClass() == PackExpansionExprClass; 3606 } 3607 3608 // Iterators 3609 child_range children() { 3610 return child_range(&Pattern, &Pattern + 1); 3611 } 3612}; 3613 3614inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3615 if (!HasTemplateKWAndArgsInfo) return 0; 3616 if (isa<UnresolvedLookupExpr>(this)) 3617 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3618 (cast<UnresolvedLookupExpr>(this) + 1); 3619 else 3620 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3621 (cast<UnresolvedMemberExpr>(this) + 1); 3622} 3623 3624/// \brief Represents an expression that computes the length of a parameter 3625/// pack. 3626/// 3627/// \code 3628/// template<typename ...Types> 3629/// struct count { 3630/// static const unsigned value = sizeof...(Types); 3631/// }; 3632/// \endcode 3633class SizeOfPackExpr : public Expr { 3634 /// \brief The location of the \c sizeof keyword. 3635 SourceLocation OperatorLoc; 3636 3637 /// \brief The location of the name of the parameter pack. 3638 SourceLocation PackLoc; 3639 3640 /// \brief The location of the closing parenthesis. 3641 SourceLocation RParenLoc; 3642 3643 /// \brief The length of the parameter pack, if known. 3644 /// 3645 /// When this expression is value-dependent, the length of the parameter pack 3646 /// is unknown. When this expression is not value-dependent, the length is 3647 /// known. 3648 unsigned Length; 3649 3650 /// \brief The parameter pack itself. 3651 NamedDecl *Pack; 3652 3653 friend class ASTStmtReader; 3654 friend class ASTStmtWriter; 3655 3656public: 3657 /// \brief Create a value-dependent expression that computes the length of 3658 /// the given parameter pack. 3659 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3660 SourceLocation PackLoc, SourceLocation RParenLoc) 3661 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3662 /*TypeDependent=*/false, /*ValueDependent=*/true, 3663 /*InstantiationDependent=*/true, 3664 /*ContainsUnexpandedParameterPack=*/false), 3665 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3666 Length(0), Pack(Pack) { } 3667 3668 /// \brief Create an expression that computes the length of 3669 /// the given parameter pack, which is already known. 3670 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3671 SourceLocation PackLoc, SourceLocation RParenLoc, 3672 unsigned Length) 3673 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3674 /*TypeDependent=*/false, /*ValueDependent=*/false, 3675 /*InstantiationDependent=*/false, 3676 /*ContainsUnexpandedParameterPack=*/false), 3677 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3678 Length(Length), Pack(Pack) { } 3679 3680 /// \brief Create an empty expression. 3681 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3682 3683 /// \brief Determine the location of the 'sizeof' keyword. 3684 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3685 3686 /// \brief Determine the location of the parameter pack. 3687 SourceLocation getPackLoc() const { return PackLoc; } 3688 3689 /// \brief Determine the location of the right parenthesis. 3690 SourceLocation getRParenLoc() const { return RParenLoc; } 3691 3692 /// \brief Retrieve the parameter pack. 3693 NamedDecl *getPack() const { return Pack; } 3694 3695 /// \brief Retrieve the length of the parameter pack. 3696 /// 3697 /// This routine may only be invoked when the expression is not 3698 /// value-dependent. 3699 unsigned getPackLength() const { 3700 assert(!isValueDependent() && 3701 "Cannot get the length of a value-dependent pack size expression"); 3702 return Length; 3703 } 3704 3705 SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; } 3706 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 3707 3708 static bool classof(const Stmt *T) { 3709 return T->getStmtClass() == SizeOfPackExprClass; 3710 } 3711 3712 // Iterators 3713 child_range children() { return child_range(); } 3714}; 3715 3716/// \brief Represents a reference to a non-type template parameter 3717/// that has been substituted with a template argument. 3718class SubstNonTypeTemplateParmExpr : public Expr { 3719 /// \brief The replaced parameter. 3720 NonTypeTemplateParmDecl *Param; 3721 3722 /// \brief The replacement expression. 3723 Stmt *Replacement; 3724 3725 /// \brief The location of the non-type template parameter reference. 3726 SourceLocation NameLoc; 3727 3728 friend class ASTReader; 3729 friend class ASTStmtReader; 3730 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 3731 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 3732 3733public: 3734 SubstNonTypeTemplateParmExpr(QualType type, 3735 ExprValueKind valueKind, 3736 SourceLocation loc, 3737 NonTypeTemplateParmDecl *param, 3738 Expr *replacement) 3739 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 3740 replacement->isTypeDependent(), replacement->isValueDependent(), 3741 replacement->isInstantiationDependent(), 3742 replacement->containsUnexpandedParameterPack()), 3743 Param(param), Replacement(replacement), NameLoc(loc) {} 3744 3745 SourceLocation getNameLoc() const { return NameLoc; } 3746 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3747 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3748 3749 Expr *getReplacement() const { return cast<Expr>(Replacement); } 3750 3751 NonTypeTemplateParmDecl *getParameter() const { return Param; } 3752 3753 static bool classof(const Stmt *s) { 3754 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 3755 } 3756 3757 // Iterators 3758 child_range children() { return child_range(&Replacement, &Replacement+1); } 3759}; 3760 3761/// \brief Represents a reference to a non-type template parameter pack that 3762/// has been substituted with a non-template argument pack. 3763/// 3764/// When a pack expansion in the source code contains multiple parameter packs 3765/// and those parameter packs correspond to different levels of template 3766/// parameter lists, this node is used to represent a non-type template 3767/// parameter pack from an outer level, which has already had its argument pack 3768/// substituted but that still lives within a pack expansion that itself 3769/// could not be instantiated. When actually performing a substitution into 3770/// that pack expansion (e.g., when all template parameters have corresponding 3771/// arguments), this type will be replaced with the appropriate underlying 3772/// expression at the current pack substitution index. 3773class SubstNonTypeTemplateParmPackExpr : public Expr { 3774 /// \brief The non-type template parameter pack itself. 3775 NonTypeTemplateParmDecl *Param; 3776 3777 /// \brief A pointer to the set of template arguments that this 3778 /// parameter pack is instantiated with. 3779 const TemplateArgument *Arguments; 3780 3781 /// \brief The number of template arguments in \c Arguments. 3782 unsigned NumArguments; 3783 3784 /// \brief The location of the non-type template parameter pack reference. 3785 SourceLocation NameLoc; 3786 3787 friend class ASTReader; 3788 friend class ASTStmtReader; 3789 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 3790 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3791 3792public: 3793 SubstNonTypeTemplateParmPackExpr(QualType T, 3794 NonTypeTemplateParmDecl *Param, 3795 SourceLocation NameLoc, 3796 const TemplateArgument &ArgPack); 3797 3798 /// \brief Retrieve the non-type template parameter pack being substituted. 3799 NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3800 3801 /// \brief Retrieve the location of the parameter pack name. 3802 SourceLocation getParameterPackLocation() const { return NameLoc; } 3803 3804 /// \brief Retrieve the template argument pack containing the substituted 3805 /// template arguments. 3806 TemplateArgument getArgumentPack() const; 3807 3808 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3809 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3810 3811 static bool classof(const Stmt *T) { 3812 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3813 } 3814 3815 // Iterators 3816 child_range children() { return child_range(); } 3817}; 3818 3819/// \brief Represents a reference to a function parameter pack that has been 3820/// substituted but not yet expanded. 3821/// 3822/// When a pack expansion contains multiple parameter packs at different levels, 3823/// this node is used to represent a function parameter pack at an outer level 3824/// which we have already substituted to refer to expanded parameters, but where 3825/// the containing pack expansion cannot yet be expanded. 3826/// 3827/// \code 3828/// template<typename...Ts> struct S { 3829/// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...)); 3830/// }; 3831/// template struct S<int, int>; 3832/// \endcode 3833class FunctionParmPackExpr : public Expr { 3834 /// \brief The function parameter pack which was referenced. 3835 ParmVarDecl *ParamPack; 3836 3837 /// \brief The location of the function parameter pack reference. 3838 SourceLocation NameLoc; 3839 3840 /// \brief The number of expansions of this pack. 3841 unsigned NumParameters; 3842 3843 FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, 3844 SourceLocation NameLoc, unsigned NumParams, 3845 Decl * const *Params); 3846 3847 friend class ASTReader; 3848 friend class ASTStmtReader; 3849 3850public: 3851 static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, 3852 ParmVarDecl *ParamPack, 3853 SourceLocation NameLoc, 3854 ArrayRef<Decl *> Params); 3855 static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context, 3856 unsigned NumParams); 3857 3858 /// \brief Get the parameter pack which this expression refers to. 3859 ParmVarDecl *getParameterPack() const { return ParamPack; } 3860 3861 /// \brief Get the location of the parameter pack. 3862 SourceLocation getParameterPackLocation() const { return NameLoc; } 3863 3864 /// \brief Iterators over the parameters which the parameter pack expanded 3865 /// into. 3866 typedef ParmVarDecl * const *iterator; 3867 iterator begin() const { return reinterpret_cast<iterator>(this+1); } 3868 iterator end() const { return begin() + NumParameters; } 3869 3870 /// \brief Get the number of parameters in this parameter pack. 3871 unsigned getNumExpansions() const { return NumParameters; } 3872 3873 /// \brief Get an expansion of the parameter pack by index. 3874 ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; } 3875 3876 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3877 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3878 3879 static bool classof(const Stmt *T) { 3880 return T->getStmtClass() == FunctionParmPackExprClass; 3881 } 3882 3883 child_range children() { return child_range(); } 3884}; 3885 3886/// \brief Represents a prvalue temporary that is written into memory so that 3887/// a reference can bind to it. 3888/// 3889/// Prvalue expressions are materialized when they need to have an address 3890/// in memory for a reference to bind to. This happens when binding a 3891/// reference to the result of a conversion, e.g., 3892/// 3893/// \code 3894/// const int &r = 1.0; 3895/// \endcode 3896/// 3897/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 3898/// then materialized via a \c MaterializeTemporaryExpr, and the reference 3899/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 3900/// (either an lvalue or an xvalue, depending on the kind of reference binding 3901/// to it), maintaining the invariant that references always bind to glvalues. 3902/// 3903/// Reference binding and copy-elision can both extend the lifetime of a 3904/// temporary. When either happens, the expression will also track the 3905/// declaration which is responsible for the lifetime extension. 3906class MaterializeTemporaryExpr : public Expr { 3907public: 3908 /// \brief The temporary-generating expression whose value will be 3909 /// materialized. 3910 Stmt *Temporary; 3911 3912 /// \brief The declaration which lifetime-extended this reference, if any. 3913 /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl. 3914 const ValueDecl *ExtendingDecl; 3915 3916 friend class ASTStmtReader; 3917 friend class ASTStmtWriter; 3918 3919public: 3920 MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3921 bool BoundToLvalueReference, 3922 const ValueDecl *ExtendedBy) 3923 : Expr(MaterializeTemporaryExprClass, T, 3924 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 3925 Temporary->isTypeDependent(), Temporary->isValueDependent(), 3926 Temporary->isInstantiationDependent(), 3927 Temporary->containsUnexpandedParameterPack()), 3928 Temporary(Temporary), ExtendingDecl(ExtendedBy) { 3929 } 3930 3931 MaterializeTemporaryExpr(EmptyShell Empty) 3932 : Expr(MaterializeTemporaryExprClass, Empty) { } 3933 3934 /// \brief Retrieve the temporary-generating subexpression whose value will 3935 /// be materialized into a glvalue. 3936 Expr *GetTemporaryExpr() const { return static_cast<Expr *>(Temporary); } 3937 3938 /// \brief Retrieve the storage duration for the materialized temporary. 3939 StorageDuration getStorageDuration() const { 3940 if (!ExtendingDecl) 3941 return SD_FullExpression; 3942 // FIXME: This is not necessarily correct for a temporary materialized 3943 // within a default initializer. 3944 if (isa<FieldDecl>(ExtendingDecl)) 3945 return SD_Automatic; 3946 return cast<VarDecl>(ExtendingDecl)->getStorageDuration(); 3947 } 3948 3949 /// \brief Get the declaration which triggered the lifetime-extension of this 3950 /// temporary, if any. 3951 const ValueDecl *getExtendingDecl() const { return ExtendingDecl; } 3952 3953 void setExtendingDecl(const ValueDecl *ExtendedBy) { 3954 ExtendingDecl = ExtendedBy; 3955 } 3956 3957 /// \brief Determine whether this materialized temporary is bound to an 3958 /// lvalue reference; otherwise, it's bound to an rvalue reference. 3959 bool isBoundToLvalueReference() const { 3960 return getValueKind() == VK_LValue; 3961 } 3962 3963 SourceLocation getLocStart() const LLVM_READONLY { 3964 return Temporary->getLocStart(); 3965 } 3966 SourceLocation getLocEnd() const LLVM_READONLY { 3967 return Temporary->getLocEnd(); 3968 } 3969 3970 static bool classof(const Stmt *T) { 3971 return T->getStmtClass() == MaterializeTemporaryExprClass; 3972 } 3973 3974 // Iterators 3975 child_range children() { return child_range(&Temporary, &Temporary + 1); } 3976}; 3977 3978} // end namespace clang 3979 3980#endif 3981