Home | History | Annotate | Download | only in AST
      1 //===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 ///
     10 /// \file
     11 /// \brief Defines the clang::Expr interface and subclasses for C++ expressions.
     12 ///
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_CLANG_AST_EXPRCXX_H
     16 #define LLVM_CLANG_AST_EXPRCXX_H
     17 
     18 #include "clang/AST/Decl.h"
     19 #include "clang/AST/Expr.h"
     20 #include "clang/AST/LambdaCapture.h"
     21 #include "clang/AST/TemplateBase.h"
     22 #include "clang/AST/UnresolvedSet.h"
     23 #include "clang/Basic/ExpressionTraits.h"
     24 #include "clang/Basic/TypeTraits.h"
     25 #include "llvm/Support/Compiler.h"
     26 
     27 namespace clang {
     28 
     29 class CXXConstructorDecl;
     30 class CXXDestructorDecl;
     31 class CXXMethodDecl;
     32 class CXXTemporary;
     33 class MSPropertyDecl;
     34 class TemplateArgumentListInfo;
     35 class UuidAttr;
     36 
     37 //===--------------------------------------------------------------------===//
     38 // C++ Expressions.
     39 //===--------------------------------------------------------------------===//
     40 
     41 /// \brief A call to an overloaded operator written using operator
     42 /// syntax.
     43 ///
     44 /// Represents a call to an overloaded operator written using operator
     45 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
     46 /// normal call, this AST node provides better information about the
     47 /// syntactic representation of the call.
     48 ///
     49 /// In a C++ template, this expression node kind will be used whenever
     50 /// any of the arguments are type-dependent. In this case, the
     51 /// function itself will be a (possibly empty) set of functions and
     52 /// function templates that were found by name lookup at template
     53 /// definition time.
     54 class CXXOperatorCallExpr : public CallExpr {
     55   /// \brief The overloaded operator.
     56   OverloadedOperatorKind Operator;
     57   SourceRange Range;
     58 
     59   // Record the FP_CONTRACT state that applies to this operator call. Only
     60   // meaningful for floating point types. For other types this value can be
     61   // set to false.
     62   unsigned FPContractable : 1;
     63 
     64   SourceRange getSourceRangeImpl() const LLVM_READONLY;
     65 public:
     66   CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
     67                       ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
     68                       SourceLocation operatorloc, bool fpContractable)
     69     : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK,
     70                operatorloc),
     71       Operator(Op), FPContractable(fpContractable) {
     72     Range = getSourceRangeImpl();
     73   }
     74   explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
     75     CallExpr(C, CXXOperatorCallExprClass, Empty) { }
     76 
     77 
     78   /// \brief Returns the kind of overloaded operator that this
     79   /// expression refers to.
     80   OverloadedOperatorKind getOperator() const { return Operator; }
     81 
     82   /// \brief Returns the location of the operator symbol in the expression.
     83   ///
     84   /// When \c getOperator()==OO_Call, this is the location of the right
     85   /// parentheses; when \c getOperator()==OO_Subscript, this is the location
     86   /// of the right bracket.
     87   SourceLocation getOperatorLoc() const { return getRParenLoc(); }
     88 
     89   SourceLocation getExprLoc() const LLVM_READONLY {
     90     return (Operator < OO_Plus || Operator >= OO_Arrow ||
     91             Operator == OO_PlusPlus || Operator == OO_MinusMinus)
     92                ? getLocStart()
     93                : getOperatorLoc();
     94   }
     95 
     96   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
     97   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
     98   SourceRange getSourceRange() const { return Range; }
     99 
    100   static bool classof(const Stmt *T) {
    101     return T->getStmtClass() == CXXOperatorCallExprClass;
    102   }
    103 
    104   // Set the FP contractability status of this operator. Only meaningful for
    105   // operations on floating point types.
    106   void setFPContractable(bool FPC) { FPContractable = FPC; }
    107 
    108   // Get the FP contractability status of this operator. Only meaningful for
    109   // operations on floating point types.
    110   bool isFPContractable() const { return FPContractable; }
    111 
    112   friend class ASTStmtReader;
    113   friend class ASTStmtWriter;
    114 };
    115 
    116 /// Represents a call to a member function that
    117 /// may be written either with member call syntax (e.g., "obj.func()"
    118 /// or "objptr->func()") or with normal function-call syntax
    119 /// ("func()") within a member function that ends up calling a member
    120 /// function. The callee in either case is a MemberExpr that contains
    121 /// both the object argument and the member function, while the
    122 /// arguments are the arguments within the parentheses (not including
    123 /// the object argument).
    124 class CXXMemberCallExpr : public CallExpr {
    125 public:
    126   CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
    127                     QualType t, ExprValueKind VK, SourceLocation RP)
    128     : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {}
    129 
    130   CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
    131     : CallExpr(C, CXXMemberCallExprClass, Empty) { }
    132 
    133   /// \brief Retrieves the implicit object argument for the member call.
    134   ///
    135   /// For example, in "x.f(5)", this returns the sub-expression "x".
    136   Expr *getImplicitObjectArgument() const;
    137 
    138   /// \brief Retrieves the declaration of the called method.
    139   CXXMethodDecl *getMethodDecl() const;
    140 
    141   /// \brief Retrieves the CXXRecordDecl for the underlying type of
    142   /// the implicit object argument.
    143   ///
    144   /// Note that this is may not be the same declaration as that of the class
    145   /// context of the CXXMethodDecl which this function is calling.
    146   /// FIXME: Returns 0 for member pointer call exprs.
    147   CXXRecordDecl *getRecordDecl() const;
    148 
    149   static bool classof(const Stmt *T) {
    150     return T->getStmtClass() == CXXMemberCallExprClass;
    151   }
    152 };
    153 
    154 /// \brief Represents a call to a CUDA kernel function.
    155 class CUDAKernelCallExpr : public CallExpr {
    156 private:
    157   enum { CONFIG, END_PREARG };
    158 
    159 public:
    160   CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
    161                      ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
    162                      SourceLocation RP)
    163     : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) {
    164     setConfig(Config);
    165   }
    166 
    167   CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
    168     : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
    169 
    170   const CallExpr *getConfig() const {
    171     return cast_or_null<CallExpr>(getPreArg(CONFIG));
    172   }
    173   CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
    174   void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
    175 
    176   static bool classof(const Stmt *T) {
    177     return T->getStmtClass() == CUDAKernelCallExprClass;
    178   }
    179 };
    180 
    181 /// \brief Abstract class common to all of the C++ "named"/"keyword" casts.
    182 ///
    183 /// This abstract class is inherited by all of the classes
    184 /// representing "named" casts: CXXStaticCastExpr for \c static_cast,
    185 /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
    186 /// reinterpret_cast, and CXXConstCastExpr for \c const_cast.
    187 class CXXNamedCastExpr : public ExplicitCastExpr {
    188 private:
    189   SourceLocation Loc; // the location of the casting op
    190   SourceLocation RParenLoc; // the location of the right parenthesis
    191   SourceRange AngleBrackets; // range for '<' '>'
    192 
    193 protected:
    194   CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
    195                    CastKind kind, Expr *op, unsigned PathSize,
    196                    TypeSourceInfo *writtenTy, SourceLocation l,
    197                    SourceLocation RParenLoc,
    198                    SourceRange AngleBrackets)
    199     : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
    200       RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
    201 
    202   explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
    203     : ExplicitCastExpr(SC, Shell, PathSize) { }
    204 
    205   friend class ASTStmtReader;
    206 
    207 public:
    208   const char *getCastName() const;
    209 
    210   /// \brief Retrieve the location of the cast operator keyword, e.g.,
    211   /// \c static_cast.
    212   SourceLocation getOperatorLoc() const { return Loc; }
    213 
    214   /// \brief Retrieve the location of the closing parenthesis.
    215   SourceLocation getRParenLoc() const { return RParenLoc; }
    216 
    217   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
    218   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
    219   SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
    220 
    221   static bool classof(const Stmt *T) {
    222     switch (T->getStmtClass()) {
    223     case CXXStaticCastExprClass:
    224     case CXXDynamicCastExprClass:
    225     case CXXReinterpretCastExprClass:
    226     case CXXConstCastExprClass:
    227       return true;
    228     default:
    229       return false;
    230     }
    231   }
    232 };
    233 
    234 /// \brief A C++ \c static_cast expression (C++ [expr.static.cast]).
    235 ///
    236 /// This expression node represents a C++ static cast, e.g.,
    237 /// \c static_cast<int>(1.0).
    238 class CXXStaticCastExpr : public CXXNamedCastExpr {
    239   CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
    240                     unsigned pathSize, TypeSourceInfo *writtenTy,
    241                     SourceLocation l, SourceLocation RParenLoc,
    242                     SourceRange AngleBrackets)
    243     : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
    244                        writtenTy, l, RParenLoc, AngleBrackets) {}
    245 
    246   explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
    247     : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
    248 
    249 public:
    250   static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T,
    251                                    ExprValueKind VK, CastKind K, Expr *Op,
    252                                    const CXXCastPath *Path,
    253                                    TypeSourceInfo *Written, SourceLocation L,
    254                                    SourceLocation RParenLoc,
    255                                    SourceRange AngleBrackets);
    256   static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
    257                                         unsigned PathSize);
    258 
    259   static bool classof(const Stmt *T) {
    260     return T->getStmtClass() == CXXStaticCastExprClass;
    261   }
    262 };
    263 
    264 /// \brief A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
    265 ///
    266 /// This expression node represents a dynamic cast, e.g.,
    267 /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
    268 /// check to determine how to perform the type conversion.
    269 class CXXDynamicCastExpr : public CXXNamedCastExpr {
    270   CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
    271                      Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
    272                      SourceLocation l, SourceLocation RParenLoc,
    273                      SourceRange AngleBrackets)
    274     : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
    275                        writtenTy, l, RParenLoc, AngleBrackets) {}
    276 
    277   explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
    278     : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
    279 
    280 public:
    281   static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
    282                                     ExprValueKind VK, CastKind Kind, Expr *Op,
    283                                     const CXXCastPath *Path,
    284                                     TypeSourceInfo *Written, SourceLocation L,
    285                                     SourceLocation RParenLoc,
    286                                     SourceRange AngleBrackets);
    287 
    288   static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
    289                                          unsigned pathSize);
    290 
    291   bool isAlwaysNull() const;
    292 
    293   static bool classof(const Stmt *T) {
    294     return T->getStmtClass() == CXXDynamicCastExprClass;
    295   }
    296 };
    297 
    298 /// \brief A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
    299 ///
    300 /// This expression node represents a reinterpret cast, e.g.,
    301 /// @c reinterpret_cast<int>(VoidPtr).
    302 ///
    303 /// A reinterpret_cast provides a differently-typed view of a value but
    304 /// (in Clang, as in most C++ implementations) performs no actual work at
    305 /// run time.
    306 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
    307   CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
    308                          Expr *op, unsigned pathSize,
    309                          TypeSourceInfo *writtenTy, SourceLocation l,
    310                          SourceLocation RParenLoc,
    311                          SourceRange AngleBrackets)
    312     : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
    313                        pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
    314 
    315   CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
    316     : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
    317 
    318 public:
    319   static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
    320                                         ExprValueKind VK, CastKind Kind,
    321                                         Expr *Op, const CXXCastPath *Path,
    322                                  TypeSourceInfo *WrittenTy, SourceLocation L,
    323                                         SourceLocation RParenLoc,
    324                                         SourceRange AngleBrackets);
    325   static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
    326                                              unsigned pathSize);
    327 
    328   static bool classof(const Stmt *T) {
    329     return T->getStmtClass() == CXXReinterpretCastExprClass;
    330   }
    331 };
    332 
    333 /// \brief A C++ \c const_cast expression (C++ [expr.const.cast]).
    334 ///
    335 /// This expression node represents a const cast, e.g.,
    336 /// \c const_cast<char*>(PtrToConstChar).
    337 ///
    338 /// A const_cast can remove type qualifiers but does not change the underlying
    339 /// value.
    340 class CXXConstCastExpr : public CXXNamedCastExpr {
    341   CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
    342                    TypeSourceInfo *writtenTy, SourceLocation l,
    343                    SourceLocation RParenLoc, SourceRange AngleBrackets)
    344     : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
    345                        0, writtenTy, l, RParenLoc, AngleBrackets) {}
    346 
    347   explicit CXXConstCastExpr(EmptyShell Empty)
    348     : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
    349 
    350 public:
    351   static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
    352                                   ExprValueKind VK, Expr *Op,
    353                                   TypeSourceInfo *WrittenTy, SourceLocation L,
    354                                   SourceLocation RParenLoc,
    355                                   SourceRange AngleBrackets);
    356   static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
    357 
    358   static bool classof(const Stmt *T) {
    359     return T->getStmtClass() == CXXConstCastExprClass;
    360   }
    361 };
    362 
    363 /// \brief A call to a literal operator (C++11 [over.literal])
    364 /// written as a user-defined literal (C++11 [lit.ext]).
    365 ///
    366 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
    367 /// is semantically equivalent to a normal call, this AST node provides better
    368 /// information about the syntactic representation of the literal.
    369 ///
    370 /// Since literal operators are never found by ADL and can only be declared at
    371 /// namespace scope, a user-defined literal is never dependent.
    372 class UserDefinedLiteral : public CallExpr {
    373   /// \brief The location of a ud-suffix within the literal.
    374   SourceLocation UDSuffixLoc;
    375 
    376 public:
    377   UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
    378                      QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
    379                      SourceLocation SuffixLoc)
    380     : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc),
    381       UDSuffixLoc(SuffixLoc) {}
    382   explicit UserDefinedLiteral(const ASTContext &C, EmptyShell Empty)
    383     : CallExpr(C, UserDefinedLiteralClass, Empty) {}
    384 
    385   /// The kind of literal operator which is invoked.
    386   enum LiteralOperatorKind {
    387     LOK_Raw,      ///< Raw form: operator "" X (const char *)
    388     LOK_Template, ///< Raw form: operator "" X<cs...> ()
    389     LOK_Integer,  ///< operator "" X (unsigned long long)
    390     LOK_Floating, ///< operator "" X (long double)
    391     LOK_String,   ///< operator "" X (const CharT *, size_t)
    392     LOK_Character ///< operator "" X (CharT)
    393   };
    394 
    395   /// \brief Returns the kind of literal operator invocation
    396   /// which this expression represents.
    397   LiteralOperatorKind getLiteralOperatorKind() const;
    398 
    399   /// \brief If this is not a raw user-defined literal, get the
    400   /// underlying cooked literal (representing the literal with the suffix
    401   /// removed).
    402   Expr *getCookedLiteral();
    403   const Expr *getCookedLiteral() const {
    404     return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
    405   }
    406 
    407   SourceLocation getLocStart() const {
    408     if (getLiteralOperatorKind() == LOK_Template)
    409       return getRParenLoc();
    410     return getArg(0)->getLocStart();
    411   }
    412   SourceLocation getLocEnd() const { return getRParenLoc(); }
    413 
    414 
    415   /// \brief Returns the location of a ud-suffix in the expression.
    416   ///
    417   /// For a string literal, there may be multiple identical suffixes. This
    418   /// returns the first.
    419   SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
    420 
    421   /// \brief Returns the ud-suffix specified for this literal.
    422   const IdentifierInfo *getUDSuffix() const;
    423 
    424   static bool classof(const Stmt *S) {
    425     return S->getStmtClass() == UserDefinedLiteralClass;
    426   }
    427 
    428   friend class ASTStmtReader;
    429   friend class ASTStmtWriter;
    430 };
    431 
    432 /// \brief A boolean literal, per ([C++ lex.bool] Boolean literals).
    433 ///
    434 class CXXBoolLiteralExpr : public Expr {
    435   bool Value;
    436   SourceLocation Loc;
    437 public:
    438   CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
    439     Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
    440          false, false),
    441     Value(val), Loc(l) {}
    442 
    443   explicit CXXBoolLiteralExpr(EmptyShell Empty)
    444     : Expr(CXXBoolLiteralExprClass, Empty) { }
    445 
    446   bool getValue() const { return Value; }
    447   void setValue(bool V) { Value = V; }
    448 
    449   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
    450   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
    451 
    452   SourceLocation getLocation() const { return Loc; }
    453   void setLocation(SourceLocation L) { Loc = L; }
    454 
    455   static bool classof(const Stmt *T) {
    456     return T->getStmtClass() == CXXBoolLiteralExprClass;
    457   }
    458 
    459   // Iterators
    460   child_range children() {
    461     return child_range(child_iterator(), child_iterator());
    462   }
    463 };
    464 
    465 /// \brief The null pointer literal (C++11 [lex.nullptr])
    466 ///
    467 /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
    468 class CXXNullPtrLiteralExpr : public Expr {
    469   SourceLocation Loc;
    470 public:
    471   CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
    472     Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
    473          false, false),
    474     Loc(l) {}
    475 
    476   explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
    477     : Expr(CXXNullPtrLiteralExprClass, Empty) { }
    478 
    479   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
    480   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
    481 
    482   SourceLocation getLocation() const { return Loc; }
    483   void setLocation(SourceLocation L) { Loc = L; }
    484 
    485   static bool classof(const Stmt *T) {
    486     return T->getStmtClass() == CXXNullPtrLiteralExprClass;
    487   }
    488 
    489   child_range children() {
    490     return child_range(child_iterator(), child_iterator());
    491   }
    492 };
    493 
    494 /// \brief Implicit construction of a std::initializer_list<T> object from an
    495 /// array temporary within list-initialization (C++11 [dcl.init.list]p5).
    496 class CXXStdInitializerListExpr : public Expr {
    497   Stmt *SubExpr;
    498 
    499   CXXStdInitializerListExpr(EmptyShell Empty)
    500     : Expr(CXXStdInitializerListExprClass, Empty), SubExpr(nullptr) {}
    501 
    502 public:
    503   CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
    504     : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary,
    505            Ty->isDependentType(), SubExpr->isValueDependent(),
    506            SubExpr->isInstantiationDependent(),
    507            SubExpr->containsUnexpandedParameterPack()),
    508       SubExpr(SubExpr) {}
    509 
    510   Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
    511   const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
    512 
    513   SourceLocation getLocStart() const LLVM_READONLY {
    514     return SubExpr->getLocStart();
    515   }
    516   SourceLocation getLocEnd() const LLVM_READONLY {
    517     return SubExpr->getLocEnd();
    518   }
    519   SourceRange getSourceRange() const LLVM_READONLY {
    520     return SubExpr->getSourceRange();
    521   }
    522 
    523   static bool classof(const Stmt *S) {
    524     return S->getStmtClass() == CXXStdInitializerListExprClass;
    525   }
    526 
    527   child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
    528 
    529   friend class ASTReader;
    530   friend class ASTStmtReader;
    531 };
    532 
    533 /// A C++ \c typeid expression (C++ [expr.typeid]), which gets
    534 /// the \c type_info that corresponds to the supplied type, or the (possibly
    535 /// dynamic) type of the supplied expression.
    536 ///
    537 /// This represents code like \c typeid(int) or \c typeid(*objPtr)
    538 class CXXTypeidExpr : public Expr {
    539 private:
    540   llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
    541   SourceRange Range;
    542 
    543 public:
    544   CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
    545     : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
    546            // typeid is never type-dependent (C++ [temp.dep.expr]p4)
    547            false,
    548            // typeid is value-dependent if the type or expression are dependent
    549            Operand->getType()->isDependentType(),
    550            Operand->getType()->isInstantiationDependentType(),
    551            Operand->getType()->containsUnexpandedParameterPack()),
    552       Operand(Operand), Range(R) { }
    553 
    554   CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
    555     : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
    556         // typeid is never type-dependent (C++ [temp.dep.expr]p4)
    557            false,
    558         // typeid is value-dependent if the type or expression are dependent
    559            Operand->isTypeDependent() || Operand->isValueDependent(),
    560            Operand->isInstantiationDependent(),
    561            Operand->containsUnexpandedParameterPack()),
    562       Operand(Operand), Range(R) { }
    563 
    564   CXXTypeidExpr(EmptyShell Empty, bool isExpr)
    565     : Expr(CXXTypeidExprClass, Empty) {
    566     if (isExpr)
    567       Operand = (Expr*)nullptr;
    568     else
    569       Operand = (TypeSourceInfo*)nullptr;
    570   }
    571 
    572   /// Determine whether this typeid has a type operand which is potentially
    573   /// evaluated, per C++11 [expr.typeid]p3.
    574   bool isPotentiallyEvaluated() const;
    575 
    576   bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
    577 
    578   /// \brief Retrieves the type operand of this typeid() expression after
    579   /// various required adjustments (removing reference types, cv-qualifiers).
    580   QualType getTypeOperand(ASTContext &Context) const;
    581 
    582   /// \brief Retrieve source information for the type operand.
    583   TypeSourceInfo *getTypeOperandSourceInfo() const {
    584     assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
    585     return Operand.get<TypeSourceInfo *>();
    586   }
    587 
    588   void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
    589     assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
    590     Operand = TSI;
    591   }
    592 
    593   Expr *getExprOperand() const {
    594     assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
    595     return static_cast<Expr*>(Operand.get<Stmt *>());
    596   }
    597 
    598   void setExprOperand(Expr *E) {
    599     assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
    600     Operand = E;
    601   }
    602 
    603   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
    604   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
    605   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
    606   void setSourceRange(SourceRange R) { Range = R; }
    607 
    608   static bool classof(const Stmt *T) {
    609     return T->getStmtClass() == CXXTypeidExprClass;
    610   }
    611 
    612   // Iterators
    613   child_range children() {
    614     if (isTypeOperand())
    615       return child_range(child_iterator(), child_iterator());
    616     Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
    617     return child_range(begin, begin + 1);
    618   }
    619 };
    620 
    621 /// \brief A member reference to an MSPropertyDecl.
    622 ///
    623 /// This expression always has pseudo-object type, and therefore it is
    624 /// typically not encountered in a fully-typechecked expression except
    625 /// within the syntactic form of a PseudoObjectExpr.
    626 class MSPropertyRefExpr : public Expr {
    627   Expr *BaseExpr;
    628   MSPropertyDecl *TheDecl;
    629   SourceLocation MemberLoc;
    630   bool IsArrow;
    631   NestedNameSpecifierLoc QualifierLoc;
    632 
    633 public:
    634   MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
    635                     QualType ty, ExprValueKind VK,
    636                     NestedNameSpecifierLoc qualifierLoc,
    637                     SourceLocation nameLoc)
    638   : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
    639          /*type-dependent*/ false, baseExpr->isValueDependent(),
    640          baseExpr->isInstantiationDependent(),
    641          baseExpr->containsUnexpandedParameterPack()),
    642     BaseExpr(baseExpr), TheDecl(decl),
    643     MemberLoc(nameLoc), IsArrow(isArrow),
    644     QualifierLoc(qualifierLoc) {}
    645 
    646   MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
    647 
    648   SourceRange getSourceRange() const LLVM_READONLY {
    649     return SourceRange(getLocStart(), getLocEnd());
    650   }
    651   bool isImplicitAccess() const {
    652     return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
    653   }
    654   SourceLocation getLocStart() const {
    655     if (!isImplicitAccess())
    656       return BaseExpr->getLocStart();
    657     else if (QualifierLoc)
    658       return QualifierLoc.getBeginLoc();
    659     else
    660         return MemberLoc;
    661   }
    662   SourceLocation getLocEnd() const { return getMemberLoc(); }
    663 
    664   child_range children() {
    665     return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
    666   }
    667   static bool classof(const Stmt *T) {
    668     return T->getStmtClass() == MSPropertyRefExprClass;
    669   }
    670 
    671   Expr *getBaseExpr() const { return BaseExpr; }
    672   MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
    673   bool isArrow() const { return IsArrow; }
    674   SourceLocation getMemberLoc() const { return MemberLoc; }
    675   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
    676 
    677   friend class ASTStmtReader;
    678 };
    679 
    680 /// MS property subscript expression.
    681 /// MSVC supports 'property' attribute and allows to apply it to the
    682 /// declaration of an empty array in a class or structure definition.
    683 /// For example:
    684 /// \code
    685 /// __declspec(property(get=GetX, put=PutX)) int x[];
    686 /// \endcode
    687 /// The above statement indicates that x[] can be used with one or more array
    688 /// indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and
    689 /// p->x[a][b] = i will be turned into p->PutX(a, b, i).
    690 /// This is a syntactic pseudo-object expression.
    691 class MSPropertySubscriptExpr : public Expr {
    692   friend class ASTStmtReader;
    693   enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 };
    694   Stmt *SubExprs[NUM_SUBEXPRS];
    695   SourceLocation RBracketLoc;
    696 
    697   void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; }
    698   void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; }
    699 
    700 public:
    701   MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK,
    702                           ExprObjectKind OK, SourceLocation RBracketLoc)
    703       : Expr(MSPropertySubscriptExprClass, Ty, VK, OK, Idx->isTypeDependent(),
    704              Idx->isValueDependent(), Idx->isInstantiationDependent(),
    705              Idx->containsUnexpandedParameterPack()),
    706         RBracketLoc(RBracketLoc) {
    707     SubExprs[BASE_EXPR] = Base;
    708     SubExprs[IDX_EXPR] = Idx;
    709   }
    710 
    711   /// \brief Create an empty array subscript expression.
    712   explicit MSPropertySubscriptExpr(EmptyShell Shell)
    713       : Expr(MSPropertySubscriptExprClass, Shell) {}
    714 
    715   Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); }
    716   const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); }
    717 
    718   Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); }
    719   const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); }
    720 
    721   SourceLocation getLocStart() const LLVM_READONLY {
    722     return getBase()->getLocStart();
    723   }
    724   SourceLocation getLocEnd() const LLVM_READONLY { return RBracketLoc; }
    725 
    726   SourceLocation getRBracketLoc() const { return RBracketLoc; }
    727   void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
    728 
    729   SourceLocation getExprLoc() const LLVM_READONLY {
    730     return getBase()->getExprLoc();
    731   }
    732 
    733   static bool classof(const Stmt *T) {
    734     return T->getStmtClass() == MSPropertySubscriptExprClass;
    735   }
    736 
    737   // Iterators
    738   child_range children() {
    739     return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
    740   }
    741 };
    742 
    743 /// A Microsoft C++ @c __uuidof expression, which gets
    744 /// the _GUID that corresponds to the supplied type or expression.
    745 ///
    746 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
    747 class CXXUuidofExpr : public Expr {
    748 private:
    749   llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
    750   SourceRange Range;
    751 
    752 public:
    753   CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
    754     : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
    755            false, Operand->getType()->isDependentType(),
    756            Operand->getType()->isInstantiationDependentType(),
    757            Operand->getType()->containsUnexpandedParameterPack()),
    758       Operand(Operand), Range(R) { }
    759 
    760   CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
    761     : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
    762            false, Operand->isTypeDependent(),
    763            Operand->isInstantiationDependent(),
    764            Operand->containsUnexpandedParameterPack()),
    765       Operand(Operand), Range(R) { }
    766 
    767   CXXUuidofExpr(EmptyShell Empty, bool isExpr)
    768     : Expr(CXXUuidofExprClass, Empty) {
    769     if (isExpr)
    770       Operand = (Expr*)nullptr;
    771     else
    772       Operand = (TypeSourceInfo*)nullptr;
    773   }
    774 
    775   bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
    776 
    777   /// \brief Retrieves the type operand of this __uuidof() expression after
    778   /// various required adjustments (removing reference types, cv-qualifiers).
    779   QualType getTypeOperand(ASTContext &Context) const;
    780 
    781   /// \brief Retrieve source information for the type operand.
    782   TypeSourceInfo *getTypeOperandSourceInfo() const {
    783     assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
    784     return Operand.get<TypeSourceInfo *>();
    785   }
    786 
    787   void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
    788     assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
    789     Operand = TSI;
    790   }
    791 
    792   Expr *getExprOperand() const {
    793     assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
    794     return static_cast<Expr*>(Operand.get<Stmt *>());
    795   }
    796 
    797   void setExprOperand(Expr *E) {
    798     assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
    799     Operand = E;
    800   }
    801 
    802   StringRef getUuidAsStringRef(ASTContext &Context) const;
    803 
    804   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
    805   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
    806   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
    807   void setSourceRange(SourceRange R) { Range = R; }
    808 
    809   static bool classof(const Stmt *T) {
    810     return T->getStmtClass() == CXXUuidofExprClass;
    811   }
    812 
    813   /// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to
    814   /// a single GUID.
    815   static const UuidAttr *GetUuidAttrOfType(QualType QT,
    816                                            bool *HasMultipleGUIDsPtr = nullptr);
    817 
    818   // Iterators
    819   child_range children() {
    820     if (isTypeOperand())
    821       return child_range(child_iterator(), child_iterator());
    822     Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
    823     return child_range(begin, begin + 1);
    824   }
    825 };
    826 
    827 /// \brief Represents the \c this expression in C++.
    828 ///
    829 /// This is a pointer to the object on which the current member function is
    830 /// executing (C++ [expr.prim]p3). Example:
    831 ///
    832 /// \code
    833 /// class Foo {
    834 /// public:
    835 ///   void bar();
    836 ///   void test() { this->bar(); }
    837 /// };
    838 /// \endcode
    839 class CXXThisExpr : public Expr {
    840   SourceLocation Loc;
    841   bool Implicit : 1;
    842 
    843 public:
    844   CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
    845     : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
    846            // 'this' is type-dependent if the class type of the enclosing
    847            // member function is dependent (C++ [temp.dep.expr]p2)
    848            Type->isDependentType(), Type->isDependentType(),
    849            Type->isInstantiationDependentType(),
    850            /*ContainsUnexpandedParameterPack=*/false),
    851       Loc(L), Implicit(isImplicit) { }
    852 
    853   CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
    854 
    855   SourceLocation getLocation() const { return Loc; }
    856   void setLocation(SourceLocation L) { Loc = L; }
    857 
    858   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
    859   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
    860 
    861   bool isImplicit() const { return Implicit; }
    862   void setImplicit(bool I) { Implicit = I; }
    863 
    864   static bool classof(const Stmt *T) {
    865     return T->getStmtClass() == CXXThisExprClass;
    866   }
    867 
    868   // Iterators
    869   child_range children() {
    870     return child_range(child_iterator(), child_iterator());
    871   }
    872 };
    873 
    874 /// \brief A C++ throw-expression (C++ [except.throw]).
    875 ///
    876 /// This handles 'throw' (for re-throwing the current exception) and
    877 /// 'throw' assignment-expression.  When assignment-expression isn't
    878 /// present, Op will be null.
    879 class CXXThrowExpr : public Expr {
    880   Stmt *Op;
    881   SourceLocation ThrowLoc;
    882   /// \brief Whether the thrown variable (if any) is in scope.
    883   unsigned IsThrownVariableInScope : 1;
    884 
    885   friend class ASTStmtReader;
    886 
    887 public:
    888   // \p Ty is the void type which is used as the result type of the
    889   // expression.  The \p l is the location of the throw keyword.  \p expr
    890   // can by null, if the optional expression to throw isn't present.
    891   CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
    892                bool IsThrownVariableInScope) :
    893     Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
    894          expr && expr->isInstantiationDependent(),
    895          expr && expr->containsUnexpandedParameterPack()),
    896     Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
    897   CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
    898 
    899   const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
    900   Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
    901 
    902   SourceLocation getThrowLoc() const { return ThrowLoc; }
    903 
    904   /// \brief Determines whether the variable thrown by this expression (if any!)
    905   /// is within the innermost try block.
    906   ///
    907   /// This information is required to determine whether the NRVO can apply to
    908   /// this variable.
    909   bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
    910 
    911   SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; }
    912   SourceLocation getLocEnd() const LLVM_READONLY {
    913     if (!getSubExpr())
    914       return ThrowLoc;
    915     return getSubExpr()->getLocEnd();
    916   }
    917 
    918   static bool classof(const Stmt *T) {
    919     return T->getStmtClass() == CXXThrowExprClass;
    920   }
    921 
    922   // Iterators
    923   child_range children() {
    924     return child_range(&Op, Op ? &Op+1 : &Op);
    925   }
    926 };
    927 
    928 /// \brief A default argument (C++ [dcl.fct.default]).
    929 ///
    930 /// This wraps up a function call argument that was created from the
    931 /// corresponding parameter's default argument, when the call did not
    932 /// explicitly supply arguments for all of the parameters.
    933 class CXXDefaultArgExpr : public Expr {
    934   /// \brief The parameter whose default is being used.
    935   ///
    936   /// When the bit is set, the subexpression is stored after the
    937   /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
    938   /// actual default expression is the subexpression.
    939   llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
    940 
    941   /// \brief The location where the default argument expression was used.
    942   SourceLocation Loc;
    943 
    944   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
    945     : Expr(SC,
    946            param->hasUnparsedDefaultArg()
    947              ? param->getType().getNonReferenceType()
    948              : param->getDefaultArg()->getType(),
    949            param->getDefaultArg()->getValueKind(),
    950            param->getDefaultArg()->getObjectKind(), false, false, false, false),
    951       Param(param, false), Loc(Loc) { }
    952 
    953   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
    954                     Expr *SubExpr)
    955     : Expr(SC, SubExpr->getType(),
    956            SubExpr->getValueKind(), SubExpr->getObjectKind(),
    957            false, false, false, false),
    958       Param(param, true), Loc(Loc) {
    959     *reinterpret_cast<Expr **>(this + 1) = SubExpr;
    960   }
    961 
    962 public:
    963   CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
    964 
    965   // \p Param is the parameter whose default argument is used by this
    966   // expression.
    967   static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
    968                                    ParmVarDecl *Param) {
    969     return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
    970   }
    971 
    972   // \p Param is the parameter whose default argument is used by this
    973   // expression, and \p SubExpr is the expression that will actually be used.
    974   static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
    975                                    ParmVarDecl *Param, Expr *SubExpr);
    976 
    977   // Retrieve the parameter that the argument was created from.
    978   const ParmVarDecl *getParam() const { return Param.getPointer(); }
    979   ParmVarDecl *getParam() { return Param.getPointer(); }
    980 
    981   // Retrieve the actual argument to the function call.
    982   const Expr *getExpr() const {
    983     if (Param.getInt())
    984       return *reinterpret_cast<Expr const * const*> (this + 1);
    985     return getParam()->getDefaultArg();
    986   }
    987   Expr *getExpr() {
    988     if (Param.getInt())
    989       return *reinterpret_cast<Expr **> (this + 1);
    990     return getParam()->getDefaultArg();
    991   }
    992 
    993   /// \brief Retrieve the location where this default argument was actually
    994   /// used.
    995   SourceLocation getUsedLocation() const { return Loc; }
    996 
    997   /// Default argument expressions have no representation in the
    998   /// source, so they have an empty source range.
    999   SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
   1000   SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
   1001 
   1002   SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
   1003 
   1004   static bool classof(const Stmt *T) {
   1005     return T->getStmtClass() == CXXDefaultArgExprClass;
   1006   }
   1007 
   1008   // Iterators
   1009   child_range children() {
   1010     return child_range(child_iterator(), child_iterator());
   1011   }
   1012 
   1013   friend class ASTStmtReader;
   1014   friend class ASTStmtWriter;
   1015 };
   1016 
   1017 /// \brief A use of a default initializer in a constructor or in aggregate
   1018 /// initialization.
   1019 ///
   1020 /// This wraps a use of a C++ default initializer (technically,
   1021 /// a brace-or-equal-initializer for a non-static data member) when it
   1022 /// is implicitly used in a mem-initializer-list in a constructor
   1023 /// (C++11 [class.base.init]p8) or in aggregate initialization
   1024 /// (C++1y [dcl.init.aggr]p7).
   1025 class CXXDefaultInitExpr : public Expr {
   1026   /// \brief The field whose default is being used.
   1027   FieldDecl *Field;
   1028 
   1029   /// \brief The location where the default initializer expression was used.
   1030   SourceLocation Loc;
   1031 
   1032   CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field,
   1033                      QualType T);
   1034 
   1035   CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
   1036 
   1037 public:
   1038   /// \p Field is the non-static data member whose default initializer is used
   1039   /// by this expression.
   1040   static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc,
   1041                                     FieldDecl *Field) {
   1042     return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType());
   1043   }
   1044 
   1045   /// \brief Get the field whose initializer will be used.
   1046   FieldDecl *getField() { return Field; }
   1047   const FieldDecl *getField() const { return Field; }
   1048 
   1049   /// \brief Get the initialization expression that will be used.
   1050   const Expr *getExpr() const {
   1051     assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
   1052     return Field->getInClassInitializer();
   1053   }
   1054   Expr *getExpr() {
   1055     assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
   1056     return Field->getInClassInitializer();
   1057   }
   1058 
   1059   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
   1060   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
   1061 
   1062   static bool classof(const Stmt *T) {
   1063     return T->getStmtClass() == CXXDefaultInitExprClass;
   1064   }
   1065 
   1066   // Iterators
   1067   child_range children() {
   1068     return child_range(child_iterator(), child_iterator());
   1069   }
   1070 
   1071   friend class ASTReader;
   1072   friend class ASTStmtReader;
   1073 };
   1074 
   1075 /// \brief Represents a C++ temporary.
   1076 class CXXTemporary {
   1077   /// \brief The destructor that needs to be called.
   1078   const CXXDestructorDecl *Destructor;
   1079 
   1080   explicit CXXTemporary(const CXXDestructorDecl *destructor)
   1081     : Destructor(destructor) { }
   1082 
   1083 public:
   1084   static CXXTemporary *Create(const ASTContext &C,
   1085                               const CXXDestructorDecl *Destructor);
   1086 
   1087   const CXXDestructorDecl *getDestructor() const { return Destructor; }
   1088   void setDestructor(const CXXDestructorDecl *Dtor) {
   1089     Destructor = Dtor;
   1090   }
   1091 };
   1092 
   1093 /// \brief Represents binding an expression to a temporary.
   1094 ///
   1095 /// This ensures the destructor is called for the temporary. It should only be
   1096 /// needed for non-POD, non-trivially destructable class types. For example:
   1097 ///
   1098 /// \code
   1099 ///   struct S {
   1100 ///     S() { }  // User defined constructor makes S non-POD.
   1101 ///     ~S() { } // User defined destructor makes it non-trivial.
   1102 ///   };
   1103 ///   void test() {
   1104 ///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
   1105 ///   }
   1106 /// \endcode
   1107 class CXXBindTemporaryExpr : public Expr {
   1108   CXXTemporary *Temp;
   1109 
   1110   Stmt *SubExpr;
   1111 
   1112   CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
   1113    : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
   1114           VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
   1115           SubExpr->isValueDependent(),
   1116           SubExpr->isInstantiationDependent(),
   1117           SubExpr->containsUnexpandedParameterPack()),
   1118      Temp(temp), SubExpr(SubExpr) { }
   1119 
   1120 public:
   1121   CXXBindTemporaryExpr(EmptyShell Empty)
   1122     : Expr(CXXBindTemporaryExprClass, Empty), Temp(nullptr), SubExpr(nullptr) {}
   1123 
   1124   static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
   1125                                       Expr* SubExpr);
   1126 
   1127   CXXTemporary *getTemporary() { return Temp; }
   1128   const CXXTemporary *getTemporary() const { return Temp; }
   1129   void setTemporary(CXXTemporary *T) { Temp = T; }
   1130 
   1131   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
   1132   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
   1133   void setSubExpr(Expr *E) { SubExpr = E; }
   1134 
   1135   SourceLocation getLocStart() const LLVM_READONLY {
   1136     return SubExpr->getLocStart();
   1137   }
   1138   SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
   1139 
   1140   // Implement isa/cast/dyncast/etc.
   1141   static bool classof(const Stmt *T) {
   1142     return T->getStmtClass() == CXXBindTemporaryExprClass;
   1143   }
   1144 
   1145   // Iterators
   1146   child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
   1147 };
   1148 
   1149 /// \brief Represents a call to a C++ constructor.
   1150 class CXXConstructExpr : public Expr {
   1151 public:
   1152   enum ConstructionKind {
   1153     CK_Complete,
   1154     CK_NonVirtualBase,
   1155     CK_VirtualBase,
   1156     CK_Delegating
   1157   };
   1158 
   1159 private:
   1160   CXXConstructorDecl *Constructor;
   1161 
   1162   SourceLocation Loc;
   1163   SourceRange ParenOrBraceRange;
   1164   unsigned NumArgs : 16;
   1165   bool Elidable : 1;
   1166   bool HadMultipleCandidates : 1;
   1167   bool ListInitialization : 1;
   1168   bool StdInitListInitialization : 1;
   1169   bool ZeroInitialization : 1;
   1170   unsigned ConstructKind : 2;
   1171   Stmt **Args;
   1172 
   1173 protected:
   1174   CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T,
   1175                    SourceLocation Loc,
   1176                    CXXConstructorDecl *d, bool elidable,
   1177                    ArrayRef<Expr *> Args,
   1178                    bool HadMultipleCandidates,
   1179                    bool ListInitialization,
   1180                    bool StdInitListInitialization,
   1181                    bool ZeroInitialization,
   1182                    ConstructionKind ConstructKind,
   1183                    SourceRange ParenOrBraceRange);
   1184 
   1185   /// \brief Construct an empty C++ construction expression.
   1186   CXXConstructExpr(StmtClass SC, EmptyShell Empty)
   1187     : Expr(SC, Empty), Constructor(nullptr), NumArgs(0), Elidable(false),
   1188       HadMultipleCandidates(false), ListInitialization(false),
   1189       ZeroInitialization(false), ConstructKind(0), Args(nullptr)
   1190   { }
   1191 
   1192 public:
   1193   /// \brief Construct an empty C++ construction expression.
   1194   explicit CXXConstructExpr(EmptyShell Empty)
   1195     : Expr(CXXConstructExprClass, Empty), Constructor(nullptr),
   1196       NumArgs(0), Elidable(false), HadMultipleCandidates(false),
   1197       ListInitialization(false), ZeroInitialization(false),
   1198       ConstructKind(0), Args(nullptr)
   1199   { }
   1200 
   1201   static CXXConstructExpr *Create(const ASTContext &C, QualType T,
   1202                                   SourceLocation Loc,
   1203                                   CXXConstructorDecl *D, bool Elidable,
   1204                                   ArrayRef<Expr *> Args,
   1205                                   bool HadMultipleCandidates,
   1206                                   bool ListInitialization,
   1207                                   bool StdInitListInitialization,
   1208                                   bool ZeroInitialization,
   1209                                   ConstructionKind ConstructKind,
   1210                                   SourceRange ParenOrBraceRange);
   1211 
   1212   CXXConstructorDecl *getConstructor() const { return Constructor; }
   1213   void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
   1214 
   1215   SourceLocation getLocation() const { return Loc; }
   1216   void setLocation(SourceLocation Loc) { this->Loc = Loc; }
   1217 
   1218   /// \brief Whether this construction is elidable.
   1219   bool isElidable() const { return Elidable; }
   1220   void setElidable(bool E) { Elidable = E; }
   1221 
   1222   /// \brief Whether the referred constructor was resolved from
   1223   /// an overloaded set having size greater than 1.
   1224   bool hadMultipleCandidates() const { return HadMultipleCandidates; }
   1225   void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
   1226 
   1227   /// \brief Whether this constructor call was written as list-initialization.
   1228   bool isListInitialization() const { return ListInitialization; }
   1229   void setListInitialization(bool V) { ListInitialization = V; }
   1230 
   1231   /// \brief Whether this constructor call was written as list-initialization,
   1232   /// but was interpreted as forming a std::initializer_list<T> from the list
   1233   /// and passing that as a single constructor argument.
   1234   /// See C++11 [over.match.list]p1 bullet 1.
   1235   bool isStdInitListInitialization() const { return StdInitListInitialization; }
   1236   void setStdInitListInitialization(bool V) { StdInitListInitialization = V; }
   1237 
   1238   /// \brief Whether this construction first requires
   1239   /// zero-initialization before the initializer is called.
   1240   bool requiresZeroInitialization() const { return ZeroInitialization; }
   1241   void setRequiresZeroInitialization(bool ZeroInit) {
   1242     ZeroInitialization = ZeroInit;
   1243   }
   1244 
   1245   /// \brief Determine whether this constructor is actually constructing
   1246   /// a base class (rather than a complete object).
   1247   ConstructionKind getConstructionKind() const {
   1248     return (ConstructionKind)ConstructKind;
   1249   }
   1250   void setConstructionKind(ConstructionKind CK) {
   1251     ConstructKind = CK;
   1252   }
   1253 
   1254   typedef ExprIterator arg_iterator;
   1255   typedef ConstExprIterator const_arg_iterator;
   1256   typedef llvm::iterator_range<arg_iterator> arg_range;
   1257   typedef llvm::iterator_range<const_arg_iterator> arg_const_range;
   1258 
   1259   arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
   1260   arg_const_range arguments() const {
   1261     return arg_const_range(arg_begin(), arg_end());
   1262   }
   1263 
   1264   arg_iterator arg_begin() { return Args; }
   1265   arg_iterator arg_end() { return Args + NumArgs; }
   1266   const_arg_iterator arg_begin() const { return Args; }
   1267   const_arg_iterator arg_end() const { return Args + NumArgs; }
   1268 
   1269   Expr **getArgs() { return reinterpret_cast<Expr **>(Args); }
   1270   const Expr *const *getArgs() const {
   1271     return const_cast<CXXConstructExpr *>(this)->getArgs();
   1272   }
   1273   unsigned getNumArgs() const { return NumArgs; }
   1274 
   1275   /// \brief Return the specified argument.
   1276   Expr *getArg(unsigned Arg) {
   1277     assert(Arg < NumArgs && "Arg access out of range!");
   1278     return cast<Expr>(Args[Arg]);
   1279   }
   1280   const Expr *getArg(unsigned Arg) const {
   1281     assert(Arg < NumArgs && "Arg access out of range!");
   1282     return cast<Expr>(Args[Arg]);
   1283   }
   1284 
   1285   /// \brief Set the specified argument.
   1286   void setArg(unsigned Arg, Expr *ArgExpr) {
   1287     assert(Arg < NumArgs && "Arg access out of range!");
   1288     Args[Arg] = ArgExpr;
   1289   }
   1290 
   1291   SourceLocation getLocStart() const LLVM_READONLY;
   1292   SourceLocation getLocEnd() const LLVM_READONLY;
   1293   SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
   1294   void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
   1295 
   1296   static bool classof(const Stmt *T) {
   1297     return T->getStmtClass() == CXXConstructExprClass ||
   1298       T->getStmtClass() == CXXTemporaryObjectExprClass;
   1299   }
   1300 
   1301   // Iterators
   1302   child_range children() {
   1303     return child_range(&Args[0], &Args[0]+NumArgs);
   1304   }
   1305 
   1306   friend class ASTStmtReader;
   1307 };
   1308 
   1309 /// \brief Represents an explicit C++ type conversion that uses "functional"
   1310 /// notation (C++ [expr.type.conv]).
   1311 ///
   1312 /// Example:
   1313 /// \code
   1314 ///   x = int(0.5);
   1315 /// \endcode
   1316 class CXXFunctionalCastExpr : public ExplicitCastExpr {
   1317   SourceLocation LParenLoc;
   1318   SourceLocation RParenLoc;
   1319 
   1320   CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
   1321                         TypeSourceInfo *writtenTy,
   1322                         CastKind kind, Expr *castExpr, unsigned pathSize,
   1323                         SourceLocation lParenLoc, SourceLocation rParenLoc)
   1324     : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
   1325                        castExpr, pathSize, writtenTy),
   1326       LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
   1327 
   1328   explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
   1329     : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
   1330 
   1331 public:
   1332   static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
   1333                                        ExprValueKind VK,
   1334                                        TypeSourceInfo *Written,
   1335                                        CastKind Kind, Expr *Op,
   1336                                        const CXXCastPath *Path,
   1337                                        SourceLocation LPLoc,
   1338                                        SourceLocation RPLoc);
   1339   static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
   1340                                             unsigned PathSize);
   1341 
   1342   SourceLocation getLParenLoc() const { return LParenLoc; }
   1343   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
   1344   SourceLocation getRParenLoc() const { return RParenLoc; }
   1345   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
   1346 
   1347   SourceLocation getLocStart() const LLVM_READONLY;
   1348   SourceLocation getLocEnd() const LLVM_READONLY;
   1349 
   1350   static bool classof(const Stmt *T) {
   1351     return T->getStmtClass() == CXXFunctionalCastExprClass;
   1352   }
   1353 };
   1354 
   1355 /// @brief Represents a C++ functional cast expression that builds a
   1356 /// temporary object.
   1357 ///
   1358 /// This expression type represents a C++ "functional" cast
   1359 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
   1360 /// constructor to build a temporary object. With N == 1 arguments the
   1361 /// functional cast expression will be represented by CXXFunctionalCastExpr.
   1362 /// Example:
   1363 /// \code
   1364 /// struct X { X(int, float); }
   1365 ///
   1366 /// X create_X() {
   1367 ///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
   1368 /// };
   1369 /// \endcode
   1370 class CXXTemporaryObjectExpr : public CXXConstructExpr {
   1371   TypeSourceInfo *Type;
   1372 
   1373 public:
   1374   CXXTemporaryObjectExpr(const ASTContext &C, CXXConstructorDecl *Cons,
   1375                          TypeSourceInfo *Type,
   1376                          ArrayRef<Expr *> Args,
   1377                          SourceRange ParenOrBraceRange,
   1378                          bool HadMultipleCandidates,
   1379                          bool ListInitialization,
   1380                          bool StdInitListInitialization,
   1381                          bool ZeroInitialization);
   1382   explicit CXXTemporaryObjectExpr(EmptyShell Empty)
   1383     : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
   1384 
   1385   TypeSourceInfo *getTypeSourceInfo() const { return Type; }
   1386 
   1387   SourceLocation getLocStart() const LLVM_READONLY;
   1388   SourceLocation getLocEnd() const LLVM_READONLY;
   1389 
   1390   static bool classof(const Stmt *T) {
   1391     return T->getStmtClass() == CXXTemporaryObjectExprClass;
   1392   }
   1393 
   1394   friend class ASTStmtReader;
   1395 };
   1396 
   1397 /// \brief A C++ lambda expression, which produces a function object
   1398 /// (of unspecified type) that can be invoked later.
   1399 ///
   1400 /// Example:
   1401 /// \code
   1402 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
   1403 ///   values.erase(std::remove_if(values.begin(), values.end(),
   1404 ///                               [=](double value) { return value > cutoff; });
   1405 /// }
   1406 /// \endcode
   1407 ///
   1408 /// C++11 lambda expressions can capture local variables, either by copying
   1409 /// the values of those local variables at the time the function
   1410 /// object is constructed (not when it is called!) or by holding a
   1411 /// reference to the local variable. These captures can occur either
   1412 /// implicitly or can be written explicitly between the square
   1413 /// brackets ([...]) that start the lambda expression.
   1414 ///
   1415 /// C++1y introduces a new form of "capture" called an init-capture that
   1416 /// includes an initializing expression (rather than capturing a variable),
   1417 /// and which can never occur implicitly.
   1418 class LambdaExpr : public Expr {
   1419   /// \brief The source range that covers the lambda introducer ([...]).
   1420   SourceRange IntroducerRange;
   1421 
   1422   /// \brief The source location of this lambda's capture-default ('=' or '&').
   1423   SourceLocation CaptureDefaultLoc;
   1424 
   1425   /// \brief The number of captures.
   1426   unsigned NumCaptures : 16;
   1427 
   1428   /// \brief The default capture kind, which is a value of type
   1429   /// LambdaCaptureDefault.
   1430   unsigned CaptureDefault : 2;
   1431 
   1432   /// \brief Whether this lambda had an explicit parameter list vs. an
   1433   /// implicit (and empty) parameter list.
   1434   unsigned ExplicitParams : 1;
   1435 
   1436   /// \brief Whether this lambda had the result type explicitly specified.
   1437   unsigned ExplicitResultType : 1;
   1438 
   1439   /// \brief Whether there are any array index variables stored at the end of
   1440   /// this lambda expression.
   1441   unsigned HasArrayIndexVars : 1;
   1442 
   1443   /// \brief The location of the closing brace ('}') that completes
   1444   /// the lambda.
   1445   ///
   1446   /// The location of the brace is also available by looking up the
   1447   /// function call operator in the lambda class. However, it is
   1448   /// stored here to improve the performance of getSourceRange(), and
   1449   /// to avoid having to deserialize the function call operator from a
   1450   /// module file just to determine the source range.
   1451   SourceLocation ClosingBrace;
   1452 
   1453   // Note: The capture initializers are stored directly after the lambda
   1454   // expression, along with the index variables used to initialize by-copy
   1455   // array captures.
   1456 
   1457   typedef LambdaCapture Capture;
   1458 
   1459   /// \brief Construct a lambda expression.
   1460   LambdaExpr(QualType T, SourceRange IntroducerRange,
   1461              LambdaCaptureDefault CaptureDefault,
   1462              SourceLocation CaptureDefaultLoc,
   1463              ArrayRef<Capture> Captures,
   1464              bool ExplicitParams,
   1465              bool ExplicitResultType,
   1466              ArrayRef<Expr *> CaptureInits,
   1467              ArrayRef<VarDecl *> ArrayIndexVars,
   1468              ArrayRef<unsigned> ArrayIndexStarts,
   1469              SourceLocation ClosingBrace,
   1470              bool ContainsUnexpandedParameterPack);
   1471 
   1472   /// \brief Construct an empty lambda expression.
   1473   LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
   1474     : Expr(LambdaExprClass, Empty),
   1475       NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
   1476       ExplicitResultType(false), HasArrayIndexVars(true) {
   1477     getStoredStmts()[NumCaptures] = nullptr;
   1478   }
   1479 
   1480   Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); }
   1481 
   1482   Stmt *const *getStoredStmts() const {
   1483     return reinterpret_cast<Stmt *const *>(this + 1);
   1484   }
   1485 
   1486   /// \brief Retrieve the mapping from captures to the first array index
   1487   /// variable.
   1488   unsigned *getArrayIndexStarts() {
   1489     return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
   1490   }
   1491 
   1492   const unsigned *getArrayIndexStarts() const {
   1493     return reinterpret_cast<const unsigned *>(getStoredStmts() + NumCaptures +
   1494                                               1);
   1495   }
   1496 
   1497   /// \brief Retrieve the complete set of array-index variables.
   1498   VarDecl **getArrayIndexVars() {
   1499     unsigned ArrayIndexSize = llvm::RoundUpToAlignment(
   1500         sizeof(unsigned) * (NumCaptures + 1), llvm::alignOf<VarDecl *>());
   1501     return reinterpret_cast<VarDecl **>(
   1502         reinterpret_cast<char *>(getArrayIndexStarts()) + ArrayIndexSize);
   1503   }
   1504 
   1505   VarDecl *const *getArrayIndexVars() const {
   1506     unsigned ArrayIndexSize = llvm::RoundUpToAlignment(
   1507         sizeof(unsigned) * (NumCaptures + 1), llvm::alignOf<VarDecl *>());
   1508     return reinterpret_cast<VarDecl *const *>(
   1509         reinterpret_cast<const char *>(getArrayIndexStarts()) + ArrayIndexSize);
   1510   }
   1511 
   1512 public:
   1513   /// \brief Construct a new lambda expression.
   1514   static LambdaExpr *Create(const ASTContext &C,
   1515                             CXXRecordDecl *Class,
   1516                             SourceRange IntroducerRange,
   1517                             LambdaCaptureDefault CaptureDefault,
   1518                             SourceLocation CaptureDefaultLoc,
   1519                             ArrayRef<Capture> Captures,
   1520                             bool ExplicitParams,
   1521                             bool ExplicitResultType,
   1522                             ArrayRef<Expr *> CaptureInits,
   1523                             ArrayRef<VarDecl *> ArrayIndexVars,
   1524                             ArrayRef<unsigned> ArrayIndexStarts,
   1525                             SourceLocation ClosingBrace,
   1526                             bool ContainsUnexpandedParameterPack);
   1527 
   1528   /// \brief Construct a new lambda expression that will be deserialized from
   1529   /// an external source.
   1530   static LambdaExpr *CreateDeserialized(const ASTContext &C,
   1531                                         unsigned NumCaptures,
   1532                                         unsigned NumArrayIndexVars);
   1533 
   1534   /// \brief Determine the default capture kind for this lambda.
   1535   LambdaCaptureDefault getCaptureDefault() const {
   1536     return static_cast<LambdaCaptureDefault>(CaptureDefault);
   1537   }
   1538 
   1539   /// \brief Retrieve the location of this lambda's capture-default, if any.
   1540   SourceLocation getCaptureDefaultLoc() const {
   1541     return CaptureDefaultLoc;
   1542   }
   1543 
   1544   /// \brief Determine whether one of this lambda's captures is an init-capture.
   1545   bool isInitCapture(const LambdaCapture *Capture) const;
   1546 
   1547   /// \brief An iterator that walks over the captures of the lambda,
   1548   /// both implicit and explicit.
   1549   typedef const Capture *capture_iterator;
   1550 
   1551   /// \brief An iterator over a range of lambda captures.
   1552   typedef llvm::iterator_range<capture_iterator> capture_range;
   1553 
   1554   /// \brief Retrieve this lambda's captures.
   1555   capture_range captures() const;
   1556 
   1557   /// \brief Retrieve an iterator pointing to the first lambda capture.
   1558   capture_iterator capture_begin() const;
   1559 
   1560   /// \brief Retrieve an iterator pointing past the end of the
   1561   /// sequence of lambda captures.
   1562   capture_iterator capture_end() const;
   1563 
   1564   /// \brief Determine the number of captures in this lambda.
   1565   unsigned capture_size() const { return NumCaptures; }
   1566 
   1567   /// \brief Retrieve this lambda's explicit captures.
   1568   capture_range explicit_captures() const;
   1569 
   1570   /// \brief Retrieve an iterator pointing to the first explicit
   1571   /// lambda capture.
   1572   capture_iterator explicit_capture_begin() const;
   1573 
   1574   /// \brief Retrieve an iterator pointing past the end of the sequence of
   1575   /// explicit lambda captures.
   1576   capture_iterator explicit_capture_end() const;
   1577 
   1578   /// \brief Retrieve this lambda's implicit captures.
   1579   capture_range implicit_captures() const;
   1580 
   1581   /// \brief Retrieve an iterator pointing to the first implicit
   1582   /// lambda capture.
   1583   capture_iterator implicit_capture_begin() const;
   1584 
   1585   /// \brief Retrieve an iterator pointing past the end of the sequence of
   1586   /// implicit lambda captures.
   1587   capture_iterator implicit_capture_end() const;
   1588 
   1589   /// \brief Iterator that walks over the capture initialization
   1590   /// arguments.
   1591   typedef Expr **capture_init_iterator;
   1592 
   1593   /// \brief Const iterator that walks over the capture initialization
   1594   /// arguments.
   1595   typedef Expr *const *const_capture_init_iterator;
   1596 
   1597   /// \brief Retrieve the initialization expressions for this lambda's captures.
   1598   llvm::iterator_range<capture_init_iterator> capture_inits() {
   1599     return llvm::make_range(capture_init_begin(), capture_init_end());
   1600   }
   1601 
   1602   /// \brief Retrieve the initialization expressions for this lambda's captures.
   1603   llvm::iterator_range<const_capture_init_iterator> capture_inits() const {
   1604     return llvm::make_range(capture_init_begin(), capture_init_end());
   1605   }
   1606 
   1607   /// \brief Retrieve the first initialization argument for this
   1608   /// lambda expression (which initializes the first capture field).
   1609   capture_init_iterator capture_init_begin() {
   1610     return reinterpret_cast<Expr **>(getStoredStmts());
   1611   }
   1612 
   1613   /// \brief Retrieve the first initialization argument for this
   1614   /// lambda expression (which initializes the first capture field).
   1615   const_capture_init_iterator capture_init_begin() const {
   1616     return reinterpret_cast<Expr *const *>(getStoredStmts());
   1617   }
   1618 
   1619   /// \brief Retrieve the iterator pointing one past the last
   1620   /// initialization argument for this lambda expression.
   1621   capture_init_iterator capture_init_end() {
   1622     return capture_init_begin() + NumCaptures;
   1623   }
   1624 
   1625   /// \brief Retrieve the iterator pointing one past the last
   1626   /// initialization argument for this lambda expression.
   1627   const_capture_init_iterator capture_init_end() const {
   1628     return capture_init_begin() + NumCaptures;
   1629   }
   1630 
   1631   /// \brief Retrieve the set of index variables used in the capture
   1632   /// initializer of an array captured by copy.
   1633   ///
   1634   /// \param Iter The iterator that points at the capture initializer for
   1635   /// which we are extracting the corresponding index variables.
   1636   ArrayRef<VarDecl *>
   1637   getCaptureInitIndexVars(const_capture_init_iterator Iter) const;
   1638 
   1639   /// \brief Retrieve the source range covering the lambda introducer,
   1640   /// which contains the explicit capture list surrounded by square
   1641   /// brackets ([...]).
   1642   SourceRange getIntroducerRange() const { return IntroducerRange; }
   1643 
   1644   /// \brief Retrieve the class that corresponds to the lambda.
   1645   ///
   1646   /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
   1647   /// captures in its fields and provides the various operations permitted
   1648   /// on a lambda (copying, calling).
   1649   CXXRecordDecl *getLambdaClass() const;
   1650 
   1651   /// \brief Retrieve the function call operator associated with this
   1652   /// lambda expression.
   1653   CXXMethodDecl *getCallOperator() const;
   1654 
   1655   /// \brief If this is a generic lambda expression, retrieve the template
   1656   /// parameter list associated with it, or else return null.
   1657   TemplateParameterList *getTemplateParameterList() const;
   1658 
   1659   /// \brief Whether this is a generic lambda.
   1660   bool isGenericLambda() const { return getTemplateParameterList(); }
   1661 
   1662   /// \brief Retrieve the body of the lambda.
   1663   CompoundStmt *getBody() const;
   1664 
   1665   /// \brief Determine whether the lambda is mutable, meaning that any
   1666   /// captures values can be modified.
   1667   bool isMutable() const;
   1668 
   1669   /// \brief Determine whether this lambda has an explicit parameter
   1670   /// list vs. an implicit (empty) parameter list.
   1671   bool hasExplicitParameters() const { return ExplicitParams; }
   1672 
   1673   /// \brief Whether this lambda had its result type explicitly specified.
   1674   bool hasExplicitResultType() const { return ExplicitResultType; }
   1675 
   1676   static bool classof(const Stmt *T) {
   1677     return T->getStmtClass() == LambdaExprClass;
   1678   }
   1679 
   1680   SourceLocation getLocStart() const LLVM_READONLY {
   1681     return IntroducerRange.getBegin();
   1682   }
   1683   SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
   1684 
   1685   child_range children() {
   1686     return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
   1687   }
   1688 
   1689   friend class ASTStmtReader;
   1690   friend class ASTStmtWriter;
   1691 };
   1692 
   1693 /// An expression "T()" which creates a value-initialized rvalue of type
   1694 /// T, which is a non-class type.  See (C++98 [5.2.3p2]).
   1695 class CXXScalarValueInitExpr : public Expr {
   1696   SourceLocation RParenLoc;
   1697   TypeSourceInfo *TypeInfo;
   1698 
   1699   friend class ASTStmtReader;
   1700 
   1701 public:
   1702   /// \brief Create an explicitly-written scalar-value initialization
   1703   /// expression.
   1704   CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
   1705                          SourceLocation rParenLoc)
   1706       : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
   1707              false, false, Type->isInstantiationDependentType(),
   1708              Type->containsUnexpandedParameterPack()),
   1709         RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
   1710 
   1711   explicit CXXScalarValueInitExpr(EmptyShell Shell)
   1712     : Expr(CXXScalarValueInitExprClass, Shell) { }
   1713 
   1714   TypeSourceInfo *getTypeSourceInfo() const {
   1715     return TypeInfo;
   1716   }
   1717 
   1718   SourceLocation getRParenLoc() const { return RParenLoc; }
   1719 
   1720   SourceLocation getLocStart() const LLVM_READONLY;
   1721   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
   1722 
   1723   static bool classof(const Stmt *T) {
   1724     return T->getStmtClass() == CXXScalarValueInitExprClass;
   1725   }
   1726 
   1727   // Iterators
   1728   child_range children() {
   1729     return child_range(child_iterator(), child_iterator());
   1730   }
   1731 };
   1732 
   1733 /// \brief Represents a new-expression for memory allocation and constructor
   1734 /// calls, e.g: "new CXXNewExpr(foo)".
   1735 class CXXNewExpr : public Expr {
   1736   /// Contains an optional array size expression, an optional initialization
   1737   /// expression, and any number of optional placement arguments, in that order.
   1738   Stmt **SubExprs;
   1739   /// \brief Points to the allocation function used.
   1740   FunctionDecl *OperatorNew;
   1741   /// \brief Points to the deallocation function used in case of error. May be
   1742   /// null.
   1743   FunctionDecl *OperatorDelete;
   1744 
   1745   /// \brief The allocated type-source information, as written in the source.
   1746   TypeSourceInfo *AllocatedTypeInfo;
   1747 
   1748   /// \brief If the allocated type was expressed as a parenthesized type-id,
   1749   /// the source range covering the parenthesized type-id.
   1750   SourceRange TypeIdParens;
   1751 
   1752   /// \brief Range of the entire new expression.
   1753   SourceRange Range;
   1754 
   1755   /// \brief Source-range of a paren-delimited initializer.
   1756   SourceRange DirectInitRange;
   1757 
   1758   /// Was the usage ::new, i.e. is the global new to be used?
   1759   bool GlobalNew : 1;
   1760   /// Do we allocate an array? If so, the first SubExpr is the size expression.
   1761   bool Array : 1;
   1762   /// If this is an array allocation, does the usual deallocation
   1763   /// function for the allocated type want to know the allocated size?
   1764   bool UsualArrayDeleteWantsSize : 1;
   1765   /// The number of placement new arguments.
   1766   unsigned NumPlacementArgs : 13;
   1767   /// What kind of initializer do we have? Could be none, parens, or braces.
   1768   /// In storage, we distinguish between "none, and no initializer expr", and
   1769   /// "none, but an implicit initializer expr".
   1770   unsigned StoredInitializationStyle : 2;
   1771 
   1772   friend class ASTStmtReader;
   1773   friend class ASTStmtWriter;
   1774 public:
   1775   enum InitializationStyle {
   1776     NoInit,   ///< New-expression has no initializer as written.
   1777     CallInit, ///< New-expression has a C++98 paren-delimited initializer.
   1778     ListInit  ///< New-expression has a C++11 list-initializer.
   1779   };
   1780 
   1781   CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
   1782              FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
   1783              ArrayRef<Expr*> placementArgs,
   1784              SourceRange typeIdParens, Expr *arraySize,
   1785              InitializationStyle initializationStyle, Expr *initializer,
   1786              QualType ty, TypeSourceInfo *AllocatedTypeInfo,
   1787              SourceRange Range, SourceRange directInitRange);
   1788   explicit CXXNewExpr(EmptyShell Shell)
   1789     : Expr(CXXNewExprClass, Shell), SubExprs(nullptr) { }
   1790 
   1791   void AllocateArgsArray(const ASTContext &C, bool isArray,
   1792                          unsigned numPlaceArgs, bool hasInitializer);
   1793 
   1794   QualType getAllocatedType() const {
   1795     assert(getType()->isPointerType());
   1796     return getType()->getAs<PointerType>()->getPointeeType();
   1797   }
   1798 
   1799   TypeSourceInfo *getAllocatedTypeSourceInfo() const {
   1800     return AllocatedTypeInfo;
   1801   }
   1802 
   1803   /// \brief True if the allocation result needs to be null-checked.
   1804   ///
   1805   /// C++11 [expr.new]p13:
   1806   ///   If the allocation function returns null, initialization shall
   1807   ///   not be done, the deallocation function shall not be called,
   1808   ///   and the value of the new-expression shall be null.
   1809   ///
   1810   /// C++ DR1748:
   1811   ///   If the allocation function is a reserved placement allocation
   1812   ///   function that returns null, the behavior is undefined.
   1813   ///
   1814   /// An allocation function is not allowed to return null unless it
   1815   /// has a non-throwing exception-specification.  The '03 rule is
   1816   /// identical except that the definition of a non-throwing
   1817   /// exception specification is just "is it throw()?".
   1818   bool shouldNullCheckAllocation(const ASTContext &Ctx) const;
   1819 
   1820   FunctionDecl *getOperatorNew() const { return OperatorNew; }
   1821   void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
   1822   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
   1823   void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
   1824 
   1825   bool isArray() const { return Array; }
   1826   Expr *getArraySize() {
   1827     return Array ? cast<Expr>(SubExprs[0]) : nullptr;
   1828   }
   1829   const Expr *getArraySize() const {
   1830     return Array ? cast<Expr>(SubExprs[0]) : nullptr;
   1831   }
   1832 
   1833   unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
   1834   Expr **getPlacementArgs() {
   1835     return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
   1836   }
   1837 
   1838   Expr *getPlacementArg(unsigned i) {
   1839     assert(i < NumPlacementArgs && "Index out of range");
   1840     return getPlacementArgs()[i];
   1841   }
   1842   const Expr *getPlacementArg(unsigned i) const {
   1843     assert(i < NumPlacementArgs && "Index out of range");
   1844     return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
   1845   }
   1846 
   1847   bool isParenTypeId() const { return TypeIdParens.isValid(); }
   1848   SourceRange getTypeIdParens() const { return TypeIdParens; }
   1849 
   1850   bool isGlobalNew() const { return GlobalNew; }
   1851 
   1852   /// \brief Whether this new-expression has any initializer at all.
   1853   bool hasInitializer() const { return StoredInitializationStyle > 0; }
   1854 
   1855   /// \brief The kind of initializer this new-expression has.
   1856   InitializationStyle getInitializationStyle() const {
   1857     if (StoredInitializationStyle == 0)
   1858       return NoInit;
   1859     return static_cast<InitializationStyle>(StoredInitializationStyle-1);
   1860   }
   1861 
   1862   /// \brief The initializer of this new-expression.
   1863   Expr *getInitializer() {
   1864     return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
   1865   }
   1866   const Expr *getInitializer() const {
   1867     return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
   1868   }
   1869 
   1870   /// \brief Returns the CXXConstructExpr from this new-expression, or null.
   1871   const CXXConstructExpr* getConstructExpr() const {
   1872     return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
   1873   }
   1874 
   1875   /// Answers whether the usual array deallocation function for the
   1876   /// allocated type expects the size of the allocation as a
   1877   /// parameter.
   1878   bool doesUsualArrayDeleteWantSize() const {
   1879     return UsualArrayDeleteWantsSize;
   1880   }
   1881 
   1882   typedef ExprIterator arg_iterator;
   1883   typedef ConstExprIterator const_arg_iterator;
   1884 
   1885   llvm::iterator_range<arg_iterator> placement_arguments() {
   1886     return llvm::make_range(placement_arg_begin(), placement_arg_end());
   1887   }
   1888 
   1889   llvm::iterator_range<const_arg_iterator> placement_arguments() const {
   1890     return llvm::make_range(placement_arg_begin(), placement_arg_end());
   1891   }
   1892 
   1893   arg_iterator placement_arg_begin() {
   1894     return SubExprs + Array + hasInitializer();
   1895   }
   1896   arg_iterator placement_arg_end() {
   1897     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
   1898   }
   1899   const_arg_iterator placement_arg_begin() const {
   1900     return SubExprs + Array + hasInitializer();
   1901   }
   1902   const_arg_iterator placement_arg_end() const {
   1903     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
   1904   }
   1905 
   1906   typedef Stmt **raw_arg_iterator;
   1907   raw_arg_iterator raw_arg_begin() { return SubExprs; }
   1908   raw_arg_iterator raw_arg_end() {
   1909     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
   1910   }
   1911   const_arg_iterator raw_arg_begin() const { return SubExprs; }
   1912   const_arg_iterator raw_arg_end() const {
   1913     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
   1914   }
   1915 
   1916   SourceLocation getStartLoc() const { return Range.getBegin(); }
   1917   SourceLocation getEndLoc() const { return Range.getEnd(); }
   1918 
   1919   SourceRange getDirectInitRange() const { return DirectInitRange; }
   1920 
   1921   SourceRange getSourceRange() const LLVM_READONLY {
   1922     return Range;
   1923   }
   1924   SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
   1925   SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
   1926 
   1927   static bool classof(const Stmt *T) {
   1928     return T->getStmtClass() == CXXNewExprClass;
   1929   }
   1930 
   1931   // Iterators
   1932   child_range children() {
   1933     return child_range(raw_arg_begin(), raw_arg_end());
   1934   }
   1935 };
   1936 
   1937 /// \brief Represents a \c delete expression for memory deallocation and
   1938 /// destructor calls, e.g. "delete[] pArray".
   1939 class CXXDeleteExpr : public Expr {
   1940   /// Points to the operator delete overload that is used. Could be a member.
   1941   FunctionDecl *OperatorDelete;
   1942   /// The pointer expression to be deleted.
   1943   Stmt *Argument;
   1944   /// Location of the expression.
   1945   SourceLocation Loc;
   1946   /// Is this a forced global delete, i.e. "::delete"?
   1947   bool GlobalDelete : 1;
   1948   /// Is this the array form of delete, i.e. "delete[]"?
   1949   bool ArrayForm : 1;
   1950   /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
   1951   /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
   1952   /// will be true).
   1953   bool ArrayFormAsWritten : 1;
   1954   /// Does the usual deallocation function for the element type require
   1955   /// a size_t argument?
   1956   bool UsualArrayDeleteWantsSize : 1;
   1957 public:
   1958   CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
   1959                 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
   1960                 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
   1961     : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
   1962            arg->isInstantiationDependent(),
   1963            arg->containsUnexpandedParameterPack()),
   1964       OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
   1965       GlobalDelete(globalDelete),
   1966       ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
   1967       UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
   1968   explicit CXXDeleteExpr(EmptyShell Shell)
   1969     : Expr(CXXDeleteExprClass, Shell), OperatorDelete(nullptr),
   1970       Argument(nullptr) {}
   1971 
   1972   bool isGlobalDelete() const { return GlobalDelete; }
   1973   bool isArrayForm() const { return ArrayForm; }
   1974   bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
   1975 
   1976   /// Answers whether the usual array deallocation function for the
   1977   /// allocated type expects the size of the allocation as a
   1978   /// parameter.  This can be true even if the actual deallocation
   1979   /// function that we're using doesn't want a size.
   1980   bool doesUsualArrayDeleteWantSize() const {
   1981     return UsualArrayDeleteWantsSize;
   1982   }
   1983 
   1984   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
   1985 
   1986   Expr *getArgument() { return cast<Expr>(Argument); }
   1987   const Expr *getArgument() const { return cast<Expr>(Argument); }
   1988 
   1989   /// \brief Retrieve the type being destroyed.
   1990   ///
   1991   /// If the type being destroyed is a dependent type which may or may not
   1992   /// be a pointer, return an invalid type.
   1993   QualType getDestroyedType() const;
   1994 
   1995   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
   1996   SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
   1997 
   1998   static bool classof(const Stmt *T) {
   1999     return T->getStmtClass() == CXXDeleteExprClass;
   2000   }
   2001 
   2002   // Iterators
   2003   child_range children() { return child_range(&Argument, &Argument+1); }
   2004 
   2005   friend class ASTStmtReader;
   2006 };
   2007 
   2008 /// \brief Stores the type being destroyed by a pseudo-destructor expression.
   2009 class PseudoDestructorTypeStorage {
   2010   /// \brief Either the type source information or the name of the type, if
   2011   /// it couldn't be resolved due to type-dependence.
   2012   llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
   2013 
   2014   /// \brief The starting source location of the pseudo-destructor type.
   2015   SourceLocation Location;
   2016 
   2017 public:
   2018   PseudoDestructorTypeStorage() { }
   2019 
   2020   PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
   2021     : Type(II), Location(Loc) { }
   2022 
   2023   PseudoDestructorTypeStorage(TypeSourceInfo *Info);
   2024 
   2025   TypeSourceInfo *getTypeSourceInfo() const {
   2026     return Type.dyn_cast<TypeSourceInfo *>();
   2027   }
   2028 
   2029   IdentifierInfo *getIdentifier() const {
   2030     return Type.dyn_cast<IdentifierInfo *>();
   2031   }
   2032 
   2033   SourceLocation getLocation() const { return Location; }
   2034 };
   2035 
   2036 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
   2037 ///
   2038 /// A pseudo-destructor is an expression that looks like a member access to a
   2039 /// destructor of a scalar type, except that scalar types don't have
   2040 /// destructors. For example:
   2041 ///
   2042 /// \code
   2043 /// typedef int T;
   2044 /// void f(int *p) {
   2045 ///   p->T::~T();
   2046 /// }
   2047 /// \endcode
   2048 ///
   2049 /// Pseudo-destructors typically occur when instantiating templates such as:
   2050 ///
   2051 /// \code
   2052 /// template<typename T>
   2053 /// void destroy(T* ptr) {
   2054 ///   ptr->T::~T();
   2055 /// }
   2056 /// \endcode
   2057 ///
   2058 /// for scalar types. A pseudo-destructor expression has no run-time semantics
   2059 /// beyond evaluating the base expression.
   2060 class CXXPseudoDestructorExpr : public Expr {
   2061   /// \brief The base expression (that is being destroyed).
   2062   Stmt *Base;
   2063 
   2064   /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
   2065   /// period ('.').
   2066   bool IsArrow : 1;
   2067 
   2068   /// \brief The location of the '.' or '->' operator.
   2069   SourceLocation OperatorLoc;
   2070 
   2071   /// \brief The nested-name-specifier that follows the operator, if present.
   2072   NestedNameSpecifierLoc QualifierLoc;
   2073 
   2074   /// \brief The type that precedes the '::' in a qualified pseudo-destructor
   2075   /// expression.
   2076   TypeSourceInfo *ScopeType;
   2077 
   2078   /// \brief The location of the '::' in a qualified pseudo-destructor
   2079   /// expression.
   2080   SourceLocation ColonColonLoc;
   2081 
   2082   /// \brief The location of the '~'.
   2083   SourceLocation TildeLoc;
   2084 
   2085   /// \brief The type being destroyed, or its name if we were unable to
   2086   /// resolve the name.
   2087   PseudoDestructorTypeStorage DestroyedType;
   2088 
   2089   friend class ASTStmtReader;
   2090 
   2091 public:
   2092   CXXPseudoDestructorExpr(const ASTContext &Context,
   2093                           Expr *Base, bool isArrow, SourceLocation OperatorLoc,
   2094                           NestedNameSpecifierLoc QualifierLoc,
   2095                           TypeSourceInfo *ScopeType,
   2096                           SourceLocation ColonColonLoc,
   2097                           SourceLocation TildeLoc,
   2098                           PseudoDestructorTypeStorage DestroyedType);
   2099 
   2100   explicit CXXPseudoDestructorExpr(EmptyShell Shell)
   2101     : Expr(CXXPseudoDestructorExprClass, Shell),
   2102       Base(nullptr), IsArrow(false), QualifierLoc(), ScopeType(nullptr) { }
   2103 
   2104   Expr *getBase() const { return cast<Expr>(Base); }
   2105 
   2106   /// \brief Determines whether this member expression actually had
   2107   /// a C++ nested-name-specifier prior to the name of the member, e.g.,
   2108   /// x->Base::foo.
   2109   bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
   2110 
   2111   /// \brief Retrieves the nested-name-specifier that qualifies the type name,
   2112   /// with source-location information.
   2113   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   2114 
   2115   /// \brief If the member name was qualified, retrieves the
   2116   /// nested-name-specifier that precedes the member name. Otherwise, returns
   2117   /// null.
   2118   NestedNameSpecifier *getQualifier() const {
   2119     return QualifierLoc.getNestedNameSpecifier();
   2120   }
   2121 
   2122   /// \brief Determine whether this pseudo-destructor expression was written
   2123   /// using an '->' (otherwise, it used a '.').
   2124   bool isArrow() const { return IsArrow; }
   2125 
   2126   /// \brief Retrieve the location of the '.' or '->' operator.
   2127   SourceLocation getOperatorLoc() const { return OperatorLoc; }
   2128 
   2129   /// \brief Retrieve the scope type in a qualified pseudo-destructor
   2130   /// expression.
   2131   ///
   2132   /// Pseudo-destructor expressions can have extra qualification within them
   2133   /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
   2134   /// Here, if the object type of the expression is (or may be) a scalar type,
   2135   /// \p T may also be a scalar type and, therefore, cannot be part of a
   2136   /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
   2137   /// destructor expression.
   2138   TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
   2139 
   2140   /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
   2141   /// expression.
   2142   SourceLocation getColonColonLoc() const { return ColonColonLoc; }
   2143 
   2144   /// \brief Retrieve the location of the '~'.
   2145   SourceLocation getTildeLoc() const { return TildeLoc; }
   2146 
   2147   /// \brief Retrieve the source location information for the type
   2148   /// being destroyed.
   2149   ///
   2150   /// This type-source information is available for non-dependent
   2151   /// pseudo-destructor expressions and some dependent pseudo-destructor
   2152   /// expressions. Returns null if we only have the identifier for a
   2153   /// dependent pseudo-destructor expression.
   2154   TypeSourceInfo *getDestroyedTypeInfo() const {
   2155     return DestroyedType.getTypeSourceInfo();
   2156   }
   2157 
   2158   /// \brief In a dependent pseudo-destructor expression for which we do not
   2159   /// have full type information on the destroyed type, provides the name
   2160   /// of the destroyed type.
   2161   IdentifierInfo *getDestroyedTypeIdentifier() const {
   2162     return DestroyedType.getIdentifier();
   2163   }
   2164 
   2165   /// \brief Retrieve the type being destroyed.
   2166   QualType getDestroyedType() const;
   2167 
   2168   /// \brief Retrieve the starting location of the type being destroyed.
   2169   SourceLocation getDestroyedTypeLoc() const {
   2170     return DestroyedType.getLocation();
   2171   }
   2172 
   2173   /// \brief Set the name of destroyed type for a dependent pseudo-destructor
   2174   /// expression.
   2175   void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
   2176     DestroyedType = PseudoDestructorTypeStorage(II, Loc);
   2177   }
   2178 
   2179   /// \brief Set the destroyed type.
   2180   void setDestroyedType(TypeSourceInfo *Info) {
   2181     DestroyedType = PseudoDestructorTypeStorage(Info);
   2182   }
   2183 
   2184   SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
   2185   SourceLocation getLocEnd() const LLVM_READONLY;
   2186 
   2187   static bool classof(const Stmt *T) {
   2188     return T->getStmtClass() == CXXPseudoDestructorExprClass;
   2189   }
   2190 
   2191   // Iterators
   2192   child_range children() { return child_range(&Base, &Base + 1); }
   2193 };
   2194 
   2195 /// \brief A type trait used in the implementation of various C++11 and
   2196 /// Library TR1 trait templates.
   2197 ///
   2198 /// \code
   2199 ///   __is_pod(int) == true
   2200 ///   __is_enum(std::string) == false
   2201 ///   __is_trivially_constructible(vector<int>, int*, int*)
   2202 /// \endcode
   2203 class TypeTraitExpr : public Expr {
   2204   /// \brief The location of the type trait keyword.
   2205   SourceLocation Loc;
   2206 
   2207   /// \brief  The location of the closing parenthesis.
   2208   SourceLocation RParenLoc;
   2209 
   2210   // Note: The TypeSourceInfos for the arguments are allocated after the
   2211   // TypeTraitExpr.
   2212 
   2213   TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
   2214                 ArrayRef<TypeSourceInfo *> Args,
   2215                 SourceLocation RParenLoc,
   2216                 bool Value);
   2217 
   2218   TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
   2219 
   2220   /// \brief Retrieve the argument types.
   2221   TypeSourceInfo **getTypeSourceInfos() {
   2222     return reinterpret_cast<TypeSourceInfo **>(this+1);
   2223   }
   2224 
   2225   /// \brief Retrieve the argument types.
   2226   TypeSourceInfo * const *getTypeSourceInfos() const {
   2227     return reinterpret_cast<TypeSourceInfo * const*>(this+1);
   2228   }
   2229 
   2230 public:
   2231   /// \brief Create a new type trait expression.
   2232   static TypeTraitExpr *Create(const ASTContext &C, QualType T,
   2233                                SourceLocation Loc, TypeTrait Kind,
   2234                                ArrayRef<TypeSourceInfo *> Args,
   2235                                SourceLocation RParenLoc,
   2236                                bool Value);
   2237 
   2238   static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
   2239                                            unsigned NumArgs);
   2240 
   2241   /// \brief Determine which type trait this expression uses.
   2242   TypeTrait getTrait() const {
   2243     return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
   2244   }
   2245 
   2246   bool getValue() const {
   2247     assert(!isValueDependent());
   2248     return TypeTraitExprBits.Value;
   2249   }
   2250 
   2251   /// \brief Determine the number of arguments to this type trait.
   2252   unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
   2253 
   2254   /// \brief Retrieve the Ith argument.
   2255   TypeSourceInfo *getArg(unsigned I) const {
   2256     assert(I < getNumArgs() && "Argument out-of-range");
   2257     return getArgs()[I];
   2258   }
   2259 
   2260   /// \brief Retrieve the argument types.
   2261   ArrayRef<TypeSourceInfo *> getArgs() const {
   2262     return llvm::makeArrayRef(getTypeSourceInfos(), getNumArgs());
   2263   }
   2264 
   2265   typedef TypeSourceInfo **arg_iterator;
   2266   arg_iterator arg_begin() {
   2267     return getTypeSourceInfos();
   2268   }
   2269   arg_iterator arg_end() {
   2270     return getTypeSourceInfos() + getNumArgs();
   2271   }
   2272 
   2273   typedef TypeSourceInfo const * const *arg_const_iterator;
   2274   arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
   2275   arg_const_iterator arg_end() const {
   2276     return getTypeSourceInfos() + getNumArgs();
   2277   }
   2278 
   2279   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
   2280   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
   2281 
   2282   static bool classof(const Stmt *T) {
   2283     return T->getStmtClass() == TypeTraitExprClass;
   2284   }
   2285 
   2286   // Iterators
   2287   child_range children() {
   2288     return child_range(child_iterator(), child_iterator());
   2289   }
   2290 
   2291   friend class ASTStmtReader;
   2292   friend class ASTStmtWriter;
   2293 
   2294 };
   2295 
   2296 /// \brief An Embarcadero array type trait, as used in the implementation of
   2297 /// __array_rank and __array_extent.
   2298 ///
   2299 /// Example:
   2300 /// \code
   2301 ///   __array_rank(int[10][20]) == 2
   2302 ///   __array_extent(int, 1)    == 20
   2303 /// \endcode
   2304 class ArrayTypeTraitExpr : public Expr {
   2305   virtual void anchor();
   2306 
   2307   /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
   2308   unsigned ATT : 2;
   2309 
   2310   /// \brief The value of the type trait. Unspecified if dependent.
   2311   uint64_t Value;
   2312 
   2313   /// \brief The array dimension being queried, or -1 if not used.
   2314   Expr *Dimension;
   2315 
   2316   /// \brief The location of the type trait keyword.
   2317   SourceLocation Loc;
   2318 
   2319   /// \brief The location of the closing paren.
   2320   SourceLocation RParen;
   2321 
   2322   /// \brief The type being queried.
   2323   TypeSourceInfo *QueriedType;
   2324 
   2325 public:
   2326   ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
   2327                      TypeSourceInfo *queried, uint64_t value,
   2328                      Expr *dimension, SourceLocation rparen, QualType ty)
   2329     : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
   2330            false, queried->getType()->isDependentType(),
   2331            (queried->getType()->isInstantiationDependentType() ||
   2332             (dimension && dimension->isInstantiationDependent())),
   2333            queried->getType()->containsUnexpandedParameterPack()),
   2334       ATT(att), Value(value), Dimension(dimension),
   2335       Loc(loc), RParen(rparen), QueriedType(queried) { }
   2336 
   2337 
   2338   explicit ArrayTypeTraitExpr(EmptyShell Empty)
   2339     : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
   2340       QueriedType() { }
   2341 
   2342   virtual ~ArrayTypeTraitExpr() { }
   2343 
   2344   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
   2345   SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
   2346 
   2347   ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
   2348 
   2349   QualType getQueriedType() const { return QueriedType->getType(); }
   2350 
   2351   TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
   2352 
   2353   uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
   2354 
   2355   Expr *getDimensionExpression() const { return Dimension; }
   2356 
   2357   static bool classof(const Stmt *T) {
   2358     return T->getStmtClass() == ArrayTypeTraitExprClass;
   2359   }
   2360 
   2361   // Iterators
   2362   child_range children() {
   2363     return child_range(child_iterator(), child_iterator());
   2364   }
   2365 
   2366   friend class ASTStmtReader;
   2367 };
   2368 
   2369 /// \brief An expression trait intrinsic.
   2370 ///
   2371 /// Example:
   2372 /// \code
   2373 ///   __is_lvalue_expr(std::cout) == true
   2374 ///   __is_lvalue_expr(1) == false
   2375 /// \endcode
   2376 class ExpressionTraitExpr : public Expr {
   2377   /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned.
   2378   unsigned ET : 31;
   2379   /// \brief The value of the type trait. Unspecified if dependent.
   2380   bool Value : 1;
   2381 
   2382   /// \brief The location of the type trait keyword.
   2383   SourceLocation Loc;
   2384 
   2385   /// \brief The location of the closing paren.
   2386   SourceLocation RParen;
   2387 
   2388   /// \brief The expression being queried.
   2389   Expr* QueriedExpression;
   2390 public:
   2391   ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
   2392                      Expr *queried, bool value,
   2393                      SourceLocation rparen, QualType resultType)
   2394     : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
   2395            false, // Not type-dependent
   2396            // Value-dependent if the argument is type-dependent.
   2397            queried->isTypeDependent(),
   2398            queried->isInstantiationDependent(),
   2399            queried->containsUnexpandedParameterPack()),
   2400       ET(et), Value(value), Loc(loc), RParen(rparen),
   2401       QueriedExpression(queried) { }
   2402 
   2403   explicit ExpressionTraitExpr(EmptyShell Empty)
   2404     : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
   2405       QueriedExpression() { }
   2406 
   2407   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
   2408   SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
   2409 
   2410   ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
   2411 
   2412   Expr *getQueriedExpression() const { return QueriedExpression; }
   2413 
   2414   bool getValue() const { return Value; }
   2415 
   2416   static bool classof(const Stmt *T) {
   2417     return T->getStmtClass() == ExpressionTraitExprClass;
   2418   }
   2419 
   2420   // Iterators
   2421   child_range children() {
   2422     return child_range(child_iterator(), child_iterator());
   2423   }
   2424 
   2425   friend class ASTStmtReader;
   2426 };
   2427 
   2428 
   2429 /// \brief A reference to an overloaded function set, either an
   2430 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
   2431 class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) OverloadExpr : public Expr {
   2432   /// \brief The common name of these declarations.
   2433   DeclarationNameInfo NameInfo;
   2434 
   2435   /// \brief The nested-name-specifier that qualifies the name, if any.
   2436   NestedNameSpecifierLoc QualifierLoc;
   2437 
   2438   /// The results.  These are undesugared, which is to say, they may
   2439   /// include UsingShadowDecls.  Access is relative to the naming
   2440   /// class.
   2441   // FIXME: Allocate this data after the OverloadExpr subclass.
   2442   DeclAccessPair *Results;
   2443   unsigned NumResults;
   2444 
   2445 protected:
   2446   /// \brief Whether the name includes info for explicit template
   2447   /// keyword and arguments.
   2448   bool HasTemplateKWAndArgsInfo;
   2449 
   2450   /// \brief Return the optional template keyword and arguments info.
   2451   ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
   2452 
   2453   /// \brief Return the optional template keyword and arguments info.
   2454   const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
   2455     return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
   2456   }
   2457 
   2458   OverloadExpr(StmtClass K, const ASTContext &C,
   2459                NestedNameSpecifierLoc QualifierLoc,
   2460                SourceLocation TemplateKWLoc,
   2461                const DeclarationNameInfo &NameInfo,
   2462                const TemplateArgumentListInfo *TemplateArgs,
   2463                UnresolvedSetIterator Begin, UnresolvedSetIterator End,
   2464                bool KnownDependent,
   2465                bool KnownInstantiationDependent,
   2466                bool KnownContainsUnexpandedParameterPack);
   2467 
   2468   OverloadExpr(StmtClass K, EmptyShell Empty)
   2469     : Expr(K, Empty), QualifierLoc(), Results(nullptr), NumResults(0),
   2470       HasTemplateKWAndArgsInfo(false) { }
   2471 
   2472   void initializeResults(const ASTContext &C,
   2473                          UnresolvedSetIterator Begin,
   2474                          UnresolvedSetIterator End);
   2475 
   2476 public:
   2477   struct FindResult {
   2478     OverloadExpr *Expression;
   2479     bool IsAddressOfOperand;
   2480     bool HasFormOfMemberPointer;
   2481   };
   2482 
   2483   /// \brief Finds the overloaded expression in the given expression \p E of
   2484   /// OverloadTy.
   2485   ///
   2486   /// \return the expression (which must be there) and true if it has
   2487   /// the particular form of a member pointer expression
   2488   static FindResult find(Expr *E) {
   2489     assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
   2490 
   2491     FindResult Result;
   2492 
   2493     E = E->IgnoreParens();
   2494     if (isa<UnaryOperator>(E)) {
   2495       assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
   2496       E = cast<UnaryOperator>(E)->getSubExpr();
   2497       OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
   2498 
   2499       Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
   2500       Result.IsAddressOfOperand = true;
   2501       Result.Expression = Ovl;
   2502     } else {
   2503       Result.HasFormOfMemberPointer = false;
   2504       Result.IsAddressOfOperand = false;
   2505       Result.Expression = cast<OverloadExpr>(E);
   2506     }
   2507 
   2508     return Result;
   2509   }
   2510 
   2511   /// \brief Gets the naming class of this lookup, if any.
   2512   CXXRecordDecl *getNamingClass() const;
   2513 
   2514   typedef UnresolvedSetImpl::iterator decls_iterator;
   2515   decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
   2516   decls_iterator decls_end() const {
   2517     return UnresolvedSetIterator(Results + NumResults);
   2518   }
   2519   llvm::iterator_range<decls_iterator> decls() const {
   2520     return llvm::make_range(decls_begin(), decls_end());
   2521   }
   2522 
   2523   /// \brief Gets the number of declarations in the unresolved set.
   2524   unsigned getNumDecls() const { return NumResults; }
   2525 
   2526   /// \brief Gets the full name info.
   2527   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
   2528 
   2529   /// \brief Gets the name looked up.
   2530   DeclarationName getName() const { return NameInfo.getName(); }
   2531 
   2532   /// \brief Gets the location of the name.
   2533   SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
   2534 
   2535   /// \brief Fetches the nested-name qualifier, if one was given.
   2536   NestedNameSpecifier *getQualifier() const {
   2537     return QualifierLoc.getNestedNameSpecifier();
   2538   }
   2539 
   2540   /// \brief Fetches the nested-name qualifier with source-location
   2541   /// information, if one was given.
   2542   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   2543 
   2544   /// \brief Retrieve the location of the template keyword preceding
   2545   /// this name, if any.
   2546   SourceLocation getTemplateKeywordLoc() const {
   2547     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
   2548     return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
   2549   }
   2550 
   2551   /// \brief Retrieve the location of the left angle bracket starting the
   2552   /// explicit template argument list following the name, if any.
   2553   SourceLocation getLAngleLoc() const {
   2554     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
   2555     return getTemplateKWAndArgsInfo()->LAngleLoc;
   2556   }
   2557 
   2558   /// \brief Retrieve the location of the right angle bracket ending the
   2559   /// explicit template argument list following the name, if any.
   2560   SourceLocation getRAngleLoc() const {
   2561     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
   2562     return getTemplateKWAndArgsInfo()->RAngleLoc;
   2563   }
   2564 
   2565   /// \brief Determines whether the name was preceded by the template keyword.
   2566   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
   2567 
   2568   /// \brief Determines whether this expression had explicit template arguments.
   2569   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
   2570 
   2571   // Note that, inconsistently with the explicit-template-argument AST
   2572   // nodes, users are *forbidden* from calling these methods on objects
   2573   // without explicit template arguments.
   2574 
   2575   ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
   2576     assert(hasExplicitTemplateArgs());
   2577     return *getTemplateKWAndArgsInfo();
   2578   }
   2579 
   2580   const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
   2581     return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
   2582   }
   2583 
   2584   TemplateArgumentLoc const *getTemplateArgs() const {
   2585     return getExplicitTemplateArgs().getTemplateArgs();
   2586   }
   2587 
   2588   unsigned getNumTemplateArgs() const {
   2589     return getExplicitTemplateArgs().NumTemplateArgs;
   2590   }
   2591 
   2592   /// \brief Copies the template arguments into the given structure.
   2593   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
   2594     getExplicitTemplateArgs().copyInto(List);
   2595   }
   2596 
   2597   /// \brief Retrieves the optional explicit template arguments.
   2598   ///
   2599   /// This points to the same data as getExplicitTemplateArgs(), but
   2600   /// returns null if there are no explicit template arguments.
   2601   const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
   2602     if (!hasExplicitTemplateArgs()) return nullptr;
   2603     return &getExplicitTemplateArgs();
   2604   }
   2605 
   2606   static bool classof(const Stmt *T) {
   2607     return T->getStmtClass() == UnresolvedLookupExprClass ||
   2608            T->getStmtClass() == UnresolvedMemberExprClass;
   2609   }
   2610 
   2611   friend class ASTStmtReader;
   2612   friend class ASTStmtWriter;
   2613 };
   2614 
   2615 /// \brief A reference to a name which we were able to look up during
   2616 /// parsing but could not resolve to a specific declaration.
   2617 ///
   2618 /// This arises in several ways:
   2619 ///   * we might be waiting for argument-dependent lookup;
   2620 ///   * the name might resolve to an overloaded function;
   2621 /// and eventually:
   2622 ///   * the lookup might have included a function template.
   2623 ///
   2624 /// These never include UnresolvedUsingValueDecls, which are always class
   2625 /// members and therefore appear only in UnresolvedMemberLookupExprs.
   2626 class UnresolvedLookupExpr : public OverloadExpr {
   2627   /// True if these lookup results should be extended by
   2628   /// argument-dependent lookup if this is the operand of a function
   2629   /// call.
   2630   bool RequiresADL;
   2631 
   2632   /// True if these lookup results are overloaded.  This is pretty
   2633   /// trivially rederivable if we urgently need to kill this field.
   2634   bool Overloaded;
   2635 
   2636   /// The naming class (C++ [class.access.base]p5) of the lookup, if
   2637   /// any.  This can generally be recalculated from the context chain,
   2638   /// but that can be fairly expensive for unqualified lookups.  If we
   2639   /// want to improve memory use here, this could go in a union
   2640   /// against the qualified-lookup bits.
   2641   CXXRecordDecl *NamingClass;
   2642 
   2643   UnresolvedLookupExpr(const ASTContext &C,
   2644                        CXXRecordDecl *NamingClass,
   2645                        NestedNameSpecifierLoc QualifierLoc,
   2646                        SourceLocation TemplateKWLoc,
   2647                        const DeclarationNameInfo &NameInfo,
   2648                        bool RequiresADL, bool Overloaded,
   2649                        const TemplateArgumentListInfo *TemplateArgs,
   2650                        UnresolvedSetIterator Begin, UnresolvedSetIterator End)
   2651     : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
   2652                    NameInfo, TemplateArgs, Begin, End, false, false, false),
   2653       RequiresADL(RequiresADL),
   2654       Overloaded(Overloaded), NamingClass(NamingClass)
   2655   {}
   2656 
   2657   UnresolvedLookupExpr(EmptyShell Empty)
   2658     : OverloadExpr(UnresolvedLookupExprClass, Empty),
   2659       RequiresADL(false), Overloaded(false), NamingClass(nullptr)
   2660   {}
   2661 
   2662   friend class ASTStmtReader;
   2663 
   2664 public:
   2665   static UnresolvedLookupExpr *Create(const ASTContext &C,
   2666                                       CXXRecordDecl *NamingClass,
   2667                                       NestedNameSpecifierLoc QualifierLoc,
   2668                                       const DeclarationNameInfo &NameInfo,
   2669                                       bool ADL, bool Overloaded,
   2670                                       UnresolvedSetIterator Begin,
   2671                                       UnresolvedSetIterator End) {
   2672     return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
   2673                                        SourceLocation(), NameInfo,
   2674                                        ADL, Overloaded, nullptr, Begin, End);
   2675   }
   2676 
   2677   static UnresolvedLookupExpr *Create(const ASTContext &C,
   2678                                       CXXRecordDecl *NamingClass,
   2679                                       NestedNameSpecifierLoc QualifierLoc,
   2680                                       SourceLocation TemplateKWLoc,
   2681                                       const DeclarationNameInfo &NameInfo,
   2682                                       bool ADL,
   2683                                       const TemplateArgumentListInfo *Args,
   2684                                       UnresolvedSetIterator Begin,
   2685                                       UnresolvedSetIterator End);
   2686 
   2687   static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C,
   2688                                            bool HasTemplateKWAndArgsInfo,
   2689                                            unsigned NumTemplateArgs);
   2690 
   2691   /// True if this declaration should be extended by
   2692   /// argument-dependent lookup.
   2693   bool requiresADL() const { return RequiresADL; }
   2694 
   2695   /// True if this lookup is overloaded.
   2696   bool isOverloaded() const { return Overloaded; }
   2697 
   2698   /// Gets the 'naming class' (in the sense of C++0x
   2699   /// [class.access.base]p5) of the lookup.  This is the scope
   2700   /// that was looked in to find these results.
   2701   CXXRecordDecl *getNamingClass() const { return NamingClass; }
   2702 
   2703   SourceLocation getLocStart() const LLVM_READONLY {
   2704     if (NestedNameSpecifierLoc l = getQualifierLoc())
   2705       return l.getBeginLoc();
   2706     return getNameInfo().getLocStart();
   2707   }
   2708   SourceLocation getLocEnd() const LLVM_READONLY {
   2709     if (hasExplicitTemplateArgs())
   2710       return getRAngleLoc();
   2711     return getNameInfo().getLocEnd();
   2712   }
   2713 
   2714   child_range children() {
   2715     return child_range(child_iterator(), child_iterator());
   2716   }
   2717 
   2718   static bool classof(const Stmt *T) {
   2719     return T->getStmtClass() == UnresolvedLookupExprClass;
   2720   }
   2721 };
   2722 
   2723 /// \brief A qualified reference to a name whose declaration cannot
   2724 /// yet be resolved.
   2725 ///
   2726 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
   2727 /// it expresses a reference to a declaration such as
   2728 /// X<T>::value. The difference, however, is that an
   2729 /// DependentScopeDeclRefExpr node is used only within C++ templates when
   2730 /// the qualification (e.g., X<T>::) refers to a dependent type. In
   2731 /// this case, X<T>::value cannot resolve to a declaration because the
   2732 /// declaration will differ from one instantiation of X<T> to the
   2733 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
   2734 /// qualifier (X<T>::) and the name of the entity being referenced
   2735 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
   2736 /// declaration can be found.
   2737 class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) DependentScopeDeclRefExpr
   2738     : public Expr {
   2739   /// \brief The nested-name-specifier that qualifies this unresolved
   2740   /// declaration name.
   2741   NestedNameSpecifierLoc QualifierLoc;
   2742 
   2743   /// \brief The name of the entity we will be referencing.
   2744   DeclarationNameInfo NameInfo;
   2745 
   2746   /// \brief Whether the name includes info for explicit template
   2747   /// keyword and arguments.
   2748   bool HasTemplateKWAndArgsInfo;
   2749 
   2750   /// \brief Return the optional template keyword and arguments info.
   2751   ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
   2752     if (!HasTemplateKWAndArgsInfo) return nullptr;
   2753     return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
   2754   }
   2755   /// \brief Return the optional template keyword and arguments info.
   2756   const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
   2757     return const_cast<DependentScopeDeclRefExpr*>(this)
   2758       ->getTemplateKWAndArgsInfo();
   2759   }
   2760 
   2761   DependentScopeDeclRefExpr(QualType T,
   2762                             NestedNameSpecifierLoc QualifierLoc,
   2763                             SourceLocation TemplateKWLoc,
   2764                             const DeclarationNameInfo &NameInfo,
   2765                             const TemplateArgumentListInfo *Args);
   2766 
   2767 public:
   2768   static DependentScopeDeclRefExpr *Create(const ASTContext &C,
   2769                                            NestedNameSpecifierLoc QualifierLoc,
   2770                                            SourceLocation TemplateKWLoc,
   2771                                            const DeclarationNameInfo &NameInfo,
   2772                               const TemplateArgumentListInfo *TemplateArgs);
   2773 
   2774   static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C,
   2775                                                 bool HasTemplateKWAndArgsInfo,
   2776                                                 unsigned NumTemplateArgs);
   2777 
   2778   /// \brief Retrieve the name that this expression refers to.
   2779   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
   2780 
   2781   /// \brief Retrieve the name that this expression refers to.
   2782   DeclarationName getDeclName() const { return NameInfo.getName(); }
   2783 
   2784   /// \brief Retrieve the location of the name within the expression.
   2785   ///
   2786   /// For example, in "X<T>::value" this is the location of "value".
   2787   SourceLocation getLocation() const { return NameInfo.getLoc(); }
   2788 
   2789   /// \brief Retrieve the nested-name-specifier that qualifies the
   2790   /// name, with source location information.
   2791   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   2792 
   2793   /// \brief Retrieve the nested-name-specifier that qualifies this
   2794   /// declaration.
   2795   NestedNameSpecifier *getQualifier() const {
   2796     return QualifierLoc.getNestedNameSpecifier();
   2797   }
   2798 
   2799   /// \brief Retrieve the location of the template keyword preceding
   2800   /// this name, if any.
   2801   SourceLocation getTemplateKeywordLoc() const {
   2802     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
   2803     return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
   2804   }
   2805 
   2806   /// \brief Retrieve the location of the left angle bracket starting the
   2807   /// explicit template argument list following the name, if any.
   2808   SourceLocation getLAngleLoc() const {
   2809     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
   2810     return getTemplateKWAndArgsInfo()->LAngleLoc;
   2811   }
   2812 
   2813   /// \brief Retrieve the location of the right angle bracket ending the
   2814   /// explicit template argument list following the name, if any.
   2815   SourceLocation getRAngleLoc() const {
   2816     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
   2817     return getTemplateKWAndArgsInfo()->RAngleLoc;
   2818   }
   2819 
   2820   /// Determines whether the name was preceded by the template keyword.
   2821   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
   2822 
   2823   /// Determines whether this lookup had explicit template arguments.
   2824   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
   2825 
   2826   // Note that, inconsistently with the explicit-template-argument AST
   2827   // nodes, users are *forbidden* from calling these methods on objects
   2828   // without explicit template arguments.
   2829 
   2830   ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
   2831     assert(hasExplicitTemplateArgs());
   2832     return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
   2833   }
   2834 
   2835   /// Gets a reference to the explicit template argument list.
   2836   const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
   2837     assert(hasExplicitTemplateArgs());
   2838     return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
   2839   }
   2840 
   2841   /// \brief Retrieves the optional explicit template arguments.
   2842   ///
   2843   /// This points to the same data as getExplicitTemplateArgs(), but
   2844   /// returns null if there are no explicit template arguments.
   2845   const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
   2846     if (!hasExplicitTemplateArgs()) return nullptr;
   2847     return &getExplicitTemplateArgs();
   2848   }
   2849 
   2850   /// \brief Copies the template arguments (if present) into the given
   2851   /// structure.
   2852   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
   2853     getExplicitTemplateArgs().copyInto(List);
   2854   }
   2855 
   2856   TemplateArgumentLoc const *getTemplateArgs() const {
   2857     return getExplicitTemplateArgs().getTemplateArgs();
   2858   }
   2859 
   2860   unsigned getNumTemplateArgs() const {
   2861     return getExplicitTemplateArgs().NumTemplateArgs;
   2862   }
   2863 
   2864   /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr,
   2865   /// and differs from getLocation().getStart().
   2866   SourceLocation getLocStart() const LLVM_READONLY {
   2867     return QualifierLoc.getBeginLoc();
   2868   }
   2869   SourceLocation getLocEnd() const LLVM_READONLY {
   2870     if (hasExplicitTemplateArgs())
   2871       return getRAngleLoc();
   2872     return getLocation();
   2873   }
   2874 
   2875   static bool classof(const Stmt *T) {
   2876     return T->getStmtClass() == DependentScopeDeclRefExprClass;
   2877   }
   2878 
   2879   child_range children() {
   2880     return child_range(child_iterator(), child_iterator());
   2881   }
   2882 
   2883   friend class ASTStmtReader;
   2884   friend class ASTStmtWriter;
   2885 };
   2886 
   2887 /// Represents an expression -- generally a full-expression -- that
   2888 /// introduces cleanups to be run at the end of the sub-expression's
   2889 /// evaluation.  The most common source of expression-introduced
   2890 /// cleanups is temporary objects in C++, but several other kinds of
   2891 /// expressions can create cleanups, including basically every
   2892 /// call in ARC that returns an Objective-C pointer.
   2893 ///
   2894 /// This expression also tracks whether the sub-expression contains a
   2895 /// potentially-evaluated block literal.  The lifetime of a block
   2896 /// literal is the extent of the enclosing scope.
   2897 class ExprWithCleanups : public Expr {
   2898 public:
   2899   /// The type of objects that are kept in the cleanup.
   2900   /// It's useful to remember the set of blocks;  we could also
   2901   /// remember the set of temporaries, but there's currently
   2902   /// no need.
   2903   typedef BlockDecl *CleanupObject;
   2904 
   2905 private:
   2906   Stmt *SubExpr;
   2907 
   2908   ExprWithCleanups(EmptyShell, unsigned NumObjects);
   2909   ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
   2910 
   2911   CleanupObject *getObjectsBuffer() {
   2912     return reinterpret_cast<CleanupObject*>(this + 1);
   2913   }
   2914   const CleanupObject *getObjectsBuffer() const {
   2915     return reinterpret_cast<const CleanupObject*>(this + 1);
   2916   }
   2917   friend class ASTStmtReader;
   2918 
   2919 public:
   2920   static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
   2921                                   unsigned numObjects);
   2922 
   2923   static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
   2924                                   ArrayRef<CleanupObject> objects);
   2925 
   2926   ArrayRef<CleanupObject> getObjects() const {
   2927     return llvm::makeArrayRef(getObjectsBuffer(), getNumObjects());
   2928   }
   2929 
   2930   unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
   2931 
   2932   CleanupObject getObject(unsigned i) const {
   2933     assert(i < getNumObjects() && "Index out of range");
   2934     return getObjects()[i];
   2935   }
   2936 
   2937   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
   2938   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
   2939 
   2940   /// As with any mutator of the AST, be very careful
   2941   /// when modifying an existing AST to preserve its invariants.
   2942   void setSubExpr(Expr *E) { SubExpr = E; }
   2943 
   2944   SourceLocation getLocStart() const LLVM_READONLY {
   2945     return SubExpr->getLocStart();
   2946   }
   2947   SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
   2948 
   2949   // Implement isa/cast/dyncast/etc.
   2950   static bool classof(const Stmt *T) {
   2951     return T->getStmtClass() == ExprWithCleanupsClass;
   2952   }
   2953 
   2954   // Iterators
   2955   child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
   2956 };
   2957 
   2958 /// \brief Describes an explicit type conversion that uses functional
   2959 /// notion but could not be resolved because one or more arguments are
   2960 /// type-dependent.
   2961 ///
   2962 /// The explicit type conversions expressed by
   2963 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
   2964 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
   2965 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
   2966 /// type-dependent. For example, this would occur in a template such
   2967 /// as:
   2968 ///
   2969 /// \code
   2970 ///   template<typename T, typename A1>
   2971 ///   inline T make_a(const A1& a1) {
   2972 ///     return T(a1);
   2973 ///   }
   2974 /// \endcode
   2975 ///
   2976 /// When the returned expression is instantiated, it may resolve to a
   2977 /// constructor call, conversion function call, or some kind of type
   2978 /// conversion.
   2979 class CXXUnresolvedConstructExpr : public Expr {
   2980   /// \brief The type being constructed.
   2981   TypeSourceInfo *Type;
   2982 
   2983   /// \brief The location of the left parentheses ('(').
   2984   SourceLocation LParenLoc;
   2985 
   2986   /// \brief The location of the right parentheses (')').
   2987   SourceLocation RParenLoc;
   2988 
   2989   /// \brief The number of arguments used to construct the type.
   2990   unsigned NumArgs;
   2991 
   2992   CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
   2993                              SourceLocation LParenLoc,
   2994                              ArrayRef<Expr*> Args,
   2995                              SourceLocation RParenLoc);
   2996 
   2997   CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
   2998     : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
   2999 
   3000   friend class ASTStmtReader;
   3001 
   3002 public:
   3003   static CXXUnresolvedConstructExpr *Create(const ASTContext &C,
   3004                                             TypeSourceInfo *Type,
   3005                                             SourceLocation LParenLoc,
   3006                                             ArrayRef<Expr*> Args,
   3007                                             SourceLocation RParenLoc);
   3008 
   3009   static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C,
   3010                                                  unsigned NumArgs);
   3011 
   3012   /// \brief Retrieve the type that is being constructed, as specified
   3013   /// in the source code.
   3014   QualType getTypeAsWritten() const { return Type->getType(); }
   3015 
   3016   /// \brief Retrieve the type source information for the type being
   3017   /// constructed.
   3018   TypeSourceInfo *getTypeSourceInfo() const { return Type; }
   3019 
   3020   /// \brief Retrieve the location of the left parentheses ('(') that
   3021   /// precedes the argument list.
   3022   SourceLocation getLParenLoc() const { return LParenLoc; }
   3023   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
   3024 
   3025   /// \brief Retrieve the location of the right parentheses (')') that
   3026   /// follows the argument list.
   3027   SourceLocation getRParenLoc() const { return RParenLoc; }
   3028   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
   3029 
   3030   /// \brief Retrieve the number of arguments.
   3031   unsigned arg_size() const { return NumArgs; }
   3032 
   3033   typedef Expr** arg_iterator;
   3034   arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
   3035   arg_iterator arg_end() { return arg_begin() + NumArgs; }
   3036 
   3037   typedef const Expr* const * const_arg_iterator;
   3038   const_arg_iterator arg_begin() const {
   3039     return reinterpret_cast<const Expr* const *>(this + 1);
   3040   }
   3041   const_arg_iterator arg_end() const {
   3042     return arg_begin() + NumArgs;
   3043   }
   3044 
   3045   Expr *getArg(unsigned I) {
   3046     assert(I < NumArgs && "Argument index out-of-range");
   3047     return *(arg_begin() + I);
   3048   }
   3049 
   3050   const Expr *getArg(unsigned I) const {
   3051     assert(I < NumArgs && "Argument index out-of-range");
   3052     return *(arg_begin() + I);
   3053   }
   3054 
   3055   void setArg(unsigned I, Expr *E) {
   3056     assert(I < NumArgs && "Argument index out-of-range");
   3057     *(arg_begin() + I) = E;
   3058   }
   3059 
   3060   SourceLocation getLocStart() const LLVM_READONLY;
   3061   SourceLocation getLocEnd() const LLVM_READONLY {
   3062     if (!RParenLoc.isValid() && NumArgs > 0)
   3063       return getArg(NumArgs - 1)->getLocEnd();
   3064     return RParenLoc;
   3065   }
   3066 
   3067   static bool classof(const Stmt *T) {
   3068     return T->getStmtClass() == CXXUnresolvedConstructExprClass;
   3069   }
   3070 
   3071   // Iterators
   3072   child_range children() {
   3073     Stmt **begin = reinterpret_cast<Stmt**>(this+1);
   3074     return child_range(begin, begin + NumArgs);
   3075   }
   3076 };
   3077 
   3078 /// \brief Represents a C++ member access expression where the actual
   3079 /// member referenced could not be resolved because the base
   3080 /// expression or the member name was dependent.
   3081 ///
   3082 /// Like UnresolvedMemberExprs, these can be either implicit or
   3083 /// explicit accesses.  It is only possible to get one of these with
   3084 /// an implicit access if a qualifier is provided.
   3085 class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) CXXDependentScopeMemberExpr
   3086     : public Expr {
   3087   /// \brief The expression for the base pointer or class reference,
   3088   /// e.g., the \c x in x.f.  Can be null in implicit accesses.
   3089   Stmt *Base;
   3090 
   3091   /// \brief The type of the base expression.  Never null, even for
   3092   /// implicit accesses.
   3093   QualType BaseType;
   3094 
   3095   /// \brief Whether this member expression used the '->' operator or
   3096   /// the '.' operator.
   3097   bool IsArrow : 1;
   3098 
   3099   /// \brief Whether this member expression has info for explicit template
   3100   /// keyword and arguments.
   3101   bool HasTemplateKWAndArgsInfo : 1;
   3102 
   3103   /// \brief The location of the '->' or '.' operator.
   3104   SourceLocation OperatorLoc;
   3105 
   3106   /// \brief The nested-name-specifier that precedes the member name, if any.
   3107   NestedNameSpecifierLoc QualifierLoc;
   3108 
   3109   /// \brief In a qualified member access expression such as t->Base::f, this
   3110   /// member stores the resolves of name lookup in the context of the member
   3111   /// access expression, to be used at instantiation time.
   3112   ///
   3113   /// FIXME: This member, along with the QualifierLoc, could
   3114   /// be stuck into a structure that is optionally allocated at the end of
   3115   /// the CXXDependentScopeMemberExpr, to save space in the common case.
   3116   NamedDecl *FirstQualifierFoundInScope;
   3117 
   3118   /// \brief The member to which this member expression refers, which
   3119   /// can be name, overloaded operator, or destructor.
   3120   ///
   3121   /// FIXME: could also be a template-id
   3122   DeclarationNameInfo MemberNameInfo;
   3123 
   3124   /// \brief Return the optional template keyword and arguments info.
   3125   ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
   3126     if (!HasTemplateKWAndArgsInfo) return nullptr;
   3127     return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
   3128   }
   3129   /// \brief Return the optional template keyword and arguments info.
   3130   const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
   3131     return const_cast<CXXDependentScopeMemberExpr*>(this)
   3132       ->getTemplateKWAndArgsInfo();
   3133   }
   3134 
   3135   CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
   3136                               QualType BaseType, bool IsArrow,
   3137                               SourceLocation OperatorLoc,
   3138                               NestedNameSpecifierLoc QualifierLoc,
   3139                               SourceLocation TemplateKWLoc,
   3140                               NamedDecl *FirstQualifierFoundInScope,
   3141                               DeclarationNameInfo MemberNameInfo,
   3142                               const TemplateArgumentListInfo *TemplateArgs);
   3143 
   3144 public:
   3145   CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
   3146                               QualType BaseType, bool IsArrow,
   3147                               SourceLocation OperatorLoc,
   3148                               NestedNameSpecifierLoc QualifierLoc,
   3149                               NamedDecl *FirstQualifierFoundInScope,
   3150                               DeclarationNameInfo MemberNameInfo);
   3151 
   3152   static CXXDependentScopeMemberExpr *
   3153   Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
   3154          SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
   3155          SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
   3156          DeclarationNameInfo MemberNameInfo,
   3157          const TemplateArgumentListInfo *TemplateArgs);
   3158 
   3159   static CXXDependentScopeMemberExpr *
   3160   CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
   3161               unsigned NumTemplateArgs);
   3162 
   3163   /// \brief True if this is an implicit access, i.e. one in which the
   3164   /// member being accessed was not written in the source.  The source
   3165   /// location of the operator is invalid in this case.
   3166   bool isImplicitAccess() const;
   3167 
   3168   /// \brief Retrieve the base object of this member expressions,
   3169   /// e.g., the \c x in \c x.m.
   3170   Expr *getBase() const {
   3171     assert(!isImplicitAccess());
   3172     return cast<Expr>(Base);
   3173   }
   3174 
   3175   QualType getBaseType() const { return BaseType; }
   3176 
   3177   /// \brief Determine whether this member expression used the '->'
   3178   /// operator; otherwise, it used the '.' operator.
   3179   bool isArrow() const { return IsArrow; }
   3180 
   3181   /// \brief Retrieve the location of the '->' or '.' operator.
   3182   SourceLocation getOperatorLoc() const { return OperatorLoc; }
   3183 
   3184   /// \brief Retrieve the nested-name-specifier that qualifies the member
   3185   /// name.
   3186   NestedNameSpecifier *getQualifier() const {
   3187     return QualifierLoc.getNestedNameSpecifier();
   3188   }
   3189 
   3190   /// \brief Retrieve the nested-name-specifier that qualifies the member
   3191   /// name, with source location information.
   3192   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   3193 
   3194 
   3195   /// \brief Retrieve the first part of the nested-name-specifier that was
   3196   /// found in the scope of the member access expression when the member access
   3197   /// was initially parsed.
   3198   ///
   3199   /// This function only returns a useful result when member access expression
   3200   /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
   3201   /// returned by this function describes what was found by unqualified name
   3202   /// lookup for the identifier "Base" within the scope of the member access
   3203   /// expression itself. At template instantiation time, this information is
   3204   /// combined with the results of name lookup into the type of the object
   3205   /// expression itself (the class type of x).
   3206   NamedDecl *getFirstQualifierFoundInScope() const {
   3207     return FirstQualifierFoundInScope;
   3208   }
   3209 
   3210   /// \brief Retrieve the name of the member that this expression
   3211   /// refers to.
   3212   const DeclarationNameInfo &getMemberNameInfo() const {
   3213     return MemberNameInfo;
   3214   }
   3215 
   3216   /// \brief Retrieve the name of the member that this expression
   3217   /// refers to.
   3218   DeclarationName getMember() const { return MemberNameInfo.getName(); }
   3219 
   3220   // \brief Retrieve the location of the name of the member that this
   3221   // expression refers to.
   3222   SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
   3223 
   3224   /// \brief Retrieve the location of the template keyword preceding the
   3225   /// member name, if any.
   3226   SourceLocation getTemplateKeywordLoc() const {
   3227     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
   3228     return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
   3229   }
   3230 
   3231   /// \brief Retrieve the location of the left angle bracket starting the
   3232   /// explicit template argument list following the member name, if any.
   3233   SourceLocation getLAngleLoc() const {
   3234     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
   3235     return getTemplateKWAndArgsInfo()->LAngleLoc;
   3236   }
   3237 
   3238   /// \brief Retrieve the location of the right angle bracket ending the
   3239   /// explicit template argument list following the member name, if any.
   3240   SourceLocation getRAngleLoc() const {
   3241     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
   3242     return getTemplateKWAndArgsInfo()->RAngleLoc;
   3243   }
   3244 
   3245   /// Determines whether the member name was preceded by the template keyword.
   3246   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
   3247 
   3248   /// \brief Determines whether this member expression actually had a C++
   3249   /// template argument list explicitly specified, e.g., x.f<int>.
   3250   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
   3251 
   3252   /// \brief Retrieve the explicit template argument list that followed the
   3253   /// member template name, if any.
   3254   ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
   3255     assert(hasExplicitTemplateArgs());
   3256     return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
   3257   }
   3258 
   3259   /// \brief Retrieve the explicit template argument list that followed the
   3260   /// member template name, if any.
   3261   const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
   3262     return const_cast<CXXDependentScopeMemberExpr *>(this)
   3263              ->getExplicitTemplateArgs();
   3264   }
   3265 
   3266   /// \brief Retrieves the optional explicit template arguments.
   3267   ///
   3268   /// This points to the same data as getExplicitTemplateArgs(), but
   3269   /// returns null if there are no explicit template arguments.
   3270   const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
   3271     if (!hasExplicitTemplateArgs()) return nullptr;
   3272     return &getExplicitTemplateArgs();
   3273   }
   3274 
   3275   /// \brief Copies the template arguments (if present) into the given
   3276   /// structure.
   3277   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
   3278     getExplicitTemplateArgs().copyInto(List);
   3279   }
   3280 
   3281   /// \brief Initializes the template arguments using the given structure.
   3282   void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
   3283     getExplicitTemplateArgs().initializeFrom(List);
   3284   }
   3285 
   3286   /// \brief Retrieve the template arguments provided as part of this
   3287   /// template-id.
   3288   const TemplateArgumentLoc *getTemplateArgs() const {
   3289     return getExplicitTemplateArgs().getTemplateArgs();
   3290   }
   3291 
   3292   /// \brief Retrieve the number of template arguments provided as part of this
   3293   /// template-id.
   3294   unsigned getNumTemplateArgs() const {
   3295     return getExplicitTemplateArgs().NumTemplateArgs;
   3296   }
   3297 
   3298   SourceLocation getLocStart() const LLVM_READONLY {
   3299     if (!isImplicitAccess())
   3300       return Base->getLocStart();
   3301     if (getQualifier())
   3302       return getQualifierLoc().getBeginLoc();
   3303     return MemberNameInfo.getBeginLoc();
   3304 
   3305   }
   3306   SourceLocation getLocEnd() const LLVM_READONLY {
   3307     if (hasExplicitTemplateArgs())
   3308       return getRAngleLoc();
   3309     return MemberNameInfo.getEndLoc();
   3310   }
   3311 
   3312   static bool classof(const Stmt *T) {
   3313     return T->getStmtClass() == CXXDependentScopeMemberExprClass;
   3314   }
   3315 
   3316   // Iterators
   3317   child_range children() {
   3318     if (isImplicitAccess())
   3319       return child_range(child_iterator(), child_iterator());
   3320     return child_range(&Base, &Base + 1);
   3321   }
   3322 
   3323   friend class ASTStmtReader;
   3324   friend class ASTStmtWriter;
   3325 };
   3326 
   3327 /// \brief Represents a C++ member access expression for which lookup
   3328 /// produced a set of overloaded functions.
   3329 ///
   3330 /// The member access may be explicit or implicit:
   3331 /// \code
   3332 ///    struct A {
   3333 ///      int a, b;
   3334 ///      int explicitAccess() { return this->a + this->A::b; }
   3335 ///      int implicitAccess() { return a + A::b; }
   3336 ///    };
   3337 /// \endcode
   3338 ///
   3339 /// In the final AST, an explicit access always becomes a MemberExpr.
   3340 /// An implicit access may become either a MemberExpr or a
   3341 /// DeclRefExpr, depending on whether the member is static.
   3342 class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) UnresolvedMemberExpr
   3343     : public OverloadExpr {
   3344   /// \brief Whether this member expression used the '->' operator or
   3345   /// the '.' operator.
   3346   bool IsArrow : 1;
   3347 
   3348   /// \brief Whether the lookup results contain an unresolved using
   3349   /// declaration.
   3350   bool HasUnresolvedUsing : 1;
   3351 
   3352   /// \brief The expression for the base pointer or class reference,
   3353   /// e.g., the \c x in x.f.
   3354   ///
   3355   /// This can be null if this is an 'unbased' member expression.
   3356   Stmt *Base;
   3357 
   3358   /// \brief The type of the base expression; never null.
   3359   QualType BaseType;
   3360 
   3361   /// \brief The location of the '->' or '.' operator.
   3362   SourceLocation OperatorLoc;
   3363 
   3364   UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing,
   3365                        Expr *Base, QualType BaseType, bool IsArrow,
   3366                        SourceLocation OperatorLoc,
   3367                        NestedNameSpecifierLoc QualifierLoc,
   3368                        SourceLocation TemplateKWLoc,
   3369                        const DeclarationNameInfo &MemberNameInfo,
   3370                        const TemplateArgumentListInfo *TemplateArgs,
   3371                        UnresolvedSetIterator Begin, UnresolvedSetIterator End);
   3372 
   3373   UnresolvedMemberExpr(EmptyShell Empty)
   3374     : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
   3375       HasUnresolvedUsing(false), Base(nullptr) { }
   3376 
   3377   friend class ASTStmtReader;
   3378 
   3379 public:
   3380   static UnresolvedMemberExpr *
   3381   Create(const ASTContext &C, bool HasUnresolvedUsing,
   3382          Expr *Base, QualType BaseType, bool IsArrow,
   3383          SourceLocation OperatorLoc,
   3384          NestedNameSpecifierLoc QualifierLoc,
   3385          SourceLocation TemplateKWLoc,
   3386          const DeclarationNameInfo &MemberNameInfo,
   3387          const TemplateArgumentListInfo *TemplateArgs,
   3388          UnresolvedSetIterator Begin, UnresolvedSetIterator End);
   3389 
   3390   static UnresolvedMemberExpr *
   3391   CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
   3392               unsigned NumTemplateArgs);
   3393 
   3394   /// \brief True if this is an implicit access, i.e., one in which the
   3395   /// member being accessed was not written in the source.
   3396   ///
   3397   /// The source location of the operator is invalid in this case.
   3398   bool isImplicitAccess() const;
   3399 
   3400   /// \brief Retrieve the base object of this member expressions,
   3401   /// e.g., the \c x in \c x.m.
   3402   Expr *getBase() {
   3403     assert(!isImplicitAccess());
   3404     return cast<Expr>(Base);
   3405   }
   3406   const Expr *getBase() const {
   3407     assert(!isImplicitAccess());
   3408     return cast<Expr>(Base);
   3409   }
   3410 
   3411   QualType getBaseType() const { return BaseType; }
   3412 
   3413   /// \brief Determine whether the lookup results contain an unresolved using
   3414   /// declaration.
   3415   bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
   3416 
   3417   /// \brief Determine whether this member expression used the '->'
   3418   /// operator; otherwise, it used the '.' operator.
   3419   bool isArrow() const { return IsArrow; }
   3420 
   3421   /// \brief Retrieve the location of the '->' or '.' operator.
   3422   SourceLocation getOperatorLoc() const { return OperatorLoc; }
   3423 
   3424   /// \brief Retrieve the naming class of this lookup.
   3425   CXXRecordDecl *getNamingClass() const;
   3426 
   3427   /// \brief Retrieve the full name info for the member that this expression
   3428   /// refers to.
   3429   const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
   3430 
   3431   /// \brief Retrieve the name of the member that this expression
   3432   /// refers to.
   3433   DeclarationName getMemberName() const { return getName(); }
   3434 
   3435   // \brief Retrieve the location of the name of the member that this
   3436   // expression refers to.
   3437   SourceLocation getMemberLoc() const { return getNameLoc(); }
   3438 
   3439   // \brief Return the preferred location (the member name) for the arrow when
   3440   // diagnosing a problem with this expression.
   3441   SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
   3442 
   3443   SourceLocation getLocStart() const LLVM_READONLY {
   3444     if (!isImplicitAccess())
   3445       return Base->getLocStart();
   3446     if (NestedNameSpecifierLoc l = getQualifierLoc())
   3447       return l.getBeginLoc();
   3448     return getMemberNameInfo().getLocStart();
   3449   }
   3450   SourceLocation getLocEnd() const LLVM_READONLY {
   3451     if (hasExplicitTemplateArgs())
   3452       return getRAngleLoc();
   3453     return getMemberNameInfo().getLocEnd();
   3454   }
   3455 
   3456   static bool classof(const Stmt *T) {
   3457     return T->getStmtClass() == UnresolvedMemberExprClass;
   3458   }
   3459 
   3460   // Iterators
   3461   child_range children() {
   3462     if (isImplicitAccess())
   3463       return child_range(child_iterator(), child_iterator());
   3464     return child_range(&Base, &Base + 1);
   3465   }
   3466 };
   3467 
   3468 inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
   3469   if (!HasTemplateKWAndArgsInfo)
   3470     return nullptr;
   3471   if (isa<UnresolvedLookupExpr>(this))
   3472     return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
   3473         cast<UnresolvedLookupExpr>(this) + 1);
   3474   else
   3475     return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
   3476         cast<UnresolvedMemberExpr>(this) + 1);
   3477 }
   3478 
   3479 /// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
   3480 ///
   3481 /// The noexcept expression tests whether a given expression might throw. Its
   3482 /// result is a boolean constant.
   3483 class CXXNoexceptExpr : public Expr {
   3484   bool Value : 1;
   3485   Stmt *Operand;
   3486   SourceRange Range;
   3487 
   3488   friend class ASTStmtReader;
   3489 
   3490 public:
   3491   CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
   3492                   SourceLocation Keyword, SourceLocation RParen)
   3493     : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
   3494            /*TypeDependent*/false,
   3495            /*ValueDependent*/Val == CT_Dependent,
   3496            Val == CT_Dependent || Operand->isInstantiationDependent(),
   3497            Operand->containsUnexpandedParameterPack()),
   3498       Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
   3499   { }
   3500 
   3501   CXXNoexceptExpr(EmptyShell Empty)
   3502     : Expr(CXXNoexceptExprClass, Empty)
   3503   { }
   3504 
   3505   Expr *getOperand() const { return static_cast<Expr*>(Operand); }
   3506 
   3507   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
   3508   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
   3509   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
   3510 
   3511   bool getValue() const { return Value; }
   3512 
   3513   static bool classof(const Stmt *T) {
   3514     return T->getStmtClass() == CXXNoexceptExprClass;
   3515   }
   3516 
   3517   // Iterators
   3518   child_range children() { return child_range(&Operand, &Operand + 1); }
   3519 };
   3520 
   3521 /// \brief Represents a C++11 pack expansion that produces a sequence of
   3522 /// expressions.
   3523 ///
   3524 /// A pack expansion expression contains a pattern (which itself is an
   3525 /// expression) followed by an ellipsis. For example:
   3526 ///
   3527 /// \code
   3528 /// template<typename F, typename ...Types>
   3529 /// void forward(F f, Types &&...args) {
   3530 ///   f(static_cast<Types&&>(args)...);
   3531 /// }
   3532 /// \endcode
   3533 ///
   3534 /// Here, the argument to the function object \c f is a pack expansion whose
   3535 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
   3536 /// template is instantiated, the pack expansion will instantiate to zero or
   3537 /// or more function arguments to the function object \c f.
   3538 class PackExpansionExpr : public Expr {
   3539   SourceLocation EllipsisLoc;
   3540 
   3541   /// \brief The number of expansions that will be produced by this pack
   3542   /// expansion expression, if known.
   3543   ///
   3544   /// When zero, the number of expansions is not known. Otherwise, this value
   3545   /// is the number of expansions + 1.
   3546   unsigned NumExpansions;
   3547 
   3548   Stmt *Pattern;
   3549 
   3550   friend class ASTStmtReader;
   3551   friend class ASTStmtWriter;
   3552 
   3553 public:
   3554   PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
   3555                     Optional<unsigned> NumExpansions)
   3556     : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
   3557            Pattern->getObjectKind(), /*TypeDependent=*/true,
   3558            /*ValueDependent=*/true, /*InstantiationDependent=*/true,
   3559            /*ContainsUnexpandedParameterPack=*/false),
   3560       EllipsisLoc(EllipsisLoc),
   3561       NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
   3562       Pattern(Pattern) { }
   3563 
   3564   PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
   3565 
   3566   /// \brief Retrieve the pattern of the pack expansion.
   3567   Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
   3568 
   3569   /// \brief Retrieve the pattern of the pack expansion.
   3570   const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
   3571 
   3572   /// \brief Retrieve the location of the ellipsis that describes this pack
   3573   /// expansion.
   3574   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
   3575 
   3576   /// \brief Determine the number of expansions that will be produced when
   3577   /// this pack expansion is instantiated, if already known.
   3578   Optional<unsigned> getNumExpansions() const {
   3579     if (NumExpansions)
   3580       return NumExpansions - 1;
   3581 
   3582     return None;
   3583   }
   3584 
   3585   SourceLocation getLocStart() const LLVM_READONLY {
   3586     return Pattern->getLocStart();
   3587   }
   3588   SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; }
   3589 
   3590   static bool classof(const Stmt *T) {
   3591     return T->getStmtClass() == PackExpansionExprClass;
   3592   }
   3593 
   3594   // Iterators
   3595   child_range children() {
   3596     return child_range(&Pattern, &Pattern + 1);
   3597   }
   3598 };
   3599 
   3600 
   3601 /// \brief Represents an expression that computes the length of a parameter
   3602 /// pack.
   3603 ///
   3604 /// \code
   3605 /// template<typename ...Types>
   3606 /// struct count {
   3607 ///   static const unsigned value = sizeof...(Types);
   3608 /// };
   3609 /// \endcode
   3610 class SizeOfPackExpr : public Expr {
   3611   /// \brief The location of the \c sizeof keyword.
   3612   SourceLocation OperatorLoc;
   3613 
   3614   /// \brief The location of the name of the parameter pack.
   3615   SourceLocation PackLoc;
   3616 
   3617   /// \brief The location of the closing parenthesis.
   3618   SourceLocation RParenLoc;
   3619 
   3620   /// \brief The length of the parameter pack, if known.
   3621   ///
   3622   /// When this expression is not value-dependent, this is the length of
   3623   /// the pack. When the expression was parsed rather than instantiated
   3624   /// (and thus is value-dependent), this is zero.
   3625   ///
   3626   /// After partial substitution into a sizeof...(X) expression (for instance,
   3627   /// within an alias template or during function template argument deduction),
   3628   /// we store a trailing array of partially-substituted TemplateArguments,
   3629   /// and this is the length of that array.
   3630   unsigned Length;
   3631 
   3632   /// \brief The parameter pack.
   3633   NamedDecl *Pack;
   3634 
   3635   friend class ASTStmtReader;
   3636   friend class ASTStmtWriter;
   3637 
   3638   /// \brief Create an expression that computes the length of
   3639   /// the given parameter pack.
   3640   SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
   3641                  SourceLocation PackLoc, SourceLocation RParenLoc,
   3642                  Optional<unsigned> Length, ArrayRef<TemplateArgument> PartialArgs)
   3643       : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
   3644              /*TypeDependent=*/false, /*ValueDependent=*/!Length,
   3645              /*InstantiationDependent=*/!Length,
   3646              /*ContainsUnexpandedParameterPack=*/false),
   3647         OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
   3648         Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
   3649     assert((!Length || PartialArgs.empty()) &&
   3650            "have partial args for non-dependent sizeof... expression");
   3651     TemplateArgument *Args = reinterpret_cast<TemplateArgument *>(this + 1);
   3652     std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
   3653   }
   3654 
   3655   /// \brief Create an empty expression.
   3656   SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs)
   3657       : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs), Pack() {}
   3658 
   3659 public:
   3660   static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
   3661                                 NamedDecl *Pack, SourceLocation PackLoc,
   3662                                 SourceLocation RParenLoc,
   3663                                 Optional<unsigned> Length = None,
   3664                                 ArrayRef<TemplateArgument> PartialArgs = None);
   3665   static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
   3666                                             unsigned NumPartialArgs);
   3667 
   3668   /// \brief Determine the location of the 'sizeof' keyword.
   3669   SourceLocation getOperatorLoc() const { return OperatorLoc; }
   3670 
   3671   /// \brief Determine the location of the parameter pack.
   3672   SourceLocation getPackLoc() const { return PackLoc; }
   3673 
   3674   /// \brief Determine the location of the right parenthesis.
   3675   SourceLocation getRParenLoc() const { return RParenLoc; }
   3676 
   3677   /// \brief Retrieve the parameter pack.
   3678   NamedDecl *getPack() const { return Pack; }
   3679 
   3680   /// \brief Retrieve the length of the parameter pack.
   3681   ///
   3682   /// This routine may only be invoked when the expression is not
   3683   /// value-dependent.
   3684   unsigned getPackLength() const {
   3685     assert(!isValueDependent() &&
   3686            "Cannot get the length of a value-dependent pack size expression");
   3687     return Length;
   3688   }
   3689 
   3690   /// \brief Determine whether this represents a partially-substituted sizeof...
   3691   /// expression, such as is produced for:
   3692   ///
   3693   ///   template<typename ...Ts> using X = int[sizeof...(Ts)];
   3694   ///   template<typename ...Us> void f(X<Us..., 1, 2, 3, Us...>);
   3695   bool isPartiallySubstituted() const {
   3696     return isValueDependent() && Length;
   3697   }
   3698 
   3699   /// \brief Get
   3700   ArrayRef<TemplateArgument> getPartialArguments() const {
   3701     assert(isPartiallySubstituted());
   3702     const TemplateArgument *Args =
   3703         reinterpret_cast<const TemplateArgument *>(this + 1);
   3704     return llvm::makeArrayRef(Args, Args + Length);
   3705   }
   3706 
   3707   SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
   3708   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
   3709 
   3710   static bool classof(const Stmt *T) {
   3711     return T->getStmtClass() == SizeOfPackExprClass;
   3712   }
   3713 
   3714   // Iterators
   3715   child_range children() {
   3716     return child_range(child_iterator(), child_iterator());
   3717   }
   3718 };
   3719 
   3720 /// \brief Represents a reference to a non-type template parameter
   3721 /// that has been substituted with a template argument.
   3722 class SubstNonTypeTemplateParmExpr : public Expr {
   3723   /// \brief The replaced parameter.
   3724   NonTypeTemplateParmDecl *Param;
   3725 
   3726   /// \brief The replacement expression.
   3727   Stmt *Replacement;
   3728 
   3729   /// \brief The location of the non-type template parameter reference.
   3730   SourceLocation NameLoc;
   3731 
   3732   friend class ASTReader;
   3733   friend class ASTStmtReader;
   3734   explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
   3735     : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
   3736 
   3737 public:
   3738   SubstNonTypeTemplateParmExpr(QualType type,
   3739                                ExprValueKind valueKind,
   3740                                SourceLocation loc,
   3741                                NonTypeTemplateParmDecl *param,
   3742                                Expr *replacement)
   3743     : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
   3744            replacement->isTypeDependent(), replacement->isValueDependent(),
   3745            replacement->isInstantiationDependent(),
   3746            replacement->containsUnexpandedParameterPack()),
   3747       Param(param), Replacement(replacement), NameLoc(loc) {}
   3748 
   3749   SourceLocation getNameLoc() const { return NameLoc; }
   3750   SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
   3751   SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
   3752 
   3753   Expr *getReplacement() const { return cast<Expr>(Replacement); }
   3754 
   3755   NonTypeTemplateParmDecl *getParameter() const { return Param; }
   3756 
   3757   static bool classof(const Stmt *s) {
   3758     return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
   3759   }
   3760 
   3761   // Iterators
   3762   child_range children() { return child_range(&Replacement, &Replacement+1); }
   3763 };
   3764 
   3765 /// \brief Represents a reference to a non-type template parameter pack that
   3766 /// has been substituted with a non-template argument pack.
   3767 ///
   3768 /// When a pack expansion in the source code contains multiple parameter packs
   3769 /// and those parameter packs correspond to different levels of template
   3770 /// parameter lists, this node is used to represent a non-type template
   3771 /// parameter pack from an outer level, which has already had its argument pack
   3772 /// substituted but that still lives within a pack expansion that itself
   3773 /// could not be instantiated. When actually performing a substitution into
   3774 /// that pack expansion (e.g., when all template parameters have corresponding
   3775 /// arguments), this type will be replaced with the appropriate underlying
   3776 /// expression at the current pack substitution index.
   3777 class SubstNonTypeTemplateParmPackExpr : public Expr {
   3778   /// \brief The non-type template parameter pack itself.
   3779   NonTypeTemplateParmDecl *Param;
   3780 
   3781   /// \brief A pointer to the set of template arguments that this
   3782   /// parameter pack is instantiated with.
   3783   const TemplateArgument *Arguments;
   3784 
   3785   /// \brief The number of template arguments in \c Arguments.
   3786   unsigned NumArguments;
   3787 
   3788   /// \brief The location of the non-type template parameter pack reference.
   3789   SourceLocation NameLoc;
   3790 
   3791   friend class ASTReader;
   3792   friend class ASTStmtReader;
   3793   explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
   3794     : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
   3795 
   3796 public:
   3797   SubstNonTypeTemplateParmPackExpr(QualType T,
   3798                                    NonTypeTemplateParmDecl *Param,
   3799                                    SourceLocation NameLoc,
   3800                                    const TemplateArgument &ArgPack);
   3801 
   3802   /// \brief Retrieve the non-type template parameter pack being substituted.
   3803   NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
   3804 
   3805   /// \brief Retrieve the location of the parameter pack name.
   3806   SourceLocation getParameterPackLocation() const { return NameLoc; }
   3807 
   3808   /// \brief Retrieve the template argument pack containing the substituted
   3809   /// template arguments.
   3810   TemplateArgument getArgumentPack() const;
   3811 
   3812   SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
   3813   SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
   3814 
   3815   static bool classof(const Stmt *T) {
   3816     return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
   3817   }
   3818 
   3819   // Iterators
   3820   child_range children() {
   3821     return child_range(child_iterator(), child_iterator());
   3822   }
   3823 };
   3824 
   3825 /// \brief Represents a reference to a function parameter pack that has been
   3826 /// substituted but not yet expanded.
   3827 ///
   3828 /// When a pack expansion contains multiple parameter packs at different levels,
   3829 /// this node is used to represent a function parameter pack at an outer level
   3830 /// which we have already substituted to refer to expanded parameters, but where
   3831 /// the containing pack expansion cannot yet be expanded.
   3832 ///
   3833 /// \code
   3834 /// template<typename...Ts> struct S {
   3835 ///   template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
   3836 /// };
   3837 /// template struct S<int, int>;
   3838 /// \endcode
   3839 class FunctionParmPackExpr : public Expr {
   3840   /// \brief The function parameter pack which was referenced.
   3841   ParmVarDecl *ParamPack;
   3842 
   3843   /// \brief The location of the function parameter pack reference.
   3844   SourceLocation NameLoc;
   3845 
   3846   /// \brief The number of expansions of this pack.
   3847   unsigned NumParameters;
   3848 
   3849   FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
   3850                        SourceLocation NameLoc, unsigned NumParams,
   3851                        ParmVarDecl *const *Params);
   3852 
   3853   friend class ASTReader;
   3854   friend class ASTStmtReader;
   3855 
   3856 public:
   3857   static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
   3858                                       ParmVarDecl *ParamPack,
   3859                                       SourceLocation NameLoc,
   3860                                       ArrayRef<ParmVarDecl *> Params);
   3861   static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
   3862                                            unsigned NumParams);
   3863 
   3864   /// \brief Get the parameter pack which this expression refers to.
   3865   ParmVarDecl *getParameterPack() const { return ParamPack; }
   3866 
   3867   /// \brief Get the location of the parameter pack.
   3868   SourceLocation getParameterPackLocation() const { return NameLoc; }
   3869 
   3870   /// \brief Iterators over the parameters which the parameter pack expanded
   3871   /// into.
   3872   typedef ParmVarDecl * const *iterator;
   3873   iterator begin() const { return reinterpret_cast<iterator>(this+1); }
   3874   iterator end() const { return begin() + NumParameters; }
   3875 
   3876   /// \brief Get the number of parameters in this parameter pack.
   3877   unsigned getNumExpansions() const { return NumParameters; }
   3878 
   3879   /// \brief Get an expansion of the parameter pack by index.
   3880   ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
   3881 
   3882   SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
   3883   SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
   3884 
   3885   static bool classof(const Stmt *T) {
   3886     return T->getStmtClass() == FunctionParmPackExprClass;
   3887   }
   3888 
   3889   child_range children() {
   3890     return child_range(child_iterator(), child_iterator());
   3891   }
   3892 };
   3893 
   3894 /// \brief Represents a prvalue temporary that is written into memory so that
   3895 /// a reference can bind to it.
   3896 ///
   3897 /// Prvalue expressions are materialized when they need to have an address
   3898 /// in memory for a reference to bind to. This happens when binding a
   3899 /// reference to the result of a conversion, e.g.,
   3900 ///
   3901 /// \code
   3902 /// const int &r = 1.0;
   3903 /// \endcode
   3904 ///
   3905 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
   3906 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
   3907 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
   3908 /// (either an lvalue or an xvalue, depending on the kind of reference binding
   3909 /// to it), maintaining the invariant that references always bind to glvalues.
   3910 ///
   3911 /// Reference binding and copy-elision can both extend the lifetime of a
   3912 /// temporary. When either happens, the expression will also track the
   3913 /// declaration which is responsible for the lifetime extension.
   3914 class MaterializeTemporaryExpr : public Expr {
   3915 private:
   3916   struct ExtraState {
   3917     /// \brief The temporary-generating expression whose value will be
   3918     /// materialized.
   3919     Stmt *Temporary;
   3920 
   3921     /// \brief The declaration which lifetime-extended this reference, if any.
   3922     /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
   3923     const ValueDecl *ExtendingDecl;
   3924 
   3925     unsigned ManglingNumber;
   3926   };
   3927   llvm::PointerUnion<Stmt *, ExtraState *> State;
   3928 
   3929   friend class ASTStmtReader;
   3930   friend class ASTStmtWriter;
   3931 
   3932   void initializeExtraState(const ValueDecl *ExtendedBy,
   3933                             unsigned ManglingNumber);
   3934 
   3935 public:
   3936   MaterializeTemporaryExpr(QualType T, Expr *Temporary,
   3937                            bool BoundToLvalueReference)
   3938     : Expr(MaterializeTemporaryExprClass, T,
   3939            BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
   3940            Temporary->isTypeDependent(), Temporary->isValueDependent(),
   3941            Temporary->isInstantiationDependent(),
   3942            Temporary->containsUnexpandedParameterPack()),
   3943         State(Temporary) {}
   3944 
   3945   MaterializeTemporaryExpr(EmptyShell Empty)
   3946     : Expr(MaterializeTemporaryExprClass, Empty) { }
   3947 
   3948   Stmt *getTemporary() const {
   3949     return State.is<Stmt *>() ? State.get<Stmt *>()
   3950                               : State.get<ExtraState *>()->Temporary;
   3951   }
   3952 
   3953   /// \brief Retrieve the temporary-generating subexpression whose value will
   3954   /// be materialized into a glvalue.
   3955   Expr *GetTemporaryExpr() const { return static_cast<Expr *>(getTemporary()); }
   3956 
   3957   /// \brief Retrieve the storage duration for the materialized temporary.
   3958   StorageDuration getStorageDuration() const {
   3959     const ValueDecl *ExtendingDecl = getExtendingDecl();
   3960     if (!ExtendingDecl)
   3961       return SD_FullExpression;
   3962     // FIXME: This is not necessarily correct for a temporary materialized
   3963     // within a default initializer.
   3964     if (isa<FieldDecl>(ExtendingDecl))
   3965       return SD_Automatic;
   3966     return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
   3967   }
   3968 
   3969   /// \brief Get the declaration which triggered the lifetime-extension of this
   3970   /// temporary, if any.
   3971   const ValueDecl *getExtendingDecl() const {
   3972     return State.is<Stmt *>() ? nullptr
   3973                               : State.get<ExtraState *>()->ExtendingDecl;
   3974   }
   3975 
   3976   void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber);
   3977 
   3978   unsigned getManglingNumber() const {
   3979     return State.is<Stmt *>() ? 0 : State.get<ExtraState *>()->ManglingNumber;
   3980   }
   3981 
   3982   /// \brief Determine whether this materialized temporary is bound to an
   3983   /// lvalue reference; otherwise, it's bound to an rvalue reference.
   3984   bool isBoundToLvalueReference() const {
   3985     return getValueKind() == VK_LValue;
   3986   }
   3987 
   3988   SourceLocation getLocStart() const LLVM_READONLY {
   3989     return getTemporary()->getLocStart();
   3990   }
   3991   SourceLocation getLocEnd() const LLVM_READONLY {
   3992     return getTemporary()->getLocEnd();
   3993   }
   3994 
   3995   static bool classof(const Stmt *T) {
   3996     return T->getStmtClass() == MaterializeTemporaryExprClass;
   3997   }
   3998 
   3999   // Iterators
   4000   child_range children() {
   4001     if (State.is<Stmt *>())
   4002       return child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1);
   4003 
   4004     auto ES = State.get<ExtraState *>();
   4005     return child_range(&ES->Temporary, &ES->Temporary + 1);
   4006   }
   4007 };
   4008 
   4009 /// \brief Represents a folding of a pack over an operator.
   4010 ///
   4011 /// This expression is always dependent and represents a pack expansion of the
   4012 /// forms:
   4013 ///
   4014 ///    ( expr op ... )
   4015 ///    ( ... op expr )
   4016 ///    ( expr op ... op expr )
   4017 class CXXFoldExpr : public Expr {
   4018   SourceLocation LParenLoc;
   4019   SourceLocation EllipsisLoc;
   4020   SourceLocation RParenLoc;
   4021   Stmt *SubExprs[2];
   4022   BinaryOperatorKind Opcode;
   4023 
   4024   friend class ASTStmtReader;
   4025   friend class ASTStmtWriter;
   4026 public:
   4027   CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS,
   4028               BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS,
   4029               SourceLocation RParenLoc)
   4030       : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary,
   4031              /*Dependent*/ true, true, true,
   4032              /*ContainsUnexpandedParameterPack*/ false),
   4033         LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
   4034         Opcode(Opcode) {
   4035     SubExprs[0] = LHS;
   4036     SubExprs[1] = RHS;
   4037   }
   4038   CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
   4039 
   4040   Expr *getLHS() const { return static_cast<Expr*>(SubExprs[0]); }
   4041   Expr *getRHS() const { return static_cast<Expr*>(SubExprs[1]); }
   4042 
   4043   /// Does this produce a right-associated sequence of operators?
   4044   bool isRightFold() const {
   4045     return getLHS() && getLHS()->containsUnexpandedParameterPack();
   4046   }
   4047   /// Does this produce a left-associated sequence of operators?
   4048   bool isLeftFold() const { return !isRightFold(); }
   4049   /// Get the pattern, that is, the operand that contains an unexpanded pack.
   4050   Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
   4051   /// Get the operand that doesn't contain a pack, for a binary fold.
   4052   Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
   4053 
   4054   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
   4055   BinaryOperatorKind getOperator() const { return Opcode; }
   4056 
   4057   SourceLocation getLocStart() const LLVM_READONLY {
   4058     return LParenLoc;
   4059   }
   4060   SourceLocation getLocEnd() const LLVM_READONLY {
   4061     return RParenLoc;
   4062   }
   4063 
   4064   static bool classof(const Stmt *T) {
   4065     return T->getStmtClass() == CXXFoldExprClass;
   4066   }
   4067 
   4068   // Iterators
   4069   child_range children() { return child_range(SubExprs, SubExprs + 2); }
   4070 };
   4071 
   4072 /// \brief Represents an expression that might suspend coroutine execution;
   4073 /// either a co_await or co_yield expression.
   4074 ///
   4075 /// Evaluation of this expression first evaluates its 'ready' expression. If
   4076 /// that returns 'false':
   4077 ///  -- execution of the coroutine is suspended
   4078 ///  -- the 'suspend' expression is evaluated
   4079 ///     -- if the 'suspend' expression returns 'false', the coroutine is
   4080 ///        resumed
   4081 ///     -- otherwise, control passes back to the resumer.
   4082 /// If the coroutine is not suspended, or when it is resumed, the 'resume'
   4083 /// expression is evaluated, and its result is the result of the overall
   4084 /// expression.
   4085 class CoroutineSuspendExpr : public Expr {
   4086   SourceLocation KeywordLoc;
   4087 
   4088   enum SubExpr { Common, Ready, Suspend, Resume, Count };
   4089   Stmt *SubExprs[SubExpr::Count];
   4090 
   4091   friend class ASTStmtReader;
   4092 public:
   4093   CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Common,
   4094                        Expr *Ready, Expr *Suspend, Expr *Resume)
   4095       : Expr(SC, Resume->getType(), Resume->getValueKind(),
   4096              Resume->getObjectKind(), Resume->isTypeDependent(),
   4097              Resume->isValueDependent(), Common->isInstantiationDependent(),
   4098              Common->containsUnexpandedParameterPack()),
   4099         KeywordLoc(KeywordLoc) {
   4100     SubExprs[SubExpr::Common] = Common;
   4101     SubExprs[SubExpr::Ready] = Ready;
   4102     SubExprs[SubExpr::Suspend] = Suspend;
   4103     SubExprs[SubExpr::Resume] = Resume;
   4104   }
   4105   CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty,
   4106                        Expr *Common)
   4107       : Expr(SC, Ty, VK_RValue, OK_Ordinary, true, true, true,
   4108              Common->containsUnexpandedParameterPack()),
   4109         KeywordLoc(KeywordLoc) {
   4110     assert(Common->isTypeDependent() && Ty->isDependentType() &&
   4111            "wrong constructor for non-dependent co_await/co_yield expression");
   4112     SubExprs[SubExpr::Common] = Common;
   4113     SubExprs[SubExpr::Ready] = nullptr;
   4114     SubExprs[SubExpr::Suspend] = nullptr;
   4115     SubExprs[SubExpr::Resume] = nullptr;
   4116   }
   4117   CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
   4118     SubExprs[SubExpr::Common] = nullptr;
   4119     SubExprs[SubExpr::Ready] = nullptr;
   4120     SubExprs[SubExpr::Suspend] = nullptr;
   4121     SubExprs[SubExpr::Resume] = nullptr;
   4122   }
   4123 
   4124   SourceLocation getKeywordLoc() const { return KeywordLoc; }
   4125   Expr *getCommonExpr() const {
   4126     return static_cast<Expr*>(SubExprs[SubExpr::Common]);
   4127   }
   4128 
   4129   Expr *getReadyExpr() const {
   4130     return static_cast<Expr*>(SubExprs[SubExpr::Ready]);
   4131   }
   4132   Expr *getSuspendExpr() const {
   4133     return static_cast<Expr*>(SubExprs[SubExpr::Suspend]);
   4134   }
   4135   Expr *getResumeExpr() const {
   4136     return static_cast<Expr*>(SubExprs[SubExpr::Resume]);
   4137   }
   4138 
   4139   SourceLocation getLocStart() const LLVM_READONLY {
   4140     return KeywordLoc;
   4141   }
   4142   SourceLocation getLocEnd() const LLVM_READONLY {
   4143     return getCommonExpr()->getLocEnd();
   4144   }
   4145 
   4146   child_range children() {
   4147     return child_range(SubExprs, SubExprs + SubExpr::Count);
   4148   }
   4149 
   4150   static bool classof(const Stmt *T) {
   4151     return T->getStmtClass() == CoawaitExprClass ||
   4152            T->getStmtClass() == CoyieldExprClass;
   4153   }
   4154 };
   4155 
   4156 /// \brief Represents a 'co_await' expression.
   4157 class CoawaitExpr : public CoroutineSuspendExpr {
   4158   friend class ASTStmtReader;
   4159 public:
   4160   CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Ready,
   4161               Expr *Suspend, Expr *Resume)
   4162       : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Ready,
   4163                              Suspend, Resume) {}
   4164   CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand)
   4165       : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand) {}
   4166   CoawaitExpr(EmptyShell Empty)
   4167       : CoroutineSuspendExpr(CoawaitExprClass, Empty) {}
   4168 
   4169   Expr *getOperand() const {
   4170     // FIXME: Dig out the actual operand or store it.
   4171     return getCommonExpr();
   4172   }
   4173 
   4174   static bool classof(const Stmt *T) {
   4175     return T->getStmtClass() == CoawaitExprClass;
   4176   }
   4177 };
   4178 
   4179 /// \brief Represents a 'co_yield' expression.
   4180 class CoyieldExpr : public CoroutineSuspendExpr {
   4181   friend class ASTStmtReader;
   4182 public:
   4183   CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Ready,
   4184               Expr *Suspend, Expr *Resume)
   4185       : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Ready,
   4186                              Suspend, Resume) {}
   4187   CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand)
   4188       : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand) {}
   4189   CoyieldExpr(EmptyShell Empty)
   4190       : CoroutineSuspendExpr(CoyieldExprClass, Empty) {}
   4191 
   4192   Expr *getOperand() const {
   4193     // FIXME: Dig out the actual operand or store it.
   4194     return getCommonExpr();
   4195   }
   4196 
   4197   static bool classof(const Stmt *T) {
   4198     return T->getStmtClass() == CoyieldExprClass;
   4199   }
   4200 };
   4201 
   4202 }  // end namespace clang
   4203 
   4204 #endif
   4205