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