clang API Documentation

ExprCXX.h
Go to the documentation of this file.
00001 //===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 ///
00010 /// \file
00011 /// \brief Defines the clang::Expr interface and subclasses for C++ expressions.
00012 ///
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_AST_EXPRCXX_H
00016 #define LLVM_CLANG_AST_EXPRCXX_H
00017 
00018 #include "clang/AST/Decl.h"
00019 #include "clang/AST/Expr.h"
00020 #include "clang/AST/TemplateBase.h"
00021 #include "clang/AST/UnresolvedSet.h"
00022 #include "clang/Basic/ExpressionTraits.h"
00023 #include "clang/AST/LambdaCapture.h"
00024 #include "clang/Basic/TypeTraits.h"
00025 #include "llvm/Support/Compiler.h"
00026 
00027 namespace clang {
00028 
00029 class CXXConstructorDecl;
00030 class CXXDestructorDecl;
00031 class CXXMethodDecl;
00032 class CXXTemporary;
00033 class MSPropertyDecl;
00034 class TemplateArgumentListInfo;
00035 class UuidAttr;
00036 
00037 //===--------------------------------------------------------------------===//
00038 // C++ Expressions.
00039 //===--------------------------------------------------------------------===//
00040 
00041 /// \brief A call to an overloaded operator written using operator
00042 /// syntax.
00043 ///
00044 /// Represents a call to an overloaded operator written using operator
00045 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
00046 /// normal call, this AST node provides better information about the
00047 /// syntactic representation of the call.
00048 ///
00049 /// In a C++ template, this expression node kind will be used whenever
00050 /// any of the arguments are type-dependent. In this case, the
00051 /// function itself will be a (possibly empty) set of functions and
00052 /// function templates that were found by name lookup at template
00053 /// definition time.
00054 class CXXOperatorCallExpr : public CallExpr {
00055   /// \brief The overloaded operator.
00056   OverloadedOperatorKind Operator;
00057   SourceRange Range;
00058 
00059   // Record the FP_CONTRACT state that applies to this operator call. Only
00060   // meaningful for floating point types. For other types this value can be
00061   // set to false.
00062   unsigned FPContractable : 1;
00063 
00064   SourceRange getSourceRangeImpl() const LLVM_READONLY;
00065 public:
00066   CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
00067                       ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
00068                       SourceLocation operatorloc, bool fpContractable)
00069     : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK,
00070                operatorloc),
00071       Operator(Op), FPContractable(fpContractable) {
00072     Range = getSourceRangeImpl();
00073   }
00074   explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
00075     CallExpr(C, CXXOperatorCallExprClass, Empty) { }
00076 
00077 
00078   /// \brief Returns the kind of overloaded operator that this
00079   /// expression refers to.
00080   OverloadedOperatorKind getOperator() const { return Operator; }
00081 
00082   /// \brief Returns the location of the operator symbol in the expression.
00083   ///
00084   /// When \c getOperator()==OO_Call, this is the location of the right
00085   /// parentheses; when \c getOperator()==OO_Subscript, this is the location
00086   /// of the right bracket.
00087   SourceLocation getOperatorLoc() const { return getRParenLoc(); }
00088 
00089   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
00090   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
00091   SourceRange getSourceRange() const { return Range; }
00092 
00093   static bool classof(const Stmt *T) {
00094     return T->getStmtClass() == CXXOperatorCallExprClass;
00095   }
00096 
00097   // Set the FP contractability status of this operator. Only meaningful for
00098   // operations on floating point types.
00099   void setFPContractable(bool FPC) { FPContractable = FPC; }
00100 
00101   // Get the FP contractability status of this operator. Only meaningful for
00102   // operations on floating point types.
00103   bool isFPContractable() const { return FPContractable; }
00104 
00105   friend class ASTStmtReader;
00106   friend class ASTStmtWriter;
00107 };
00108 
00109 /// Represents a call to a member function that
00110 /// may be written either with member call syntax (e.g., "obj.func()"
00111 /// or "objptr->func()") or with normal function-call syntax
00112 /// ("func()") within a member function that ends up calling a member
00113 /// function. The callee in either case is a MemberExpr that contains
00114 /// both the object argument and the member function, while the
00115 /// arguments are the arguments within the parentheses (not including
00116 /// the object argument).
00117 class CXXMemberCallExpr : public CallExpr {
00118 public:
00119   CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
00120                     QualType t, ExprValueKind VK, SourceLocation RP)
00121     : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {}
00122 
00123   CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
00124     : CallExpr(C, CXXMemberCallExprClass, Empty) { }
00125 
00126   /// \brief Retrieves the implicit object argument for the member call.
00127   ///
00128   /// For example, in "x.f(5)", this returns the sub-expression "x".
00129   Expr *getImplicitObjectArgument() const;
00130 
00131   /// \brief Retrieves the declaration of the called method.
00132   CXXMethodDecl *getMethodDecl() const;
00133 
00134   /// \brief Retrieves the CXXRecordDecl for the underlying type of
00135   /// the implicit object argument.
00136   ///
00137   /// Note that this is may not be the same declaration as that of the class
00138   /// context of the CXXMethodDecl which this function is calling.
00139   /// FIXME: Returns 0 for member pointer call exprs.
00140   CXXRecordDecl *getRecordDecl() const;
00141 
00142   static bool classof(const Stmt *T) {
00143     return T->getStmtClass() == CXXMemberCallExprClass;
00144   }
00145 };
00146 
00147 /// \brief Represents a call to a CUDA kernel function.
00148 class CUDAKernelCallExpr : public CallExpr {
00149 private:
00150   enum { CONFIG, END_PREARG };
00151 
00152 public:
00153   CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
00154                      ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
00155                      SourceLocation RP)
00156     : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) {
00157     setConfig(Config);
00158   }
00159 
00160   CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
00161     : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
00162 
00163   const CallExpr *getConfig() const {
00164     return cast_or_null<CallExpr>(getPreArg(CONFIG));
00165   }
00166   CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
00167   void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
00168 
00169   static bool classof(const Stmt *T) {
00170     return T->getStmtClass() == CUDAKernelCallExprClass;
00171   }
00172 };
00173 
00174 /// \brief Abstract class common to all of the C++ "named"/"keyword" casts.
00175 ///
00176 /// This abstract class is inherited by all of the classes
00177 /// representing "named" casts: CXXStaticCastExpr for \c static_cast,
00178 /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
00179 /// reinterpret_cast, and CXXConstCastExpr for \c const_cast.
00180 class CXXNamedCastExpr : public ExplicitCastExpr {
00181 private:
00182   SourceLocation Loc; // the location of the casting op
00183   SourceLocation RParenLoc; // the location of the right parenthesis
00184   SourceRange AngleBrackets; // range for '<' '>'
00185 
00186 protected:
00187   CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
00188                    CastKind kind, Expr *op, unsigned PathSize,
00189                    TypeSourceInfo *writtenTy, SourceLocation l,
00190                    SourceLocation RParenLoc,
00191                    SourceRange AngleBrackets)
00192     : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
00193       RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
00194 
00195   explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
00196     : ExplicitCastExpr(SC, Shell, PathSize) { }
00197 
00198   friend class ASTStmtReader;
00199 
00200 public:
00201   const char *getCastName() const;
00202 
00203   /// \brief Retrieve the location of the cast operator keyword, e.g.,
00204   /// \c static_cast.
00205   SourceLocation getOperatorLoc() const { return Loc; }
00206 
00207   /// \brief Retrieve the location of the closing parenthesis.
00208   SourceLocation getRParenLoc() const { return RParenLoc; }
00209 
00210   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
00211   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
00212   SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
00213 
00214   static bool classof(const Stmt *T) {
00215     switch (T->getStmtClass()) {
00216     case CXXStaticCastExprClass:
00217     case CXXDynamicCastExprClass:
00218     case CXXReinterpretCastExprClass:
00219     case CXXConstCastExprClass:
00220       return true;
00221     default:
00222       return false;
00223     }
00224   }
00225 };
00226 
00227 /// \brief A C++ \c static_cast expression (C++ [expr.static.cast]).
00228 ///
00229 /// This expression node represents a C++ static cast, e.g.,
00230 /// \c static_cast<int>(1.0).
00231 class CXXStaticCastExpr : public CXXNamedCastExpr {
00232   CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
00233                     unsigned pathSize, TypeSourceInfo *writtenTy,
00234                     SourceLocation l, SourceLocation RParenLoc,
00235                     SourceRange AngleBrackets)
00236     : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
00237                        writtenTy, l, RParenLoc, AngleBrackets) {}
00238 
00239   explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
00240     : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
00241 
00242 public:
00243   static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T,
00244                                    ExprValueKind VK, CastKind K, Expr *Op,
00245                                    const CXXCastPath *Path,
00246                                    TypeSourceInfo *Written, SourceLocation L,
00247                                    SourceLocation RParenLoc,
00248                                    SourceRange AngleBrackets);
00249   static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
00250                                         unsigned PathSize);
00251 
00252   static bool classof(const Stmt *T) {
00253     return T->getStmtClass() == CXXStaticCastExprClass;
00254   }
00255 };
00256 
00257 /// \brief A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
00258 ///
00259 /// This expression node represents a dynamic cast, e.g.,
00260 /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
00261 /// check to determine how to perform the type conversion.
00262 class CXXDynamicCastExpr : public CXXNamedCastExpr {
00263   CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
00264                      Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
00265                      SourceLocation l, SourceLocation RParenLoc,
00266                      SourceRange AngleBrackets)
00267     : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
00268                        writtenTy, l, RParenLoc, AngleBrackets) {}
00269 
00270   explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
00271     : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
00272 
00273 public:
00274   static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
00275                                     ExprValueKind VK, CastKind Kind, Expr *Op,
00276                                     const CXXCastPath *Path,
00277                                     TypeSourceInfo *Written, SourceLocation L,
00278                                     SourceLocation RParenLoc,
00279                                     SourceRange AngleBrackets);
00280 
00281   static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
00282                                          unsigned pathSize);
00283 
00284   bool isAlwaysNull() const;
00285 
00286   static bool classof(const Stmt *T) {
00287     return T->getStmtClass() == CXXDynamicCastExprClass;
00288   }
00289 };
00290 
00291 /// \brief A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
00292 ///
00293 /// This expression node represents a reinterpret cast, e.g.,
00294 /// @c reinterpret_cast<int>(VoidPtr).
00295 ///
00296 /// A reinterpret_cast provides a differently-typed view of a value but
00297 /// (in Clang, as in most C++ implementations) performs no actual work at
00298 /// run time.
00299 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
00300   CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
00301                          Expr *op, unsigned pathSize,
00302                          TypeSourceInfo *writtenTy, SourceLocation l,
00303                          SourceLocation RParenLoc,
00304                          SourceRange AngleBrackets)
00305     : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
00306                        pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
00307 
00308   CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
00309     : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
00310 
00311 public:
00312   static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
00313                                         ExprValueKind VK, CastKind Kind,
00314                                         Expr *Op, const CXXCastPath *Path,
00315                                  TypeSourceInfo *WrittenTy, SourceLocation L,
00316                                         SourceLocation RParenLoc,
00317                                         SourceRange AngleBrackets);
00318   static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
00319                                              unsigned pathSize);
00320 
00321   static bool classof(const Stmt *T) {
00322     return T->getStmtClass() == CXXReinterpretCastExprClass;
00323   }
00324 };
00325 
00326 /// \brief A C++ \c const_cast expression (C++ [expr.const.cast]).
00327 ///
00328 /// This expression node represents a const cast, e.g.,
00329 /// \c const_cast<char*>(PtrToConstChar).
00330 ///
00331 /// A const_cast can remove type qualifiers but does not change the underlying
00332 /// value.
00333 class CXXConstCastExpr : public CXXNamedCastExpr {
00334   CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
00335                    TypeSourceInfo *writtenTy, SourceLocation l,
00336                    SourceLocation RParenLoc, SourceRange AngleBrackets)
00337     : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
00338                        0, writtenTy, l, RParenLoc, AngleBrackets) {}
00339 
00340   explicit CXXConstCastExpr(EmptyShell Empty)
00341     : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
00342 
00343 public:
00344   static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
00345                                   ExprValueKind VK, Expr *Op,
00346                                   TypeSourceInfo *WrittenTy, SourceLocation L,
00347                                   SourceLocation RParenLoc,
00348                                   SourceRange AngleBrackets);
00349   static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
00350 
00351   static bool classof(const Stmt *T) {
00352     return T->getStmtClass() == CXXConstCastExprClass;
00353   }
00354 };
00355 
00356 /// \brief A call to a literal operator (C++11 [over.literal])
00357 /// written as a user-defined literal (C++11 [lit.ext]).
00358 ///
00359 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
00360 /// is semantically equivalent to a normal call, this AST node provides better
00361 /// information about the syntactic representation of the literal.
00362 ///
00363 /// Since literal operators are never found by ADL and can only be declared at
00364 /// namespace scope, a user-defined literal is never dependent.
00365 class UserDefinedLiteral : public CallExpr {
00366   /// \brief The location of a ud-suffix within the literal.
00367   SourceLocation UDSuffixLoc;
00368 
00369 public:
00370   UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
00371                      QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
00372                      SourceLocation SuffixLoc)
00373     : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc),
00374       UDSuffixLoc(SuffixLoc) {}
00375   explicit UserDefinedLiteral(const ASTContext &C, EmptyShell Empty)
00376     : CallExpr(C, UserDefinedLiteralClass, Empty) {}
00377 
00378   /// The kind of literal operator which is invoked.
00379   enum LiteralOperatorKind {
00380     LOK_Raw,      ///< Raw form: operator "" X (const char *)
00381     LOK_Template, ///< Raw form: operator "" X<cs...> ()
00382     LOK_Integer,  ///< operator "" X (unsigned long long)
00383     LOK_Floating, ///< operator "" X (long double)
00384     LOK_String,   ///< operator "" X (const CharT *, size_t)
00385     LOK_Character ///< operator "" X (CharT)
00386   };
00387 
00388   /// \brief Returns the kind of literal operator invocation
00389   /// which this expression represents.
00390   LiteralOperatorKind getLiteralOperatorKind() const;
00391 
00392   /// \brief If this is not a raw user-defined literal, get the
00393   /// underlying cooked literal (representing the literal with the suffix
00394   /// removed).
00395   Expr *getCookedLiteral();
00396   const Expr *getCookedLiteral() const {
00397     return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
00398   }
00399 
00400   SourceLocation getLocStart() const {
00401     if (getLiteralOperatorKind() == LOK_Template)
00402       return getRParenLoc();
00403     return getArg(0)->getLocStart();
00404   }
00405   SourceLocation getLocEnd() const { return getRParenLoc(); }
00406 
00407 
00408   /// \brief Returns the location of a ud-suffix in the expression.
00409   ///
00410   /// For a string literal, there may be multiple identical suffixes. This
00411   /// returns the first.
00412   SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
00413 
00414   /// \brief Returns the ud-suffix specified for this literal.
00415   const IdentifierInfo *getUDSuffix() const;
00416 
00417   static bool classof(const Stmt *S) {
00418     return S->getStmtClass() == UserDefinedLiteralClass;
00419   }
00420 
00421   friend class ASTStmtReader;
00422   friend class ASTStmtWriter;
00423 };
00424 
00425 /// \brief A boolean literal, per ([C++ lex.bool] Boolean literals).
00426 ///
00427 class CXXBoolLiteralExpr : public Expr {
00428   bool Value;
00429   SourceLocation Loc;
00430 public:
00431   CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
00432     Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
00433          false, false),
00434     Value(val), Loc(l) {}
00435 
00436   explicit CXXBoolLiteralExpr(EmptyShell Empty)
00437     : Expr(CXXBoolLiteralExprClass, Empty) { }
00438 
00439   bool getValue() const { return Value; }
00440   void setValue(bool V) { Value = V; }
00441 
00442   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
00443   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
00444 
00445   SourceLocation getLocation() const { return Loc; }
00446   void setLocation(SourceLocation L) { Loc = L; }
00447 
00448   static bool classof(const Stmt *T) {
00449     return T->getStmtClass() == CXXBoolLiteralExprClass;
00450   }
00451 
00452   // Iterators
00453   child_range children() { return child_range(); }
00454 };
00455 
00456 /// \brief The null pointer literal (C++11 [lex.nullptr])
00457 ///
00458 /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
00459 class CXXNullPtrLiteralExpr : public Expr {
00460   SourceLocation Loc;
00461 public:
00462   CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
00463     Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
00464          false, false),
00465     Loc(l) {}
00466 
00467   explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
00468     : Expr(CXXNullPtrLiteralExprClass, Empty) { }
00469 
00470   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
00471   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
00472 
00473   SourceLocation getLocation() const { return Loc; }
00474   void setLocation(SourceLocation L) { Loc = L; }
00475 
00476   static bool classof(const Stmt *T) {
00477     return T->getStmtClass() == CXXNullPtrLiteralExprClass;
00478   }
00479 
00480   child_range children() { return child_range(); }
00481 };
00482 
00483 /// \brief Implicit construction of a std::initializer_list<T> object from an
00484 /// array temporary within list-initialization (C++11 [dcl.init.list]p5).
00485 class CXXStdInitializerListExpr : public Expr {
00486   Stmt *SubExpr;
00487 
00488   CXXStdInitializerListExpr(EmptyShell Empty)
00489     : Expr(CXXStdInitializerListExprClass, Empty), SubExpr(nullptr) {}
00490 
00491 public:
00492   CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
00493     : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary,
00494            Ty->isDependentType(), SubExpr->isValueDependent(),
00495            SubExpr->isInstantiationDependent(),
00496            SubExpr->containsUnexpandedParameterPack()),
00497       SubExpr(SubExpr) {}
00498 
00499   Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
00500   const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
00501 
00502   SourceLocation getLocStart() const LLVM_READONLY {
00503     return SubExpr->getLocStart();
00504   }
00505   SourceLocation getLocEnd() const LLVM_READONLY {
00506     return SubExpr->getLocEnd();
00507   }
00508   SourceRange getSourceRange() const LLVM_READONLY {
00509     return SubExpr->getSourceRange();
00510   }
00511 
00512   static bool classof(const Stmt *S) {
00513     return S->getStmtClass() == CXXStdInitializerListExprClass;
00514   }
00515 
00516   child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
00517 
00518   friend class ASTReader;
00519   friend class ASTStmtReader;
00520 };
00521 
00522 /// A C++ \c typeid expression (C++ [expr.typeid]), which gets
00523 /// the \c type_info that corresponds to the supplied type, or the (possibly
00524 /// dynamic) type of the supplied expression.
00525 ///
00526 /// This represents code like \c typeid(int) or \c typeid(*objPtr)
00527 class CXXTypeidExpr : public Expr {
00528 private:
00529   llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
00530   SourceRange Range;
00531 
00532 public:
00533   CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
00534     : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
00535            // typeid is never type-dependent (C++ [temp.dep.expr]p4)
00536            false,
00537            // typeid is value-dependent if the type or expression are dependent
00538            Operand->getType()->isDependentType(),
00539            Operand->getType()->isInstantiationDependentType(),
00540            Operand->getType()->containsUnexpandedParameterPack()),
00541       Operand(Operand), Range(R) { }
00542 
00543   CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
00544     : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
00545         // typeid is never type-dependent (C++ [temp.dep.expr]p4)
00546            false,
00547         // typeid is value-dependent if the type or expression are dependent
00548            Operand->isTypeDependent() || Operand->isValueDependent(),
00549            Operand->isInstantiationDependent(),
00550            Operand->containsUnexpandedParameterPack()),
00551       Operand(Operand), Range(R) { }
00552 
00553   CXXTypeidExpr(EmptyShell Empty, bool isExpr)
00554     : Expr(CXXTypeidExprClass, Empty) {
00555     if (isExpr)
00556       Operand = (Expr*)nullptr;
00557     else
00558       Operand = (TypeSourceInfo*)nullptr;
00559   }
00560 
00561   /// Determine whether this typeid has a type operand which is potentially
00562   /// evaluated, per C++11 [expr.typeid]p3.
00563   bool isPotentiallyEvaluated() const;
00564 
00565   bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
00566 
00567   /// \brief Retrieves the type operand of this typeid() expression after
00568   /// various required adjustments (removing reference types, cv-qualifiers).
00569   QualType getTypeOperand(ASTContext &Context) const;
00570 
00571   /// \brief Retrieve source information for the type operand.
00572   TypeSourceInfo *getTypeOperandSourceInfo() const {
00573     assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
00574     return Operand.get<TypeSourceInfo *>();
00575   }
00576 
00577   void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
00578     assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
00579     Operand = TSI;
00580   }
00581 
00582   Expr *getExprOperand() const {
00583     assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
00584     return static_cast<Expr*>(Operand.get<Stmt *>());
00585   }
00586 
00587   void setExprOperand(Expr *E) {
00588     assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
00589     Operand = E;
00590   }
00591 
00592   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
00593   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
00594   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
00595   void setSourceRange(SourceRange R) { Range = R; }
00596 
00597   static bool classof(const Stmt *T) {
00598     return T->getStmtClass() == CXXTypeidExprClass;
00599   }
00600 
00601   // Iterators
00602   child_range children() {
00603     if (isTypeOperand()) return child_range();
00604     Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
00605     return child_range(begin, begin + 1);
00606   }
00607 };
00608 
00609 /// \brief A member reference to an MSPropertyDecl. 
00610 ///
00611 /// This expression always has pseudo-object type, and therefore it is
00612 /// typically not encountered in a fully-typechecked expression except
00613 /// within the syntactic form of a PseudoObjectExpr.
00614 class MSPropertyRefExpr : public Expr {
00615   Expr *BaseExpr;
00616   MSPropertyDecl *TheDecl;
00617   SourceLocation MemberLoc;
00618   bool IsArrow;
00619   NestedNameSpecifierLoc QualifierLoc;
00620 
00621 public:
00622   MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
00623                     QualType ty, ExprValueKind VK,
00624                     NestedNameSpecifierLoc qualifierLoc,
00625                     SourceLocation nameLoc)
00626   : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
00627          /*type-dependent*/ false, baseExpr->isValueDependent(),
00628          baseExpr->isInstantiationDependent(),
00629          baseExpr->containsUnexpandedParameterPack()),
00630     BaseExpr(baseExpr), TheDecl(decl),
00631     MemberLoc(nameLoc), IsArrow(isArrow),
00632     QualifierLoc(qualifierLoc) {}
00633 
00634   MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
00635 
00636   SourceRange getSourceRange() const LLVM_READONLY {
00637     return SourceRange(getLocStart(), getLocEnd());
00638   }
00639   bool isImplicitAccess() const {
00640     return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
00641   }
00642   SourceLocation getLocStart() const {
00643     if (!isImplicitAccess())
00644       return BaseExpr->getLocStart();
00645     else if (QualifierLoc)
00646       return QualifierLoc.getBeginLoc();
00647     else
00648         return MemberLoc;
00649   }
00650   SourceLocation getLocEnd() const { return getMemberLoc(); }
00651 
00652   child_range children() {
00653     return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
00654   }
00655   static bool classof(const Stmt *T) {
00656     return T->getStmtClass() == MSPropertyRefExprClass;
00657   }
00658 
00659   Expr *getBaseExpr() const { return BaseExpr; }
00660   MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
00661   bool isArrow() const { return IsArrow; }
00662   SourceLocation getMemberLoc() const { return MemberLoc; }
00663   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
00664 
00665   friend class ASTStmtReader;
00666 };
00667 
00668 /// A Microsoft C++ @c __uuidof expression, which gets
00669 /// the _GUID that corresponds to the supplied type or expression.
00670 ///
00671 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
00672 class CXXUuidofExpr : public Expr {
00673 private:
00674   llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
00675   SourceRange Range;
00676 
00677 public:
00678   CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
00679     : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
00680            false, Operand->getType()->isDependentType(),
00681            Operand->getType()->isInstantiationDependentType(),
00682            Operand->getType()->containsUnexpandedParameterPack()),
00683       Operand(Operand), Range(R) { }
00684 
00685   CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
00686     : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
00687            false, Operand->isTypeDependent(),
00688            Operand->isInstantiationDependent(),
00689            Operand->containsUnexpandedParameterPack()),
00690       Operand(Operand), Range(R) { }
00691 
00692   CXXUuidofExpr(EmptyShell Empty, bool isExpr)
00693     : Expr(CXXUuidofExprClass, Empty) {
00694     if (isExpr)
00695       Operand = (Expr*)nullptr;
00696     else
00697       Operand = (TypeSourceInfo*)nullptr;
00698   }
00699 
00700   bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
00701 
00702   /// \brief Retrieves the type operand of this __uuidof() expression after
00703   /// various required adjustments (removing reference types, cv-qualifiers).
00704   QualType getTypeOperand(ASTContext &Context) const;
00705 
00706   /// \brief Retrieve source information for the type operand.
00707   TypeSourceInfo *getTypeOperandSourceInfo() const {
00708     assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
00709     return Operand.get<TypeSourceInfo *>();
00710   }
00711 
00712   void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
00713     assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
00714     Operand = TSI;
00715   }
00716 
00717   Expr *getExprOperand() const {
00718     assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
00719     return static_cast<Expr*>(Operand.get<Stmt *>());
00720   }
00721 
00722   void setExprOperand(Expr *E) {
00723     assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
00724     Operand = E;
00725   }
00726 
00727   StringRef getUuidAsStringRef(ASTContext &Context) const;
00728 
00729   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
00730   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
00731   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
00732   void setSourceRange(SourceRange R) { Range = R; }
00733 
00734   static bool classof(const Stmt *T) {
00735     return T->getStmtClass() == CXXUuidofExprClass;
00736   }
00737 
00738   /// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to
00739   /// a single GUID.
00740   static const UuidAttr *GetUuidAttrOfType(QualType QT,
00741                                            bool *HasMultipleGUIDsPtr = nullptr);
00742 
00743   // Iterators
00744   child_range children() {
00745     if (isTypeOperand()) return child_range();
00746     Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
00747     return child_range(begin, begin + 1);
00748   }
00749 };
00750 
00751 /// \brief Represents the \c this expression in C++.
00752 ///
00753 /// This is a pointer to the object on which the current member function is
00754 /// executing (C++ [expr.prim]p3). Example:
00755 ///
00756 /// \code
00757 /// class Foo {
00758 /// public:
00759 ///   void bar();
00760 ///   void test() { this->bar(); }
00761 /// };
00762 /// \endcode
00763 class CXXThisExpr : public Expr {
00764   SourceLocation Loc;
00765   bool Implicit : 1;
00766 
00767 public:
00768   CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
00769     : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
00770            // 'this' is type-dependent if the class type of the enclosing
00771            // member function is dependent (C++ [temp.dep.expr]p2)
00772            Type->isDependentType(), Type->isDependentType(),
00773            Type->isInstantiationDependentType(),
00774            /*ContainsUnexpandedParameterPack=*/false),
00775       Loc(L), Implicit(isImplicit) { }
00776 
00777   CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
00778 
00779   SourceLocation getLocation() const { return Loc; }
00780   void setLocation(SourceLocation L) { Loc = L; }
00781 
00782   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
00783   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
00784 
00785   bool isImplicit() const { return Implicit; }
00786   void setImplicit(bool I) { Implicit = I; }
00787 
00788   static bool classof(const Stmt *T) {
00789     return T->getStmtClass() == CXXThisExprClass;
00790   }
00791 
00792   // Iterators
00793   child_range children() { return child_range(); }
00794 };
00795 
00796 /// \brief A C++ throw-expression (C++ [except.throw]).
00797 ///
00798 /// This handles 'throw' (for re-throwing the current exception) and
00799 /// 'throw' assignment-expression.  When assignment-expression isn't
00800 /// present, Op will be null.
00801 class CXXThrowExpr : public Expr {
00802   Stmt *Op;
00803   SourceLocation ThrowLoc;
00804   /// \brief Whether the thrown variable (if any) is in scope.
00805   unsigned IsThrownVariableInScope : 1;
00806 
00807   friend class ASTStmtReader;
00808 
00809 public:
00810   // \p Ty is the void type which is used as the result type of the
00811   // expression.  The \p l is the location of the throw keyword.  \p expr
00812   // can by null, if the optional expression to throw isn't present.
00813   CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
00814                bool IsThrownVariableInScope) :
00815     Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
00816          expr && expr->isInstantiationDependent(),
00817          expr && expr->containsUnexpandedParameterPack()),
00818     Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
00819   CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
00820 
00821   const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
00822   Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
00823 
00824   SourceLocation getThrowLoc() const { return ThrowLoc; }
00825 
00826   /// \brief Determines whether the variable thrown by this expression (if any!)
00827   /// is within the innermost try block.
00828   ///
00829   /// This information is required to determine whether the NRVO can apply to
00830   /// this variable.
00831   bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
00832 
00833   SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; }
00834   SourceLocation getLocEnd() const LLVM_READONLY {
00835     if (!getSubExpr())
00836       return ThrowLoc;
00837     return getSubExpr()->getLocEnd();
00838   }
00839 
00840   static bool classof(const Stmt *T) {
00841     return T->getStmtClass() == CXXThrowExprClass;
00842   }
00843 
00844   // Iterators
00845   child_range children() {
00846     return child_range(&Op, Op ? &Op+1 : &Op);
00847   }
00848 };
00849 
00850 /// \brief A default argument (C++ [dcl.fct.default]).
00851 ///
00852 /// This wraps up a function call argument that was created from the
00853 /// corresponding parameter's default argument, when the call did not
00854 /// explicitly supply arguments for all of the parameters.
00855 class CXXDefaultArgExpr : public Expr {
00856   /// \brief The parameter whose default is being used.
00857   ///
00858   /// When the bit is set, the subexpression is stored after the
00859   /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
00860   /// actual default expression is the subexpression.
00861   llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
00862 
00863   /// \brief The location where the default argument expression was used.
00864   SourceLocation Loc;
00865 
00866   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
00867     : Expr(SC,
00868            param->hasUnparsedDefaultArg()
00869              ? param->getType().getNonReferenceType()
00870              : param->getDefaultArg()->getType(),
00871            param->getDefaultArg()->getValueKind(),
00872            param->getDefaultArg()->getObjectKind(), false, false, false, false),
00873       Param(param, false), Loc(Loc) { }
00874 
00875   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
00876                     Expr *SubExpr)
00877     : Expr(SC, SubExpr->getType(),
00878            SubExpr->getValueKind(), SubExpr->getObjectKind(),
00879            false, false, false, false),
00880       Param(param, true), Loc(Loc) {
00881     *reinterpret_cast<Expr **>(this + 1) = SubExpr;
00882   }
00883 
00884 public:
00885   CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
00886 
00887   // \p Param is the parameter whose default argument is used by this
00888   // expression.
00889   static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
00890                                    ParmVarDecl *Param) {
00891     return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
00892   }
00893 
00894   // \p Param is the parameter whose default argument is used by this
00895   // expression, and \p SubExpr is the expression that will actually be used.
00896   static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
00897                                    ParmVarDecl *Param, Expr *SubExpr);
00898 
00899   // Retrieve the parameter that the argument was created from.
00900   const ParmVarDecl *getParam() const { return Param.getPointer(); }
00901   ParmVarDecl *getParam() { return Param.getPointer(); }
00902 
00903   // Retrieve the actual argument to the function call.
00904   const Expr *getExpr() const {
00905     if (Param.getInt())
00906       return *reinterpret_cast<Expr const * const*> (this + 1);
00907     return getParam()->getDefaultArg();
00908   }
00909   Expr *getExpr() {
00910     if (Param.getInt())
00911       return *reinterpret_cast<Expr **> (this + 1);
00912     return getParam()->getDefaultArg();
00913   }
00914 
00915   /// \brief Retrieve the location where this default argument was actually
00916   /// used.
00917   SourceLocation getUsedLocation() const { return Loc; }
00918 
00919   /// Default argument expressions have no representation in the
00920   /// source, so they have an empty source range.
00921   SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
00922   SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
00923 
00924   SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
00925 
00926   static bool classof(const Stmt *T) {
00927     return T->getStmtClass() == CXXDefaultArgExprClass;
00928   }
00929 
00930   // Iterators
00931   child_range children() { return child_range(); }
00932 
00933   friend class ASTStmtReader;
00934   friend class ASTStmtWriter;
00935 };
00936 
00937 /// \brief A use of a default initializer in a constructor or in aggregate
00938 /// initialization.
00939 ///
00940 /// This wraps a use of a C++ default initializer (technically,
00941 /// a brace-or-equal-initializer for a non-static data member) when it
00942 /// is implicitly used in a mem-initializer-list in a constructor
00943 /// (C++11 [class.base.init]p8) or in aggregate initialization
00944 /// (C++1y [dcl.init.aggr]p7).
00945 class CXXDefaultInitExpr : public Expr {
00946   /// \brief The field whose default is being used.
00947   FieldDecl *Field;
00948 
00949   /// \brief The location where the default initializer expression was used.
00950   SourceLocation Loc;
00951 
00952   CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field,
00953                      QualType T);
00954 
00955   CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
00956 
00957 public:
00958   /// \p Field is the non-static data member whose default initializer is used
00959   /// by this expression.
00960   static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc,
00961                                     FieldDecl *Field) {
00962     return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType());
00963   }
00964 
00965   /// \brief Get the field whose initializer will be used.
00966   FieldDecl *getField() { return Field; }
00967   const FieldDecl *getField() const { return Field; }
00968 
00969   /// \brief Get the initialization expression that will be used.
00970   const Expr *getExpr() const {
00971     assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
00972     return Field->getInClassInitializer();
00973   }
00974   Expr *getExpr() {
00975     assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
00976     return Field->getInClassInitializer();
00977   }
00978 
00979   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
00980   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
00981 
00982   static bool classof(const Stmt *T) {
00983     return T->getStmtClass() == CXXDefaultInitExprClass;
00984   }
00985 
00986   // Iterators
00987   child_range children() { return child_range(); }
00988 
00989   friend class ASTReader;
00990   friend class ASTStmtReader;
00991 };
00992 
00993 /// \brief Represents a C++ temporary.
00994 class CXXTemporary {
00995   /// \brief The destructor that needs to be called.
00996   const CXXDestructorDecl *Destructor;
00997 
00998   explicit CXXTemporary(const CXXDestructorDecl *destructor)
00999     : Destructor(destructor) { }
01000 
01001 public:
01002   static CXXTemporary *Create(const ASTContext &C,
01003                               const CXXDestructorDecl *Destructor);
01004 
01005   const CXXDestructorDecl *getDestructor() const { return Destructor; }
01006   void setDestructor(const CXXDestructorDecl *Dtor) {
01007     Destructor = Dtor;
01008   }
01009 };
01010 
01011 /// \brief Represents binding an expression to a temporary.
01012 ///
01013 /// This ensures the destructor is called for the temporary. It should only be
01014 /// needed for non-POD, non-trivially destructable class types. For example:
01015 ///
01016 /// \code
01017 ///   struct S {
01018 ///     S() { }  // User defined constructor makes S non-POD.
01019 ///     ~S() { } // User defined destructor makes it non-trivial.
01020 ///   };
01021 ///   void test() {
01022 ///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
01023 ///   }
01024 /// \endcode
01025 class CXXBindTemporaryExpr : public Expr {
01026   CXXTemporary *Temp;
01027 
01028   Stmt *SubExpr;
01029 
01030   CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
01031    : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
01032           VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
01033           SubExpr->isValueDependent(),
01034           SubExpr->isInstantiationDependent(),
01035           SubExpr->containsUnexpandedParameterPack()),
01036      Temp(temp), SubExpr(SubExpr) { }
01037 
01038 public:
01039   CXXBindTemporaryExpr(EmptyShell Empty)
01040     : Expr(CXXBindTemporaryExprClass, Empty), Temp(nullptr), SubExpr(nullptr) {}
01041 
01042   static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
01043                                       Expr* SubExpr);
01044 
01045   CXXTemporary *getTemporary() { return Temp; }
01046   const CXXTemporary *getTemporary() const { return Temp; }
01047   void setTemporary(CXXTemporary *T) { Temp = T; }
01048 
01049   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
01050   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
01051   void setSubExpr(Expr *E) { SubExpr = E; }
01052 
01053   SourceLocation getLocStart() const LLVM_READONLY {
01054     return SubExpr->getLocStart();
01055   }
01056   SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
01057 
01058   // Implement isa/cast/dyncast/etc.
01059   static bool classof(const Stmt *T) {
01060     return T->getStmtClass() == CXXBindTemporaryExprClass;
01061   }
01062 
01063   // Iterators
01064   child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
01065 };
01066 
01067 /// \brief Represents a call to a C++ constructor.
01068 class CXXConstructExpr : public Expr {
01069 public:
01070   enum ConstructionKind {
01071     CK_Complete,
01072     CK_NonVirtualBase,
01073     CK_VirtualBase,
01074     CK_Delegating
01075   };
01076 
01077 private:
01078   CXXConstructorDecl *Constructor;
01079 
01080   SourceLocation Loc;
01081   SourceRange ParenOrBraceRange;
01082   unsigned NumArgs : 16;
01083   bool Elidable : 1;
01084   bool HadMultipleCandidates : 1;
01085   bool ListInitialization : 1;
01086   bool StdInitListInitialization : 1;
01087   bool ZeroInitialization : 1;
01088   unsigned ConstructKind : 2;
01089   Stmt **Args;
01090 
01091 protected:
01092   CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T,
01093                    SourceLocation Loc,
01094                    CXXConstructorDecl *d, bool elidable,
01095                    ArrayRef<Expr *> Args,
01096                    bool HadMultipleCandidates,
01097                    bool ListInitialization,
01098                    bool StdInitListInitialization,
01099                    bool ZeroInitialization,
01100                    ConstructionKind ConstructKind,
01101                    SourceRange ParenOrBraceRange);
01102 
01103   /// \brief Construct an empty C++ construction expression.
01104   CXXConstructExpr(StmtClass SC, EmptyShell Empty)
01105     : Expr(SC, Empty), Constructor(nullptr), NumArgs(0), Elidable(false),
01106       HadMultipleCandidates(false), ListInitialization(false),
01107       ZeroInitialization(false), ConstructKind(0), Args(nullptr)
01108   { }
01109 
01110 public:
01111   /// \brief Construct an empty C++ construction expression.
01112   explicit CXXConstructExpr(EmptyShell Empty)
01113     : Expr(CXXConstructExprClass, Empty), Constructor(nullptr),
01114       NumArgs(0), Elidable(false), HadMultipleCandidates(false),
01115       ListInitialization(false), ZeroInitialization(false),
01116       ConstructKind(0), Args(nullptr)
01117   { }
01118 
01119   static CXXConstructExpr *Create(const ASTContext &C, QualType T,
01120                                   SourceLocation Loc,
01121                                   CXXConstructorDecl *D, bool Elidable,
01122                                   ArrayRef<Expr *> Args,
01123                                   bool HadMultipleCandidates,
01124                                   bool ListInitialization,
01125                                   bool StdInitListInitialization,
01126                                   bool ZeroInitialization,
01127                                   ConstructionKind ConstructKind,
01128                                   SourceRange ParenOrBraceRange);
01129 
01130   CXXConstructorDecl* getConstructor() const { return Constructor; }
01131   void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
01132 
01133   SourceLocation getLocation() const { return Loc; }
01134   void setLocation(SourceLocation Loc) { this->Loc = Loc; }
01135 
01136   /// \brief Whether this construction is elidable.
01137   bool isElidable() const { return Elidable; }
01138   void setElidable(bool E) { Elidable = E; }
01139 
01140   /// \brief Whether the referred constructor was resolved from
01141   /// an overloaded set having size greater than 1.
01142   bool hadMultipleCandidates() const { return HadMultipleCandidates; }
01143   void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
01144 
01145   /// \brief Whether this constructor call was written as list-initialization.
01146   bool isListInitialization() const { return ListInitialization; }
01147   void setListInitialization(bool V) { ListInitialization = V; }
01148 
01149   /// \brief Whether this constructor call was written as list-initialization,
01150   /// but was interpreted as forming a std::initializer_list<T> from the list
01151   /// and passing that as a single constructor argument.
01152   /// See C++11 [over.match.list]p1 bullet 1.
01153   bool isStdInitListInitialization() const { return StdInitListInitialization; }
01154   void setStdInitListInitialization(bool V) { StdInitListInitialization = V; }
01155 
01156   /// \brief Whether this construction first requires
01157   /// zero-initialization before the initializer is called.
01158   bool requiresZeroInitialization() const { return ZeroInitialization; }
01159   void setRequiresZeroInitialization(bool ZeroInit) {
01160     ZeroInitialization = ZeroInit;
01161   }
01162 
01163   /// \brief Determine whether this constructor is actually constructing
01164   /// a base class (rather than a complete object).
01165   ConstructionKind getConstructionKind() const {
01166     return (ConstructionKind)ConstructKind;
01167   }
01168   void setConstructionKind(ConstructionKind CK) {
01169     ConstructKind = CK;
01170   }
01171 
01172   typedef ExprIterator arg_iterator;
01173   typedef ConstExprIterator const_arg_iterator;
01174   typedef llvm::iterator_range<arg_iterator> arg_range;
01175   typedef llvm::iterator_range<const_arg_iterator> arg_const_range;
01176 
01177   arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
01178   arg_const_range arguments() const {
01179     return arg_const_range(arg_begin(), arg_end());
01180   }
01181 
01182   arg_iterator arg_begin() { return Args; }
01183   arg_iterator arg_end() { return Args + NumArgs; }
01184   const_arg_iterator arg_begin() const { return Args; }
01185   const_arg_iterator arg_end() const { return Args + NumArgs; }
01186 
01187   Expr **getArgs() { return reinterpret_cast<Expr **>(Args); }
01188   const Expr *const *getArgs() const {
01189     return const_cast<CXXConstructExpr *>(this)->getArgs();
01190   }
01191   unsigned getNumArgs() const { return NumArgs; }
01192 
01193   /// \brief Return the specified argument.
01194   Expr *getArg(unsigned Arg) {
01195     assert(Arg < NumArgs && "Arg access out of range!");
01196     return cast<Expr>(Args[Arg]);
01197   }
01198   const Expr *getArg(unsigned Arg) const {
01199     assert(Arg < NumArgs && "Arg access out of range!");
01200     return cast<Expr>(Args[Arg]);
01201   }
01202 
01203   /// \brief Set the specified argument.
01204   void setArg(unsigned Arg, Expr *ArgExpr) {
01205     assert(Arg < NumArgs && "Arg access out of range!");
01206     Args[Arg] = ArgExpr;
01207   }
01208 
01209   SourceLocation getLocStart() const LLVM_READONLY;
01210   SourceLocation getLocEnd() const LLVM_READONLY;
01211   SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
01212   void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
01213 
01214   static bool classof(const Stmt *T) {
01215     return T->getStmtClass() == CXXConstructExprClass ||
01216       T->getStmtClass() == CXXTemporaryObjectExprClass;
01217   }
01218 
01219   // Iterators
01220   child_range children() {
01221     return child_range(&Args[0], &Args[0]+NumArgs);
01222   }
01223 
01224   friend class ASTStmtReader;
01225 };
01226 
01227 /// \brief Represents an explicit C++ type conversion that uses "functional"
01228 /// notation (C++ [expr.type.conv]).
01229 ///
01230 /// Example:
01231 /// \code
01232 ///   x = int(0.5);
01233 /// \endcode
01234 class CXXFunctionalCastExpr : public ExplicitCastExpr {
01235   SourceLocation LParenLoc;
01236   SourceLocation RParenLoc;
01237 
01238   CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
01239                         TypeSourceInfo *writtenTy,
01240                         CastKind kind, Expr *castExpr, unsigned pathSize,
01241                         SourceLocation lParenLoc, SourceLocation rParenLoc)
01242     : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
01243                        castExpr, pathSize, writtenTy),
01244       LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
01245 
01246   explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
01247     : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
01248 
01249 public:
01250   static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
01251                                        ExprValueKind VK,
01252                                        TypeSourceInfo *Written,
01253                                        CastKind Kind, Expr *Op,
01254                                        const CXXCastPath *Path,
01255                                        SourceLocation LPLoc,
01256                                        SourceLocation RPLoc);
01257   static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
01258                                             unsigned PathSize);
01259 
01260   SourceLocation getLParenLoc() const { return LParenLoc; }
01261   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
01262   SourceLocation getRParenLoc() const { return RParenLoc; }
01263   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
01264 
01265   SourceLocation getLocStart() const LLVM_READONLY;
01266   SourceLocation getLocEnd() const LLVM_READONLY;
01267 
01268   static bool classof(const Stmt *T) {
01269     return T->getStmtClass() == CXXFunctionalCastExprClass;
01270   }
01271 };
01272 
01273 /// @brief Represents a C++ functional cast expression that builds a
01274 /// temporary object.
01275 ///
01276 /// This expression type represents a C++ "functional" cast
01277 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
01278 /// constructor to build a temporary object. With N == 1 arguments the
01279 /// functional cast expression will be represented by CXXFunctionalCastExpr.
01280 /// Example:
01281 /// \code
01282 /// struct X { X(int, float); }
01283 ///
01284 /// X create_X() {
01285 ///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
01286 /// };
01287 /// \endcode
01288 class CXXTemporaryObjectExpr : public CXXConstructExpr {
01289   TypeSourceInfo *Type;
01290 
01291 public:
01292   CXXTemporaryObjectExpr(const ASTContext &C, CXXConstructorDecl *Cons,
01293                          TypeSourceInfo *Type,
01294                          ArrayRef<Expr *> Args,
01295                          SourceRange ParenOrBraceRange,
01296                          bool HadMultipleCandidates,
01297                          bool ListInitialization,
01298                          bool StdInitListInitialization,
01299                          bool ZeroInitialization);
01300   explicit CXXTemporaryObjectExpr(EmptyShell Empty)
01301     : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
01302 
01303   TypeSourceInfo *getTypeSourceInfo() const { return Type; }
01304 
01305   SourceLocation getLocStart() const LLVM_READONLY;
01306   SourceLocation getLocEnd() const LLVM_READONLY;
01307 
01308   static bool classof(const Stmt *T) {
01309     return T->getStmtClass() == CXXTemporaryObjectExprClass;
01310   }
01311 
01312   friend class ASTStmtReader;
01313 };
01314 
01315 /// \brief A C++ lambda expression, which produces a function object
01316 /// (of unspecified type) that can be invoked later.
01317 ///
01318 /// Example:
01319 /// \code
01320 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
01321 ///   values.erase(std::remove_if(values.begin(), values.end(),
01322 ///                               [=](double value) { return value > cutoff; });
01323 /// }
01324 /// \endcode
01325 ///
01326 /// C++11 lambda expressions can capture local variables, either by copying
01327 /// the values of those local variables at the time the function
01328 /// object is constructed (not when it is called!) or by holding a
01329 /// reference to the local variable. These captures can occur either
01330 /// implicitly or can be written explicitly between the square
01331 /// brackets ([...]) that start the lambda expression.
01332 ///
01333 /// C++1y introduces a new form of "capture" called an init-capture that
01334 /// includes an initializing expression (rather than capturing a variable),
01335 /// and which can never occur implicitly.
01336 class LambdaExpr : public Expr {
01337   /// \brief The source range that covers the lambda introducer ([...]).
01338   SourceRange IntroducerRange;
01339 
01340   /// \brief The source location of this lambda's capture-default ('=' or '&').
01341   SourceLocation CaptureDefaultLoc;
01342 
01343   /// \brief The number of captures.
01344   unsigned NumCaptures : 16;
01345   
01346   /// \brief The default capture kind, which is a value of type
01347   /// LambdaCaptureDefault.
01348   unsigned CaptureDefault : 2;
01349 
01350   /// \brief Whether this lambda had an explicit parameter list vs. an
01351   /// implicit (and empty) parameter list.
01352   unsigned ExplicitParams : 1;
01353 
01354   /// \brief Whether this lambda had the result type explicitly specified.
01355   unsigned ExplicitResultType : 1;
01356   
01357   /// \brief Whether there are any array index variables stored at the end of
01358   /// this lambda expression.
01359   unsigned HasArrayIndexVars : 1;
01360   
01361   /// \brief The location of the closing brace ('}') that completes
01362   /// the lambda.
01363   /// 
01364   /// The location of the brace is also available by looking up the
01365   /// function call operator in the lambda class. However, it is
01366   /// stored here to improve the performance of getSourceRange(), and
01367   /// to avoid having to deserialize the function call operator from a
01368   /// module file just to determine the source range.
01369   SourceLocation ClosingBrace;
01370 
01371   // Note: The capture initializers are stored directly after the lambda
01372   // expression, along with the index variables used to initialize by-copy
01373   // array captures.
01374 
01375   typedef LambdaCapture Capture;
01376 
01377   /// \brief Construct a lambda expression.
01378   LambdaExpr(QualType T, SourceRange IntroducerRange,
01379              LambdaCaptureDefault CaptureDefault,
01380              SourceLocation CaptureDefaultLoc,
01381              ArrayRef<Capture> Captures,
01382              bool ExplicitParams,
01383              bool ExplicitResultType,
01384              ArrayRef<Expr *> CaptureInits,
01385              ArrayRef<VarDecl *> ArrayIndexVars,
01386              ArrayRef<unsigned> ArrayIndexStarts,
01387              SourceLocation ClosingBrace,
01388              bool ContainsUnexpandedParameterPack);
01389 
01390   /// \brief Construct an empty lambda expression.
01391   LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
01392     : Expr(LambdaExprClass, Empty),
01393       NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
01394       ExplicitResultType(false), HasArrayIndexVars(true) { 
01395     getStoredStmts()[NumCaptures] = nullptr;
01396   }
01397   
01398   Stmt **getStoredStmts() const {
01399     return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
01400   }
01401   
01402   /// \brief Retrieve the mapping from captures to the first array index
01403   /// variable.
01404   unsigned *getArrayIndexStarts() const {
01405     return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
01406   }
01407   
01408   /// \brief Retrieve the complete set of array-index variables.
01409   VarDecl **getArrayIndexVars() const {
01410     unsigned ArrayIndexSize =
01411         llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1),
01412                                  llvm::alignOf<VarDecl*>());
01413     return reinterpret_cast<VarDecl **>(
01414         reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize);
01415   }
01416 
01417 public:
01418   /// \brief Construct a new lambda expression.
01419   static LambdaExpr *Create(const ASTContext &C,
01420                             CXXRecordDecl *Class,
01421                             SourceRange IntroducerRange,
01422                             LambdaCaptureDefault CaptureDefault,
01423                             SourceLocation CaptureDefaultLoc,
01424                             ArrayRef<Capture> Captures,
01425                             bool ExplicitParams,
01426                             bool ExplicitResultType,
01427                             ArrayRef<Expr *> CaptureInits,
01428                             ArrayRef<VarDecl *> ArrayIndexVars,
01429                             ArrayRef<unsigned> ArrayIndexStarts,
01430                             SourceLocation ClosingBrace,
01431                             bool ContainsUnexpandedParameterPack);
01432 
01433   /// \brief Construct a new lambda expression that will be deserialized from
01434   /// an external source.
01435   static LambdaExpr *CreateDeserialized(const ASTContext &C,
01436                                         unsigned NumCaptures,
01437                                         unsigned NumArrayIndexVars);
01438 
01439   /// \brief Determine the default capture kind for this lambda.
01440   LambdaCaptureDefault getCaptureDefault() const {
01441     return static_cast<LambdaCaptureDefault>(CaptureDefault);
01442   }
01443 
01444   /// \brief Retrieve the location of this lambda's capture-default, if any.
01445   SourceLocation getCaptureDefaultLoc() const {
01446     return CaptureDefaultLoc;
01447   }
01448 
01449   /// \brief An iterator that walks over the captures of the lambda,
01450   /// both implicit and explicit.
01451   typedef const Capture *capture_iterator;
01452 
01453   /// \brief An iterator over a range of lambda captures.
01454   typedef llvm::iterator_range<capture_iterator> capture_range;
01455 
01456   /// \brief Retrieve this lambda's captures.
01457   capture_range captures() const;
01458   
01459   /// \brief Retrieve an iterator pointing to the first lambda capture.
01460   capture_iterator capture_begin() const;
01461 
01462   /// \brief Retrieve an iterator pointing past the end of the
01463   /// sequence of lambda captures.
01464   capture_iterator capture_end() const;
01465 
01466   /// \brief Determine the number of captures in this lambda.
01467   unsigned capture_size() const { return NumCaptures; }
01468 
01469   /// \brief Retrieve this lambda's explicit captures.
01470   capture_range explicit_captures() const;
01471   
01472   /// \brief Retrieve an iterator pointing to the first explicit
01473   /// lambda capture.
01474   capture_iterator explicit_capture_begin() const;
01475 
01476   /// \brief Retrieve an iterator pointing past the end of the sequence of
01477   /// explicit lambda captures.
01478   capture_iterator explicit_capture_end() const;
01479 
01480   /// \brief Retrieve this lambda's implicit captures.
01481   capture_range implicit_captures() const;
01482 
01483   /// \brief Retrieve an iterator pointing to the first implicit
01484   /// lambda capture.
01485   capture_iterator implicit_capture_begin() const;
01486 
01487   /// \brief Retrieve an iterator pointing past the end of the sequence of
01488   /// implicit lambda captures.
01489   capture_iterator implicit_capture_end() const;
01490 
01491   /// \brief Iterator that walks over the capture initialization
01492   /// arguments.
01493   typedef Expr **capture_init_iterator;
01494 
01495   /// \brief Retrieve the initialization expressions for this lambda's captures.
01496   llvm::iterator_range<capture_init_iterator> capture_inits() const {
01497     return llvm::iterator_range<capture_init_iterator>(capture_init_begin(),
01498                                                        capture_init_end());
01499   }
01500 
01501   /// \brief Retrieve the first initialization argument for this
01502   /// lambda expression (which initializes the first capture field).
01503   capture_init_iterator capture_init_begin() const {
01504     return reinterpret_cast<Expr **>(getStoredStmts());
01505   }
01506 
01507   /// \brief Retrieve the iterator pointing one past the last
01508   /// initialization argument for this lambda expression.
01509   capture_init_iterator capture_init_end() const {
01510     return capture_init_begin() + NumCaptures;    
01511   }
01512 
01513   /// \brief Retrieve the set of index variables used in the capture 
01514   /// initializer of an array captured by copy.
01515   ///
01516   /// \param Iter The iterator that points at the capture initializer for 
01517   /// which we are extracting the corresponding index variables.
01518   ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
01519   
01520   /// \brief Retrieve the source range covering the lambda introducer,
01521   /// which contains the explicit capture list surrounded by square
01522   /// brackets ([...]).
01523   SourceRange getIntroducerRange() const { return IntroducerRange; }
01524 
01525   /// \brief Retrieve the class that corresponds to the lambda.
01526   /// 
01527   /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
01528   /// captures in its fields and provides the various operations permitted
01529   /// on a lambda (copying, calling).
01530   CXXRecordDecl *getLambdaClass() const;
01531 
01532   /// \brief Retrieve the function call operator associated with this
01533   /// lambda expression. 
01534   CXXMethodDecl *getCallOperator() const;
01535 
01536   /// \brief If this is a generic lambda expression, retrieve the template 
01537   /// parameter list associated with it, or else return null. 
01538   TemplateParameterList *getTemplateParameterList() const;
01539 
01540   /// \brief Whether this is a generic lambda.
01541   bool isGenericLambda() const { return getTemplateParameterList(); }
01542 
01543   /// \brief Retrieve the body of the lambda.
01544   CompoundStmt *getBody() const;
01545 
01546   /// \brief Determine whether the lambda is mutable, meaning that any
01547   /// captures values can be modified.
01548   bool isMutable() const;
01549 
01550   /// \brief Determine whether this lambda has an explicit parameter
01551   /// list vs. an implicit (empty) parameter list.
01552   bool hasExplicitParameters() const { return ExplicitParams; }
01553 
01554   /// \brief Whether this lambda had its result type explicitly specified.
01555   bool hasExplicitResultType() const { return ExplicitResultType; }
01556     
01557   static bool classof(const Stmt *T) {
01558     return T->getStmtClass() == LambdaExprClass;
01559   }
01560 
01561   SourceLocation getLocStart() const LLVM_READONLY {
01562     return IntroducerRange.getBegin();
01563   }
01564   SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
01565 
01566   child_range children() {
01567     return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
01568   }
01569 
01570   friend class ASTStmtReader;
01571   friend class ASTStmtWriter;
01572 };
01573 
01574 /// An expression "T()" which creates a value-initialized rvalue of type
01575 /// T, which is a non-class type.  See (C++98 [5.2.3p2]).
01576 class CXXScalarValueInitExpr : public Expr {
01577   SourceLocation RParenLoc;
01578   TypeSourceInfo *TypeInfo;
01579 
01580   friend class ASTStmtReader;
01581 
01582 public:
01583   /// \brief Create an explicitly-written scalar-value initialization
01584   /// expression.
01585   CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
01586                          SourceLocation rParenLoc)
01587       : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
01588              false, false, Type->isInstantiationDependentType(),
01589              Type->containsUnexpandedParameterPack()),
01590         RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
01591 
01592   explicit CXXScalarValueInitExpr(EmptyShell Shell)
01593     : Expr(CXXScalarValueInitExprClass, Shell) { }
01594 
01595   TypeSourceInfo *getTypeSourceInfo() const {
01596     return TypeInfo;
01597   }
01598 
01599   SourceLocation getRParenLoc() const { return RParenLoc; }
01600 
01601   SourceLocation getLocStart() const LLVM_READONLY;
01602   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
01603 
01604   static bool classof(const Stmt *T) {
01605     return T->getStmtClass() == CXXScalarValueInitExprClass;
01606   }
01607 
01608   // Iterators
01609   child_range children() { return child_range(); }
01610 };
01611 
01612 /// \brief Represents a new-expression for memory allocation and constructor
01613 /// calls, e.g: "new CXXNewExpr(foo)".
01614 class CXXNewExpr : public Expr {
01615   /// Contains an optional array size expression, an optional initialization
01616   /// expression, and any number of optional placement arguments, in that order.
01617   Stmt **SubExprs;
01618   /// \brief Points to the allocation function used.
01619   FunctionDecl *OperatorNew;
01620   /// \brief Points to the deallocation function used in case of error. May be
01621   /// null.
01622   FunctionDecl *OperatorDelete;
01623 
01624   /// \brief The allocated type-source information, as written in the source.
01625   TypeSourceInfo *AllocatedTypeInfo;
01626 
01627   /// \brief If the allocated type was expressed as a parenthesized type-id,
01628   /// the source range covering the parenthesized type-id.
01629   SourceRange TypeIdParens;
01630 
01631   /// \brief Range of the entire new expression.
01632   SourceRange Range;
01633 
01634   /// \brief Source-range of a paren-delimited initializer.
01635   SourceRange DirectInitRange;
01636 
01637   /// Was the usage ::new, i.e. is the global new to be used?
01638   bool GlobalNew : 1;
01639   /// Do we allocate an array? If so, the first SubExpr is the size expression.
01640   bool Array : 1;
01641   /// If this is an array allocation, does the usual deallocation
01642   /// function for the allocated type want to know the allocated size?
01643   bool UsualArrayDeleteWantsSize : 1;
01644   /// The number of placement new arguments.
01645   unsigned NumPlacementArgs : 13;
01646   /// What kind of initializer do we have? Could be none, parens, or braces.
01647   /// In storage, we distinguish between "none, and no initializer expr", and
01648   /// "none, but an implicit initializer expr".
01649   unsigned StoredInitializationStyle : 2;
01650 
01651   friend class ASTStmtReader;
01652   friend class ASTStmtWriter;
01653 public:
01654   enum InitializationStyle {
01655     NoInit,   ///< New-expression has no initializer as written.
01656     CallInit, ///< New-expression has a C++98 paren-delimited initializer.
01657     ListInit  ///< New-expression has a C++11 list-initializer.
01658   };
01659 
01660   CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
01661              FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
01662              ArrayRef<Expr*> placementArgs,
01663              SourceRange typeIdParens, Expr *arraySize,
01664              InitializationStyle initializationStyle, Expr *initializer,
01665              QualType ty, TypeSourceInfo *AllocatedTypeInfo,
01666              SourceRange Range, SourceRange directInitRange);
01667   explicit CXXNewExpr(EmptyShell Shell)
01668     : Expr(CXXNewExprClass, Shell), SubExprs(nullptr) { }
01669 
01670   void AllocateArgsArray(const ASTContext &C, bool isArray,
01671                          unsigned numPlaceArgs, bool hasInitializer);
01672 
01673   QualType getAllocatedType() const {
01674     assert(getType()->isPointerType());
01675     return getType()->getAs<PointerType>()->getPointeeType();
01676   }
01677 
01678   TypeSourceInfo *getAllocatedTypeSourceInfo() const {
01679     return AllocatedTypeInfo;
01680   }
01681 
01682   /// \brief True if the allocation result needs to be null-checked.
01683   ///
01684   /// C++11 [expr.new]p13:
01685   ///   If the allocation function returns null, initialization shall
01686   ///   not be done, the deallocation function shall not be called,
01687   ///   and the value of the new-expression shall be null.
01688   ///
01689   /// An allocation function is not allowed to return null unless it
01690   /// has a non-throwing exception-specification.  The '03 rule is
01691   /// identical except that the definition of a non-throwing
01692   /// exception specification is just "is it throw()?".
01693   bool shouldNullCheckAllocation(const ASTContext &Ctx) const;
01694 
01695   FunctionDecl *getOperatorNew() const { return OperatorNew; }
01696   void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
01697   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
01698   void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
01699 
01700   bool isArray() const { return Array; }
01701   Expr *getArraySize() {
01702     return Array ? cast<Expr>(SubExprs[0]) : nullptr;
01703   }
01704   const Expr *getArraySize() const {
01705     return Array ? cast<Expr>(SubExprs[0]) : nullptr;
01706   }
01707 
01708   unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
01709   Expr **getPlacementArgs() {
01710     return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
01711   }
01712 
01713   Expr *getPlacementArg(unsigned i) {
01714     assert(i < NumPlacementArgs && "Index out of range");
01715     return getPlacementArgs()[i];
01716   }
01717   const Expr *getPlacementArg(unsigned i) const {
01718     assert(i < NumPlacementArgs && "Index out of range");
01719     return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
01720   }
01721 
01722   bool isParenTypeId() const { return TypeIdParens.isValid(); }
01723   SourceRange getTypeIdParens() const { return TypeIdParens; }
01724 
01725   bool isGlobalNew() const { return GlobalNew; }
01726 
01727   /// \brief Whether this new-expression has any initializer at all.
01728   bool hasInitializer() const { return StoredInitializationStyle > 0; }
01729 
01730   /// \brief The kind of initializer this new-expression has.
01731   InitializationStyle getInitializationStyle() const {
01732     if (StoredInitializationStyle == 0)
01733       return NoInit;
01734     return static_cast<InitializationStyle>(StoredInitializationStyle-1);
01735   }
01736 
01737   /// \brief The initializer of this new-expression.
01738   Expr *getInitializer() {
01739     return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
01740   }
01741   const Expr *getInitializer() const {
01742     return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
01743   }
01744 
01745   /// \brief Returns the CXXConstructExpr from this new-expression, or null.
01746   const CXXConstructExpr* getConstructExpr() const {
01747     return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
01748   }
01749 
01750   /// Answers whether the usual array deallocation function for the
01751   /// allocated type expects the size of the allocation as a
01752   /// parameter.
01753   bool doesUsualArrayDeleteWantSize() const {
01754     return UsualArrayDeleteWantsSize;
01755   }
01756 
01757   typedef ExprIterator arg_iterator;
01758   typedef ConstExprIterator const_arg_iterator;
01759 
01760   arg_iterator placement_arg_begin() {
01761     return SubExprs + Array + hasInitializer();
01762   }
01763   arg_iterator placement_arg_end() {
01764     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
01765   }
01766   const_arg_iterator placement_arg_begin() const {
01767     return SubExprs + Array + hasInitializer();
01768   }
01769   const_arg_iterator placement_arg_end() const {
01770     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
01771   }
01772 
01773   typedef Stmt **raw_arg_iterator;
01774   raw_arg_iterator raw_arg_begin() { return SubExprs; }
01775   raw_arg_iterator raw_arg_end() {
01776     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
01777   }
01778   const_arg_iterator raw_arg_begin() const { return SubExprs; }
01779   const_arg_iterator raw_arg_end() const {
01780     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
01781   }
01782 
01783   SourceLocation getStartLoc() const { return Range.getBegin(); }
01784   SourceLocation getEndLoc() const { return Range.getEnd(); }
01785 
01786   SourceRange getDirectInitRange() const { return DirectInitRange; }
01787 
01788   SourceRange getSourceRange() const LLVM_READONLY {
01789     return Range;
01790   }
01791   SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
01792   SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
01793 
01794   static bool classof(const Stmt *T) {
01795     return T->getStmtClass() == CXXNewExprClass;
01796   }
01797 
01798   // Iterators
01799   child_range children() {
01800     return child_range(raw_arg_begin(), raw_arg_end());
01801   }
01802 };
01803 
01804 /// \brief Represents a \c delete expression for memory deallocation and
01805 /// destructor calls, e.g. "delete[] pArray".
01806 class CXXDeleteExpr : public Expr {
01807   /// Points to the operator delete overload that is used. Could be a member.
01808   FunctionDecl *OperatorDelete;
01809   /// The pointer expression to be deleted.
01810   Stmt *Argument;
01811   /// Location of the expression.
01812   SourceLocation Loc;
01813   /// Is this a forced global delete, i.e. "::delete"?
01814   bool GlobalDelete : 1;
01815   /// Is this the array form of delete, i.e. "delete[]"?
01816   bool ArrayForm : 1;
01817   /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
01818   /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
01819   /// will be true).
01820   bool ArrayFormAsWritten : 1;
01821   /// Does the usual deallocation function for the element type require
01822   /// a size_t argument?
01823   bool UsualArrayDeleteWantsSize : 1;
01824 public:
01825   CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
01826                 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
01827                 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
01828     : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
01829            arg->isInstantiationDependent(),
01830            arg->containsUnexpandedParameterPack()),
01831       OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
01832       GlobalDelete(globalDelete),
01833       ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
01834       UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
01835   explicit CXXDeleteExpr(EmptyShell Shell)
01836     : Expr(CXXDeleteExprClass, Shell), OperatorDelete(nullptr),
01837       Argument(nullptr) {}
01838 
01839   bool isGlobalDelete() const { return GlobalDelete; }
01840   bool isArrayForm() const { return ArrayForm; }
01841   bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
01842 
01843   /// Answers whether the usual array deallocation function for the
01844   /// allocated type expects the size of the allocation as a
01845   /// parameter.  This can be true even if the actual deallocation
01846   /// function that we're using doesn't want a size.
01847   bool doesUsualArrayDeleteWantSize() const {
01848     return UsualArrayDeleteWantsSize;
01849   }
01850 
01851   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
01852 
01853   Expr *getArgument() { return cast<Expr>(Argument); }
01854   const Expr *getArgument() const { return cast<Expr>(Argument); }
01855 
01856   /// \brief Retrieve the type being destroyed. 
01857   ///
01858   /// If the type being destroyed is a dependent type which may or may not
01859   /// be a pointer, return an invalid type.
01860   QualType getDestroyedType() const;
01861 
01862   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
01863   SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
01864 
01865   static bool classof(const Stmt *T) {
01866     return T->getStmtClass() == CXXDeleteExprClass;
01867   }
01868 
01869   // Iterators
01870   child_range children() { return child_range(&Argument, &Argument+1); }
01871 
01872   friend class ASTStmtReader;
01873 };
01874 
01875 /// \brief Stores the type being destroyed by a pseudo-destructor expression.
01876 class PseudoDestructorTypeStorage {
01877   /// \brief Either the type source information or the name of the type, if
01878   /// it couldn't be resolved due to type-dependence.
01879   llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
01880 
01881   /// \brief The starting source location of the pseudo-destructor type.
01882   SourceLocation Location;
01883 
01884 public:
01885   PseudoDestructorTypeStorage() { }
01886 
01887   PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
01888     : Type(II), Location(Loc) { }
01889 
01890   PseudoDestructorTypeStorage(TypeSourceInfo *Info);
01891 
01892   TypeSourceInfo *getTypeSourceInfo() const {
01893     return Type.dyn_cast<TypeSourceInfo *>();
01894   }
01895 
01896   IdentifierInfo *getIdentifier() const {
01897     return Type.dyn_cast<IdentifierInfo *>();
01898   }
01899 
01900   SourceLocation getLocation() const { return Location; }
01901 };
01902 
01903 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
01904 ///
01905 /// A pseudo-destructor is an expression that looks like a member access to a
01906 /// destructor of a scalar type, except that scalar types don't have
01907 /// destructors. For example:
01908 ///
01909 /// \code
01910 /// typedef int T;
01911 /// void f(int *p) {
01912 ///   p->T::~T();
01913 /// }
01914 /// \endcode
01915 ///
01916 /// Pseudo-destructors typically occur when instantiating templates such as:
01917 ///
01918 /// \code
01919 /// template<typename T>
01920 /// void destroy(T* ptr) {
01921 ///   ptr->T::~T();
01922 /// }
01923 /// \endcode
01924 ///
01925 /// for scalar types. A pseudo-destructor expression has no run-time semantics
01926 /// beyond evaluating the base expression.
01927 class CXXPseudoDestructorExpr : public Expr {
01928   /// \brief The base expression (that is being destroyed).
01929   Stmt *Base;
01930 
01931   /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
01932   /// period ('.').
01933   bool IsArrow : 1;
01934 
01935   /// \brief The location of the '.' or '->' operator.
01936   SourceLocation OperatorLoc;
01937 
01938   /// \brief The nested-name-specifier that follows the operator, if present.
01939   NestedNameSpecifierLoc QualifierLoc;
01940 
01941   /// \brief The type that precedes the '::' in a qualified pseudo-destructor
01942   /// expression.
01943   TypeSourceInfo *ScopeType;
01944 
01945   /// \brief The location of the '::' in a qualified pseudo-destructor
01946   /// expression.
01947   SourceLocation ColonColonLoc;
01948 
01949   /// \brief The location of the '~'.
01950   SourceLocation TildeLoc;
01951 
01952   /// \brief The type being destroyed, or its name if we were unable to
01953   /// resolve the name.
01954   PseudoDestructorTypeStorage DestroyedType;
01955 
01956   friend class ASTStmtReader;
01957 
01958 public:
01959   CXXPseudoDestructorExpr(const ASTContext &Context,
01960                           Expr *Base, bool isArrow, SourceLocation OperatorLoc,
01961                           NestedNameSpecifierLoc QualifierLoc,
01962                           TypeSourceInfo *ScopeType,
01963                           SourceLocation ColonColonLoc,
01964                           SourceLocation TildeLoc,
01965                           PseudoDestructorTypeStorage DestroyedType);
01966 
01967   explicit CXXPseudoDestructorExpr(EmptyShell Shell)
01968     : Expr(CXXPseudoDestructorExprClass, Shell),
01969       Base(nullptr), IsArrow(false), QualifierLoc(), ScopeType(nullptr) { }
01970 
01971   Expr *getBase() const { return cast<Expr>(Base); }
01972 
01973   /// \brief Determines whether this member expression actually had
01974   /// a C++ nested-name-specifier prior to the name of the member, e.g.,
01975   /// x->Base::foo.
01976   bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
01977 
01978   /// \brief Retrieves the nested-name-specifier that qualifies the type name,
01979   /// with source-location information.
01980   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
01981 
01982   /// \brief If the member name was qualified, retrieves the
01983   /// nested-name-specifier that precedes the member name. Otherwise, returns
01984   /// null.
01985   NestedNameSpecifier *getQualifier() const {
01986     return QualifierLoc.getNestedNameSpecifier();
01987   }
01988 
01989   /// \brief Determine whether this pseudo-destructor expression was written
01990   /// using an '->' (otherwise, it used a '.').
01991   bool isArrow() const { return IsArrow; }
01992 
01993   /// \brief Retrieve the location of the '.' or '->' operator.
01994   SourceLocation getOperatorLoc() const { return OperatorLoc; }
01995 
01996   /// \brief Retrieve the scope type in a qualified pseudo-destructor
01997   /// expression.
01998   ///
01999   /// Pseudo-destructor expressions can have extra qualification within them
02000   /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
02001   /// Here, if the object type of the expression is (or may be) a scalar type,
02002   /// \p T may also be a scalar type and, therefore, cannot be part of a
02003   /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
02004   /// destructor expression.
02005   TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
02006 
02007   /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
02008   /// expression.
02009   SourceLocation getColonColonLoc() const { return ColonColonLoc; }
02010 
02011   /// \brief Retrieve the location of the '~'.
02012   SourceLocation getTildeLoc() const { return TildeLoc; }
02013 
02014   /// \brief Retrieve the source location information for the type
02015   /// being destroyed.
02016   ///
02017   /// This type-source information is available for non-dependent
02018   /// pseudo-destructor expressions and some dependent pseudo-destructor
02019   /// expressions. Returns null if we only have the identifier for a
02020   /// dependent pseudo-destructor expression.
02021   TypeSourceInfo *getDestroyedTypeInfo() const {
02022     return DestroyedType.getTypeSourceInfo();
02023   }
02024 
02025   /// \brief In a dependent pseudo-destructor expression for which we do not
02026   /// have full type information on the destroyed type, provides the name
02027   /// of the destroyed type.
02028   IdentifierInfo *getDestroyedTypeIdentifier() const {
02029     return DestroyedType.getIdentifier();
02030   }
02031 
02032   /// \brief Retrieve the type being destroyed.
02033   QualType getDestroyedType() const;
02034 
02035   /// \brief Retrieve the starting location of the type being destroyed.
02036   SourceLocation getDestroyedTypeLoc() const {
02037     return DestroyedType.getLocation();
02038   }
02039 
02040   /// \brief Set the name of destroyed type for a dependent pseudo-destructor
02041   /// expression.
02042   void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
02043     DestroyedType = PseudoDestructorTypeStorage(II, Loc);
02044   }
02045 
02046   /// \brief Set the destroyed type.
02047   void setDestroyedType(TypeSourceInfo *Info) {
02048     DestroyedType = PseudoDestructorTypeStorage(Info);
02049   }
02050 
02051   SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
02052   SourceLocation getLocEnd() const LLVM_READONLY;
02053 
02054   static bool classof(const Stmt *T) {
02055     return T->getStmtClass() == CXXPseudoDestructorExprClass;
02056   }
02057 
02058   // Iterators
02059   child_range children() { return child_range(&Base, &Base + 1); }
02060 };
02061 
02062 /// \brief A type trait used in the implementation of various C++11 and
02063 /// Library TR1 trait templates.
02064 ///
02065 /// \code
02066 ///   __is_pod(int) == true
02067 ///   __is_enum(std::string) == false
02068 ///   __is_trivially_constructible(vector<int>, int*, int*)
02069 /// \endcode
02070 class TypeTraitExpr : public Expr {
02071   /// \brief The location of the type trait keyword.
02072   SourceLocation Loc;
02073   
02074   /// \brief  The location of the closing parenthesis.
02075   SourceLocation RParenLoc;
02076   
02077   // Note: The TypeSourceInfos for the arguments are allocated after the
02078   // TypeTraitExpr.
02079   
02080   TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
02081                 ArrayRef<TypeSourceInfo *> Args,
02082                 SourceLocation RParenLoc,
02083                 bool Value);
02084 
02085   TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
02086 
02087   /// \brief Retrieve the argument types.
02088   TypeSourceInfo **getTypeSourceInfos() {
02089     return reinterpret_cast<TypeSourceInfo **>(this+1);
02090   }
02091   
02092   /// \brief Retrieve the argument types.
02093   TypeSourceInfo * const *getTypeSourceInfos() const {
02094     return reinterpret_cast<TypeSourceInfo * const*>(this+1);
02095   }
02096   
02097 public:
02098   /// \brief Create a new type trait expression.
02099   static TypeTraitExpr *Create(const ASTContext &C, QualType T,
02100                                SourceLocation Loc, TypeTrait Kind,
02101                                ArrayRef<TypeSourceInfo *> Args,
02102                                SourceLocation RParenLoc,
02103                                bool Value);
02104 
02105   static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
02106                                            unsigned NumArgs);
02107   
02108   /// \brief Determine which type trait this expression uses.
02109   TypeTrait getTrait() const {
02110     return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
02111   }
02112 
02113   bool getValue() const { 
02114     assert(!isValueDependent()); 
02115     return TypeTraitExprBits.Value; 
02116   }
02117   
02118   /// \brief Determine the number of arguments to this type trait.
02119   unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
02120   
02121   /// \brief Retrieve the Ith argument.
02122   TypeSourceInfo *getArg(unsigned I) const {
02123     assert(I < getNumArgs() && "Argument out-of-range");
02124     return getArgs()[I];
02125   }
02126   
02127   /// \brief Retrieve the argument types.
02128   ArrayRef<TypeSourceInfo *> getArgs() const { 
02129     return llvm::makeArrayRef(getTypeSourceInfos(), getNumArgs());
02130   }
02131   
02132   typedef TypeSourceInfo **arg_iterator;
02133   arg_iterator arg_begin() { 
02134     return getTypeSourceInfos(); 
02135   }
02136   arg_iterator arg_end() { 
02137     return getTypeSourceInfos() + getNumArgs(); 
02138   }
02139 
02140   typedef TypeSourceInfo const * const *arg_const_iterator;
02141   arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
02142   arg_const_iterator arg_end() const { 
02143     return getTypeSourceInfos() + getNumArgs(); 
02144   }
02145 
02146   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
02147   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
02148 
02149   static bool classof(const Stmt *T) {
02150     return T->getStmtClass() == TypeTraitExprClass;
02151   }
02152   
02153   // Iterators
02154   child_range children() { return child_range(); }
02155   
02156   friend class ASTStmtReader;
02157   friend class ASTStmtWriter;
02158 
02159 };
02160 
02161 /// \brief An Embarcadero array type trait, as used in the implementation of
02162 /// __array_rank and __array_extent.
02163 ///
02164 /// Example:
02165 /// \code
02166 ///   __array_rank(int[10][20]) == 2
02167 ///   __array_extent(int, 1)    == 20
02168 /// \endcode
02169 class ArrayTypeTraitExpr : public Expr {
02170   virtual void anchor();
02171 
02172   /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
02173   unsigned ATT : 2;
02174 
02175   /// \brief The value of the type trait. Unspecified if dependent.
02176   uint64_t Value;
02177 
02178   /// \brief The array dimension being queried, or -1 if not used.
02179   Expr *Dimension;
02180 
02181   /// \brief The location of the type trait keyword.
02182   SourceLocation Loc;
02183 
02184   /// \brief The location of the closing paren.
02185   SourceLocation RParen;
02186 
02187   /// \brief The type being queried.
02188   TypeSourceInfo *QueriedType;
02189 
02190 public:
02191   ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
02192                      TypeSourceInfo *queried, uint64_t value,
02193                      Expr *dimension, SourceLocation rparen, QualType ty)
02194     : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
02195            false, queried->getType()->isDependentType(),
02196            (queried->getType()->isInstantiationDependentType() ||
02197             (dimension && dimension->isInstantiationDependent())),
02198            queried->getType()->containsUnexpandedParameterPack()),
02199       ATT(att), Value(value), Dimension(dimension),
02200       Loc(loc), RParen(rparen), QueriedType(queried) { }
02201 
02202 
02203   explicit ArrayTypeTraitExpr(EmptyShell Empty)
02204     : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
02205       QueriedType() { }
02206 
02207   virtual ~ArrayTypeTraitExpr() { }
02208 
02209   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
02210   SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
02211 
02212   ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
02213 
02214   QualType getQueriedType() const { return QueriedType->getType(); }
02215 
02216   TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
02217 
02218   uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
02219 
02220   Expr *getDimensionExpression() const { return Dimension; }
02221 
02222   static bool classof(const Stmt *T) {
02223     return T->getStmtClass() == ArrayTypeTraitExprClass;
02224   }
02225 
02226   // Iterators
02227   child_range children() { return child_range(); }
02228 
02229   friend class ASTStmtReader;
02230 };
02231 
02232 /// \brief An expression trait intrinsic.
02233 ///
02234 /// Example:
02235 /// \code
02236 ///   __is_lvalue_expr(std::cout) == true
02237 ///   __is_lvalue_expr(1) == false
02238 /// \endcode
02239 class ExpressionTraitExpr : public Expr {
02240   /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned.
02241   unsigned ET : 31;
02242   /// \brief The value of the type trait. Unspecified if dependent.
02243   bool Value : 1;
02244 
02245   /// \brief The location of the type trait keyword.
02246   SourceLocation Loc;
02247 
02248   /// \brief The location of the closing paren.
02249   SourceLocation RParen;
02250 
02251   /// \brief The expression being queried.
02252   Expr* QueriedExpression;
02253 public:
02254   ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
02255                      Expr *queried, bool value,
02256                      SourceLocation rparen, QualType resultType)
02257     : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
02258            false, // Not type-dependent
02259            // Value-dependent if the argument is type-dependent.
02260            queried->isTypeDependent(),
02261            queried->isInstantiationDependent(),
02262            queried->containsUnexpandedParameterPack()),
02263       ET(et), Value(value), Loc(loc), RParen(rparen),
02264       QueriedExpression(queried) { }
02265 
02266   explicit ExpressionTraitExpr(EmptyShell Empty)
02267     : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
02268       QueriedExpression() { }
02269 
02270   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
02271   SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
02272 
02273   ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
02274 
02275   Expr *getQueriedExpression() const { return QueriedExpression; }
02276 
02277   bool getValue() const { return Value; }
02278 
02279   static bool classof(const Stmt *T) {
02280     return T->getStmtClass() == ExpressionTraitExprClass;
02281   }
02282 
02283   // Iterators
02284   child_range children() { return child_range(); }
02285 
02286   friend class ASTStmtReader;
02287 };
02288 
02289 
02290 /// \brief A reference to an overloaded function set, either an
02291 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
02292 class OverloadExpr : public Expr {
02293   /// \brief The common name of these declarations.
02294   DeclarationNameInfo NameInfo;
02295 
02296   /// \brief The nested-name-specifier that qualifies the name, if any.
02297   NestedNameSpecifierLoc QualifierLoc;
02298 
02299   /// The results.  These are undesugared, which is to say, they may
02300   /// include UsingShadowDecls.  Access is relative to the naming
02301   /// class.
02302   // FIXME: Allocate this data after the OverloadExpr subclass.
02303   DeclAccessPair *Results;
02304   unsigned NumResults;
02305 
02306 protected:
02307   /// \brief Whether the name includes info for explicit template
02308   /// keyword and arguments.
02309   bool HasTemplateKWAndArgsInfo;
02310 
02311   /// \brief Return the optional template keyword and arguments info.
02312   ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
02313 
02314   /// \brief Return the optional template keyword and arguments info.
02315   const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
02316     return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
02317   }
02318 
02319   OverloadExpr(StmtClass K, const ASTContext &C,
02320                NestedNameSpecifierLoc QualifierLoc,
02321                SourceLocation TemplateKWLoc,
02322                const DeclarationNameInfo &NameInfo,
02323                const TemplateArgumentListInfo *TemplateArgs,
02324                UnresolvedSetIterator Begin, UnresolvedSetIterator End,
02325                bool KnownDependent,
02326                bool KnownInstantiationDependent,
02327                bool KnownContainsUnexpandedParameterPack);
02328 
02329   OverloadExpr(StmtClass K, EmptyShell Empty)
02330     : Expr(K, Empty), QualifierLoc(), Results(nullptr), NumResults(0),
02331       HasTemplateKWAndArgsInfo(false) { }
02332 
02333   void initializeResults(const ASTContext &C,
02334                          UnresolvedSetIterator Begin,
02335                          UnresolvedSetIterator End);
02336 
02337 public:
02338   struct FindResult {
02339     OverloadExpr *Expression;
02340     bool IsAddressOfOperand;
02341     bool HasFormOfMemberPointer;
02342   };
02343 
02344   /// \brief Finds the overloaded expression in the given expression \p E of
02345   /// OverloadTy.
02346   ///
02347   /// \return the expression (which must be there) and true if it has
02348   /// the particular form of a member pointer expression
02349   static FindResult find(Expr *E) {
02350     assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
02351 
02352     FindResult Result;
02353 
02354     E = E->IgnoreParens();
02355     if (isa<UnaryOperator>(E)) {
02356       assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
02357       E = cast<UnaryOperator>(E)->getSubExpr();
02358       OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
02359 
02360       Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
02361       Result.IsAddressOfOperand = true;
02362       Result.Expression = Ovl;
02363     } else {
02364       Result.HasFormOfMemberPointer = false;
02365       Result.IsAddressOfOperand = false;
02366       Result.Expression = cast<OverloadExpr>(E);
02367     }
02368 
02369     return Result;
02370   }
02371 
02372   /// \brief Gets the naming class of this lookup, if any.
02373   CXXRecordDecl *getNamingClass() const;
02374 
02375   typedef UnresolvedSetImpl::iterator decls_iterator;
02376   decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
02377   decls_iterator decls_end() const {
02378     return UnresolvedSetIterator(Results + NumResults);
02379   }
02380   llvm::iterator_range<decls_iterator> decls() const {
02381     return llvm::iterator_range<decls_iterator>(decls_begin(), decls_end());
02382   }
02383 
02384   /// \brief Gets the number of declarations in the unresolved set.
02385   unsigned getNumDecls() const { return NumResults; }
02386 
02387   /// \brief Gets the full name info.
02388   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
02389 
02390   /// \brief Gets the name looked up.
02391   DeclarationName getName() const { return NameInfo.getName(); }
02392 
02393   /// \brief Gets the location of the name.
02394   SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
02395 
02396   /// \brief Fetches the nested-name qualifier, if one was given.
02397   NestedNameSpecifier *getQualifier() const {
02398     return QualifierLoc.getNestedNameSpecifier();
02399   }
02400 
02401   /// \brief Fetches the nested-name qualifier with source-location
02402   /// information, if one was given.
02403   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
02404 
02405   /// \brief Retrieve the location of the template keyword preceding
02406   /// this name, if any.
02407   SourceLocation getTemplateKeywordLoc() const {
02408     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
02409     return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
02410   }
02411 
02412   /// \brief Retrieve the location of the left angle bracket starting the
02413   /// explicit template argument list following the name, if any.
02414   SourceLocation getLAngleLoc() const {
02415     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
02416     return getTemplateKWAndArgsInfo()->LAngleLoc;
02417   }
02418 
02419   /// \brief Retrieve the location of the right angle bracket ending the
02420   /// explicit template argument list following the name, if any.
02421   SourceLocation getRAngleLoc() const {
02422     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
02423     return getTemplateKWAndArgsInfo()->RAngleLoc;
02424   }
02425 
02426   /// \brief Determines whether the name was preceded by the template keyword.
02427   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
02428 
02429   /// \brief Determines whether this expression had explicit template arguments.
02430   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
02431 
02432   // Note that, inconsistently with the explicit-template-argument AST
02433   // nodes, users are *forbidden* from calling these methods on objects
02434   // without explicit template arguments.
02435 
02436   ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
02437     assert(hasExplicitTemplateArgs());
02438     return *getTemplateKWAndArgsInfo();
02439   }
02440 
02441   const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
02442     return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
02443   }
02444 
02445   TemplateArgumentLoc const *getTemplateArgs() const {
02446     return getExplicitTemplateArgs().getTemplateArgs();
02447   }
02448 
02449   unsigned getNumTemplateArgs() const {
02450     return getExplicitTemplateArgs().NumTemplateArgs;
02451   }
02452 
02453   /// \brief Copies the template arguments into the given structure.
02454   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
02455     getExplicitTemplateArgs().copyInto(List);
02456   }
02457 
02458   /// \brief Retrieves the optional explicit template arguments.
02459   ///
02460   /// This points to the same data as getExplicitTemplateArgs(), but
02461   /// returns null if there are no explicit template arguments.
02462   const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
02463     if (!hasExplicitTemplateArgs()) return nullptr;
02464     return &getExplicitTemplateArgs();
02465   }
02466 
02467   static bool classof(const Stmt *T) {
02468     return T->getStmtClass() == UnresolvedLookupExprClass ||
02469            T->getStmtClass() == UnresolvedMemberExprClass;
02470   }
02471 
02472   friend class ASTStmtReader;
02473   friend class ASTStmtWriter;
02474 };
02475 
02476 /// \brief A reference to a name which we were able to look up during
02477 /// parsing but could not resolve to a specific declaration.
02478 ///
02479 /// This arises in several ways:
02480 ///   * we might be waiting for argument-dependent lookup;
02481 ///   * the name might resolve to an overloaded function;
02482 /// and eventually:
02483 ///   * the lookup might have included a function template.
02484 ///
02485 /// These never include UnresolvedUsingValueDecls, which are always class
02486 /// members and therefore appear only in UnresolvedMemberLookupExprs.
02487 class UnresolvedLookupExpr : public OverloadExpr {
02488   /// True if these lookup results should be extended by
02489   /// argument-dependent lookup if this is the operand of a function
02490   /// call.
02491   bool RequiresADL;
02492 
02493   /// True if these lookup results are overloaded.  This is pretty
02494   /// trivially rederivable if we urgently need to kill this field.
02495   bool Overloaded;
02496 
02497   /// The naming class (C++ [class.access.base]p5) of the lookup, if
02498   /// any.  This can generally be recalculated from the context chain,
02499   /// but that can be fairly expensive for unqualified lookups.  If we
02500   /// want to improve memory use here, this could go in a union
02501   /// against the qualified-lookup bits.
02502   CXXRecordDecl *NamingClass;
02503 
02504   UnresolvedLookupExpr(const ASTContext &C,
02505                        CXXRecordDecl *NamingClass,
02506                        NestedNameSpecifierLoc QualifierLoc,
02507                        SourceLocation TemplateKWLoc,
02508                        const DeclarationNameInfo &NameInfo,
02509                        bool RequiresADL, bool Overloaded,
02510                        const TemplateArgumentListInfo *TemplateArgs,
02511                        UnresolvedSetIterator Begin, UnresolvedSetIterator End)
02512     : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
02513                    NameInfo, TemplateArgs, Begin, End, false, false, false),
02514       RequiresADL(RequiresADL),
02515       Overloaded(Overloaded), NamingClass(NamingClass)
02516   {}
02517 
02518   UnresolvedLookupExpr(EmptyShell Empty)
02519     : OverloadExpr(UnresolvedLookupExprClass, Empty),
02520       RequiresADL(false), Overloaded(false), NamingClass(nullptr)
02521   {}
02522 
02523   friend class ASTStmtReader;
02524 
02525 public:
02526   static UnresolvedLookupExpr *Create(const ASTContext &C,
02527                                       CXXRecordDecl *NamingClass,
02528                                       NestedNameSpecifierLoc QualifierLoc,
02529                                       const DeclarationNameInfo &NameInfo,
02530                                       bool ADL, bool Overloaded,
02531                                       UnresolvedSetIterator Begin,
02532                                       UnresolvedSetIterator End) {
02533     return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
02534                                        SourceLocation(), NameInfo,
02535                                        ADL, Overloaded, nullptr, Begin, End);
02536   }
02537 
02538   static UnresolvedLookupExpr *Create(const ASTContext &C,
02539                                       CXXRecordDecl *NamingClass,
02540                                       NestedNameSpecifierLoc QualifierLoc,
02541                                       SourceLocation TemplateKWLoc,
02542                                       const DeclarationNameInfo &NameInfo,
02543                                       bool ADL,
02544                                       const TemplateArgumentListInfo *Args,
02545                                       UnresolvedSetIterator Begin,
02546                                       UnresolvedSetIterator End);
02547 
02548   static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C,
02549                                            bool HasTemplateKWAndArgsInfo,
02550                                            unsigned NumTemplateArgs);
02551 
02552   /// True if this declaration should be extended by
02553   /// argument-dependent lookup.
02554   bool requiresADL() const { return RequiresADL; }
02555 
02556   /// True if this lookup is overloaded.
02557   bool isOverloaded() const { return Overloaded; }
02558 
02559   /// Gets the 'naming class' (in the sense of C++0x
02560   /// [class.access.base]p5) of the lookup.  This is the scope
02561   /// that was looked in to find these results.
02562   CXXRecordDecl *getNamingClass() const { return NamingClass; }
02563 
02564   SourceLocation getLocStart() const LLVM_READONLY {
02565     if (NestedNameSpecifierLoc l = getQualifierLoc())
02566       return l.getBeginLoc();
02567     return getNameInfo().getLocStart();
02568   }
02569   SourceLocation getLocEnd() const LLVM_READONLY {
02570     if (hasExplicitTemplateArgs())
02571       return getRAngleLoc();
02572     return getNameInfo().getLocEnd();
02573   }
02574 
02575   child_range children() { return child_range(); }
02576 
02577   static bool classof(const Stmt *T) {
02578     return T->getStmtClass() == UnresolvedLookupExprClass;
02579   }
02580 };
02581 
02582 /// \brief A qualified reference to a name whose declaration cannot
02583 /// yet be resolved.
02584 ///
02585 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
02586 /// it expresses a reference to a declaration such as
02587 /// X<T>::value. The difference, however, is that an
02588 /// DependentScopeDeclRefExpr node is used only within C++ templates when
02589 /// the qualification (e.g., X<T>::) refers to a dependent type. In
02590 /// this case, X<T>::value cannot resolve to a declaration because the
02591 /// declaration will differ from one instantiation of X<T> to the
02592 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
02593 /// qualifier (X<T>::) and the name of the entity being referenced
02594 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
02595 /// declaration can be found.
02596 class DependentScopeDeclRefExpr : public Expr {
02597   /// \brief The nested-name-specifier that qualifies this unresolved
02598   /// declaration name.
02599   NestedNameSpecifierLoc QualifierLoc;
02600 
02601   /// \brief The name of the entity we will be referencing.
02602   DeclarationNameInfo NameInfo;
02603 
02604   /// \brief Whether the name includes info for explicit template
02605   /// keyword and arguments.
02606   bool HasTemplateKWAndArgsInfo;
02607 
02608   /// \brief Return the optional template keyword and arguments info.
02609   ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
02610     if (!HasTemplateKWAndArgsInfo) return nullptr;
02611     return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
02612   }
02613   /// \brief Return the optional template keyword and arguments info.
02614   const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
02615     return const_cast<DependentScopeDeclRefExpr*>(this)
02616       ->getTemplateKWAndArgsInfo();
02617   }
02618 
02619   DependentScopeDeclRefExpr(QualType T,
02620                             NestedNameSpecifierLoc QualifierLoc,
02621                             SourceLocation TemplateKWLoc,
02622                             const DeclarationNameInfo &NameInfo,
02623                             const TemplateArgumentListInfo *Args);
02624 
02625 public:
02626   static DependentScopeDeclRefExpr *Create(const ASTContext &C,
02627                                            NestedNameSpecifierLoc QualifierLoc,
02628                                            SourceLocation TemplateKWLoc,
02629                                            const DeclarationNameInfo &NameInfo,
02630                               const TemplateArgumentListInfo *TemplateArgs);
02631 
02632   static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C,
02633                                                 bool HasTemplateKWAndArgsInfo,
02634                                                 unsigned NumTemplateArgs);
02635 
02636   /// \brief Retrieve the name that this expression refers to.
02637   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
02638 
02639   /// \brief Retrieve the name that this expression refers to.
02640   DeclarationName getDeclName() const { return NameInfo.getName(); }
02641 
02642   /// \brief Retrieve the location of the name within the expression.
02643   ///
02644   /// For example, in "X<T>::value" this is the location of "value".
02645   SourceLocation getLocation() const { return NameInfo.getLoc(); }
02646 
02647   /// \brief Retrieve the nested-name-specifier that qualifies the
02648   /// name, with source location information.
02649   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
02650 
02651   /// \brief Retrieve the nested-name-specifier that qualifies this
02652   /// declaration.
02653   NestedNameSpecifier *getQualifier() const {
02654     return QualifierLoc.getNestedNameSpecifier();
02655   }
02656 
02657   /// \brief Retrieve the location of the template keyword preceding
02658   /// this name, if any.
02659   SourceLocation getTemplateKeywordLoc() const {
02660     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
02661     return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
02662   }
02663 
02664   /// \brief Retrieve the location of the left angle bracket starting the
02665   /// explicit template argument list following the name, if any.
02666   SourceLocation getLAngleLoc() const {
02667     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
02668     return getTemplateKWAndArgsInfo()->LAngleLoc;
02669   }
02670 
02671   /// \brief Retrieve the location of the right angle bracket ending the
02672   /// explicit template argument list following the name, if any.
02673   SourceLocation getRAngleLoc() const {
02674     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
02675     return getTemplateKWAndArgsInfo()->RAngleLoc;
02676   }
02677 
02678   /// Determines whether the name was preceded by the template keyword.
02679   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
02680 
02681   /// Determines whether this lookup had explicit template arguments.
02682   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
02683 
02684   // Note that, inconsistently with the explicit-template-argument AST
02685   // nodes, users are *forbidden* from calling these methods on objects
02686   // without explicit template arguments.
02687 
02688   ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
02689     assert(hasExplicitTemplateArgs());
02690     return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
02691   }
02692 
02693   /// Gets a reference to the explicit template argument list.
02694   const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
02695     assert(hasExplicitTemplateArgs());
02696     return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
02697   }
02698 
02699   /// \brief Retrieves the optional explicit template arguments.
02700   ///
02701   /// This points to the same data as getExplicitTemplateArgs(), but
02702   /// returns null if there are no explicit template arguments.
02703   const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
02704     if (!hasExplicitTemplateArgs()) return nullptr;
02705     return &getExplicitTemplateArgs();
02706   }
02707 
02708   /// \brief Copies the template arguments (if present) into the given
02709   /// structure.
02710   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
02711     getExplicitTemplateArgs().copyInto(List);
02712   }
02713 
02714   TemplateArgumentLoc const *getTemplateArgs() const {
02715     return getExplicitTemplateArgs().getTemplateArgs();
02716   }
02717 
02718   unsigned getNumTemplateArgs() const {
02719     return getExplicitTemplateArgs().NumTemplateArgs;
02720   }
02721 
02722   /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr,
02723   /// and differs from getLocation().getStart().
02724   SourceLocation getLocStart() const LLVM_READONLY {
02725     return QualifierLoc.getBeginLoc();
02726   }
02727   SourceLocation getLocEnd() const LLVM_READONLY {
02728     if (hasExplicitTemplateArgs())
02729       return getRAngleLoc();
02730     return getLocation();
02731   }
02732 
02733   static bool classof(const Stmt *T) {
02734     return T->getStmtClass() == DependentScopeDeclRefExprClass;
02735   }
02736 
02737   child_range children() { return child_range(); }
02738 
02739   friend class ASTStmtReader;
02740   friend class ASTStmtWriter;
02741 };
02742 
02743 /// Represents an expression -- generally a full-expression -- that
02744 /// introduces cleanups to be run at the end of the sub-expression's
02745 /// evaluation.  The most common source of expression-introduced
02746 /// cleanups is temporary objects in C++, but several other kinds of
02747 /// expressions can create cleanups, including basically every
02748 /// call in ARC that returns an Objective-C pointer.
02749 ///
02750 /// This expression also tracks whether the sub-expression contains a
02751 /// potentially-evaluated block literal.  The lifetime of a block
02752 /// literal is the extent of the enclosing scope.
02753 class ExprWithCleanups : public Expr {
02754 public:
02755   /// The type of objects that are kept in the cleanup.
02756   /// It's useful to remember the set of blocks;  we could also
02757   /// remember the set of temporaries, but there's currently
02758   /// no need.
02759   typedef BlockDecl *CleanupObject;
02760 
02761 private:
02762   Stmt *SubExpr;
02763 
02764   ExprWithCleanups(EmptyShell, unsigned NumObjects);
02765   ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
02766 
02767   CleanupObject *getObjectsBuffer() {
02768     return reinterpret_cast<CleanupObject*>(this + 1);
02769   }
02770   const CleanupObject *getObjectsBuffer() const {
02771     return reinterpret_cast<const CleanupObject*>(this + 1);
02772   }
02773   friend class ASTStmtReader;
02774 
02775 public:
02776   static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
02777                                   unsigned numObjects);
02778 
02779   static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
02780                                   ArrayRef<CleanupObject> objects);
02781 
02782   ArrayRef<CleanupObject> getObjects() const {
02783     return llvm::makeArrayRef(getObjectsBuffer(), getNumObjects());
02784   }
02785 
02786   unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
02787 
02788   CleanupObject getObject(unsigned i) const {
02789     assert(i < getNumObjects() && "Index out of range");
02790     return getObjects()[i];
02791   }
02792 
02793   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
02794   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
02795 
02796   /// As with any mutator of the AST, be very careful
02797   /// when modifying an existing AST to preserve its invariants.
02798   void setSubExpr(Expr *E) { SubExpr = E; }
02799 
02800   SourceLocation getLocStart() const LLVM_READONLY {
02801     return SubExpr->getLocStart();
02802   }
02803   SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
02804 
02805   // Implement isa/cast/dyncast/etc.
02806   static bool classof(const Stmt *T) {
02807     return T->getStmtClass() == ExprWithCleanupsClass;
02808   }
02809 
02810   // Iterators
02811   child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
02812 };
02813 
02814 /// \brief Describes an explicit type conversion that uses functional
02815 /// notion but could not be resolved because one or more arguments are
02816 /// type-dependent.
02817 ///
02818 /// The explicit type conversions expressed by
02819 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
02820 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
02821 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
02822 /// type-dependent. For example, this would occur in a template such
02823 /// as:
02824 ///
02825 /// \code
02826 ///   template<typename T, typename A1>
02827 ///   inline T make_a(const A1& a1) {
02828 ///     return T(a1);
02829 ///   }
02830 /// \endcode
02831 ///
02832 /// When the returned expression is instantiated, it may resolve to a
02833 /// constructor call, conversion function call, or some kind of type
02834 /// conversion.
02835 class CXXUnresolvedConstructExpr : public Expr {
02836   /// \brief The type being constructed.
02837   TypeSourceInfo *Type;
02838 
02839   /// \brief The location of the left parentheses ('(').
02840   SourceLocation LParenLoc;
02841 
02842   /// \brief The location of the right parentheses (')').
02843   SourceLocation RParenLoc;
02844 
02845   /// \brief The number of arguments used to construct the type.
02846   unsigned NumArgs;
02847 
02848   CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
02849                              SourceLocation LParenLoc,
02850                              ArrayRef<Expr*> Args,
02851                              SourceLocation RParenLoc);
02852 
02853   CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
02854     : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
02855 
02856   friend class ASTStmtReader;
02857 
02858 public:
02859   static CXXUnresolvedConstructExpr *Create(const ASTContext &C,
02860                                             TypeSourceInfo *Type,
02861                                             SourceLocation LParenLoc,
02862                                             ArrayRef<Expr*> Args,
02863                                             SourceLocation RParenLoc);
02864 
02865   static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C,
02866                                                  unsigned NumArgs);
02867 
02868   /// \brief Retrieve the type that is being constructed, as specified
02869   /// in the source code.
02870   QualType getTypeAsWritten() const { return Type->getType(); }
02871 
02872   /// \brief Retrieve the type source information for the type being
02873   /// constructed.
02874   TypeSourceInfo *getTypeSourceInfo() const { return Type; }
02875 
02876   /// \brief Retrieve the location of the left parentheses ('(') that
02877   /// precedes the argument list.
02878   SourceLocation getLParenLoc() const { return LParenLoc; }
02879   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
02880 
02881   /// \brief Retrieve the location of the right parentheses (')') that
02882   /// follows the argument list.
02883   SourceLocation getRParenLoc() const { return RParenLoc; }
02884   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
02885 
02886   /// \brief Retrieve the number of arguments.
02887   unsigned arg_size() const { return NumArgs; }
02888 
02889   typedef Expr** arg_iterator;
02890   arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
02891   arg_iterator arg_end() { return arg_begin() + NumArgs; }
02892 
02893   typedef const Expr* const * const_arg_iterator;
02894   const_arg_iterator arg_begin() const {
02895     return reinterpret_cast<const Expr* const *>(this + 1);
02896   }
02897   const_arg_iterator arg_end() const {
02898     return arg_begin() + NumArgs;
02899   }
02900 
02901   Expr *getArg(unsigned I) {
02902     assert(I < NumArgs && "Argument index out-of-range");
02903     return *(arg_begin() + I);
02904   }
02905 
02906   const Expr *getArg(unsigned I) const {
02907     assert(I < NumArgs && "Argument index out-of-range");
02908     return *(arg_begin() + I);
02909   }
02910 
02911   void setArg(unsigned I, Expr *E) {
02912     assert(I < NumArgs && "Argument index out-of-range");
02913     *(arg_begin() + I) = E;
02914   }
02915 
02916   SourceLocation getLocStart() const LLVM_READONLY;
02917   SourceLocation getLocEnd() const LLVM_READONLY {
02918     assert(RParenLoc.isValid() || NumArgs == 1);
02919     return RParenLoc.isValid() ? RParenLoc : getArg(0)->getLocEnd();
02920   }
02921 
02922   static bool classof(const Stmt *T) {
02923     return T->getStmtClass() == CXXUnresolvedConstructExprClass;
02924   }
02925 
02926   // Iterators
02927   child_range children() {
02928     Stmt **begin = reinterpret_cast<Stmt**>(this+1);
02929     return child_range(begin, begin + NumArgs);
02930   }
02931 };
02932 
02933 /// \brief Represents a C++ member access expression where the actual
02934 /// member referenced could not be resolved because the base
02935 /// expression or the member name was dependent.
02936 ///
02937 /// Like UnresolvedMemberExprs, these can be either implicit or
02938 /// explicit accesses.  It is only possible to get one of these with
02939 /// an implicit access if a qualifier is provided.
02940 class CXXDependentScopeMemberExpr : public Expr {
02941   /// \brief The expression for the base pointer or class reference,
02942   /// e.g., the \c x in x.f.  Can be null in implicit accesses.
02943   Stmt *Base;
02944 
02945   /// \brief The type of the base expression.  Never null, even for
02946   /// implicit accesses.
02947   QualType BaseType;
02948 
02949   /// \brief Whether this member expression used the '->' operator or
02950   /// the '.' operator.
02951   bool IsArrow : 1;
02952 
02953   /// \brief Whether this member expression has info for explicit template
02954   /// keyword and arguments.
02955   bool HasTemplateKWAndArgsInfo : 1;
02956 
02957   /// \brief The location of the '->' or '.' operator.
02958   SourceLocation OperatorLoc;
02959 
02960   /// \brief The nested-name-specifier that precedes the member name, if any.
02961   NestedNameSpecifierLoc QualifierLoc;
02962 
02963   /// \brief In a qualified member access expression such as t->Base::f, this
02964   /// member stores the resolves of name lookup in the context of the member
02965   /// access expression, to be used at instantiation time.
02966   ///
02967   /// FIXME: This member, along with the QualifierLoc, could
02968   /// be stuck into a structure that is optionally allocated at the end of
02969   /// the CXXDependentScopeMemberExpr, to save space in the common case.
02970   NamedDecl *FirstQualifierFoundInScope;
02971 
02972   /// \brief The member to which this member expression refers, which
02973   /// can be name, overloaded operator, or destructor.
02974   ///
02975   /// FIXME: could also be a template-id
02976   DeclarationNameInfo MemberNameInfo;
02977 
02978   /// \brief Return the optional template keyword and arguments info.
02979   ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
02980     if (!HasTemplateKWAndArgsInfo) return nullptr;
02981     return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
02982   }
02983   /// \brief Return the optional template keyword and arguments info.
02984   const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
02985     return const_cast<CXXDependentScopeMemberExpr*>(this)
02986       ->getTemplateKWAndArgsInfo();
02987   }
02988 
02989   CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
02990                               QualType BaseType, bool IsArrow,
02991                               SourceLocation OperatorLoc,
02992                               NestedNameSpecifierLoc QualifierLoc,
02993                               SourceLocation TemplateKWLoc,
02994                               NamedDecl *FirstQualifierFoundInScope,
02995                               DeclarationNameInfo MemberNameInfo,
02996                               const TemplateArgumentListInfo *TemplateArgs);
02997 
02998 public:
02999   CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
03000                               QualType BaseType, bool IsArrow,
03001                               SourceLocation OperatorLoc,
03002                               NestedNameSpecifierLoc QualifierLoc,
03003                               NamedDecl *FirstQualifierFoundInScope,
03004                               DeclarationNameInfo MemberNameInfo);
03005 
03006   static CXXDependentScopeMemberExpr *
03007   Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
03008          SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
03009          SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
03010          DeclarationNameInfo MemberNameInfo,
03011          const TemplateArgumentListInfo *TemplateArgs);
03012 
03013   static CXXDependentScopeMemberExpr *
03014   CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
03015               unsigned NumTemplateArgs);
03016 
03017   /// \brief True if this is an implicit access, i.e. one in which the
03018   /// member being accessed was not written in the source.  The source
03019   /// location of the operator is invalid in this case.
03020   bool isImplicitAccess() const;
03021 
03022   /// \brief Retrieve the base object of this member expressions,
03023   /// e.g., the \c x in \c x.m.
03024   Expr *getBase() const {
03025     assert(!isImplicitAccess());
03026     return cast<Expr>(Base);
03027   }
03028 
03029   QualType getBaseType() const { return BaseType; }
03030 
03031   /// \brief Determine whether this member expression used the '->'
03032   /// operator; otherwise, it used the '.' operator.
03033   bool isArrow() const { return IsArrow; }
03034 
03035   /// \brief Retrieve the location of the '->' or '.' operator.
03036   SourceLocation getOperatorLoc() const { return OperatorLoc; }
03037 
03038   /// \brief Retrieve the nested-name-specifier that qualifies the member
03039   /// name.
03040   NestedNameSpecifier *getQualifier() const {
03041     return QualifierLoc.getNestedNameSpecifier();
03042   }
03043 
03044   /// \brief Retrieve the nested-name-specifier that qualifies the member
03045   /// name, with source location information.
03046   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
03047 
03048 
03049   /// \brief Retrieve the first part of the nested-name-specifier that was
03050   /// found in the scope of the member access expression when the member access
03051   /// was initially parsed.
03052   ///
03053   /// This function only returns a useful result when member access expression
03054   /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
03055   /// returned by this function describes what was found by unqualified name
03056   /// lookup for the identifier "Base" within the scope of the member access
03057   /// expression itself. At template instantiation time, this information is
03058   /// combined with the results of name lookup into the type of the object
03059   /// expression itself (the class type of x).
03060   NamedDecl *getFirstQualifierFoundInScope() const {
03061     return FirstQualifierFoundInScope;
03062   }
03063 
03064   /// \brief Retrieve the name of the member that this expression
03065   /// refers to.
03066   const DeclarationNameInfo &getMemberNameInfo() const {
03067     return MemberNameInfo;
03068   }
03069 
03070   /// \brief Retrieve the name of the member that this expression
03071   /// refers to.
03072   DeclarationName getMember() const { return MemberNameInfo.getName(); }
03073 
03074   // \brief Retrieve the location of the name of the member that this
03075   // expression refers to.
03076   SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
03077 
03078   /// \brief Retrieve the location of the template keyword preceding the
03079   /// member name, if any.
03080   SourceLocation getTemplateKeywordLoc() const {
03081     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
03082     return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
03083   }
03084 
03085   /// \brief Retrieve the location of the left angle bracket starting the
03086   /// explicit template argument list following the member name, if any.
03087   SourceLocation getLAngleLoc() const {
03088     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
03089     return getTemplateKWAndArgsInfo()->LAngleLoc;
03090   }
03091 
03092   /// \brief Retrieve the location of the right angle bracket ending the
03093   /// explicit template argument list following the member name, if any.
03094   SourceLocation getRAngleLoc() const {
03095     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
03096     return getTemplateKWAndArgsInfo()->RAngleLoc;
03097   }
03098 
03099   /// Determines whether the member name was preceded by the template keyword.
03100   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
03101 
03102   /// \brief Determines whether this member expression actually had a C++
03103   /// template argument list explicitly specified, e.g., x.f<int>.
03104   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
03105 
03106   /// \brief Retrieve the explicit template argument list that followed the
03107   /// member template name, if any.
03108   ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
03109     assert(hasExplicitTemplateArgs());
03110     return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
03111   }
03112 
03113   /// \brief Retrieve the explicit template argument list that followed the
03114   /// member template name, if any.
03115   const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
03116     return const_cast<CXXDependentScopeMemberExpr *>(this)
03117              ->getExplicitTemplateArgs();
03118   }
03119 
03120   /// \brief Retrieves the optional explicit template arguments.
03121   ///
03122   /// This points to the same data as getExplicitTemplateArgs(), but
03123   /// returns null if there are no explicit template arguments.
03124   const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
03125     if (!hasExplicitTemplateArgs()) return nullptr;
03126     return &getExplicitTemplateArgs();
03127   }
03128 
03129   /// \brief Copies the template arguments (if present) into the given
03130   /// structure.
03131   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
03132     getExplicitTemplateArgs().copyInto(List);
03133   }
03134 
03135   /// \brief Initializes the template arguments using the given structure.
03136   void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
03137     getExplicitTemplateArgs().initializeFrom(List);
03138   }
03139 
03140   /// \brief Retrieve the template arguments provided as part of this
03141   /// template-id.
03142   const TemplateArgumentLoc *getTemplateArgs() const {
03143     return getExplicitTemplateArgs().getTemplateArgs();
03144   }
03145 
03146   /// \brief Retrieve the number of template arguments provided as part of this
03147   /// template-id.
03148   unsigned getNumTemplateArgs() const {
03149     return getExplicitTemplateArgs().NumTemplateArgs;
03150   }
03151 
03152   SourceLocation getLocStart() const LLVM_READONLY {
03153     if (!isImplicitAccess())
03154       return Base->getLocStart();
03155     if (getQualifier())
03156       return getQualifierLoc().getBeginLoc();
03157     return MemberNameInfo.getBeginLoc();
03158 
03159   }
03160   SourceLocation getLocEnd() const LLVM_READONLY {
03161     if (hasExplicitTemplateArgs())
03162       return getRAngleLoc();
03163     return MemberNameInfo.getEndLoc();
03164   }
03165 
03166   static bool classof(const Stmt *T) {
03167     return T->getStmtClass() == CXXDependentScopeMemberExprClass;
03168   }
03169 
03170   // Iterators
03171   child_range children() {
03172     if (isImplicitAccess()) return child_range();
03173     return child_range(&Base, &Base + 1);
03174   }
03175 
03176   friend class ASTStmtReader;
03177   friend class ASTStmtWriter;
03178 };
03179 
03180 /// \brief Represents a C++ member access expression for which lookup
03181 /// produced a set of overloaded functions.
03182 ///
03183 /// The member access may be explicit or implicit:
03184 /// \code
03185 ///    struct A {
03186 ///      int a, b;
03187 ///      int explicitAccess() { return this->a + this->A::b; }
03188 ///      int implicitAccess() { return a + A::b; }
03189 ///    };
03190 /// \endcode
03191 ///
03192 /// In the final AST, an explicit access always becomes a MemberExpr.
03193 /// An implicit access may become either a MemberExpr or a
03194 /// DeclRefExpr, depending on whether the member is static.
03195 class UnresolvedMemberExpr : public OverloadExpr {
03196   /// \brief Whether this member expression used the '->' operator or
03197   /// the '.' operator.
03198   bool IsArrow : 1;
03199 
03200   /// \brief Whether the lookup results contain an unresolved using
03201   /// declaration.
03202   bool HasUnresolvedUsing : 1;
03203 
03204   /// \brief The expression for the base pointer or class reference,
03205   /// e.g., the \c x in x.f.
03206   ///
03207   /// This can be null if this is an 'unbased' member expression.
03208   Stmt *Base;
03209 
03210   /// \brief The type of the base expression; never null.
03211   QualType BaseType;
03212 
03213   /// \brief The location of the '->' or '.' operator.
03214   SourceLocation OperatorLoc;
03215 
03216   UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing,
03217                        Expr *Base, QualType BaseType, bool IsArrow,
03218                        SourceLocation OperatorLoc,
03219                        NestedNameSpecifierLoc QualifierLoc,
03220                        SourceLocation TemplateKWLoc,
03221                        const DeclarationNameInfo &MemberNameInfo,
03222                        const TemplateArgumentListInfo *TemplateArgs,
03223                        UnresolvedSetIterator Begin, UnresolvedSetIterator End);
03224 
03225   UnresolvedMemberExpr(EmptyShell Empty)
03226     : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
03227       HasUnresolvedUsing(false), Base(nullptr) { }
03228 
03229   friend class ASTStmtReader;
03230 
03231 public:
03232   static UnresolvedMemberExpr *
03233   Create(const ASTContext &C, bool HasUnresolvedUsing,
03234          Expr *Base, QualType BaseType, bool IsArrow,
03235          SourceLocation OperatorLoc,
03236          NestedNameSpecifierLoc QualifierLoc,
03237          SourceLocation TemplateKWLoc,
03238          const DeclarationNameInfo &MemberNameInfo,
03239          const TemplateArgumentListInfo *TemplateArgs,
03240          UnresolvedSetIterator Begin, UnresolvedSetIterator End);
03241 
03242   static UnresolvedMemberExpr *
03243   CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
03244               unsigned NumTemplateArgs);
03245 
03246   /// \brief True if this is an implicit access, i.e., one in which the
03247   /// member being accessed was not written in the source.
03248   ///
03249   /// The source location of the operator is invalid in this case.
03250   bool isImplicitAccess() const;
03251 
03252   /// \brief Retrieve the base object of this member expressions,
03253   /// e.g., the \c x in \c x.m.
03254   Expr *getBase() {
03255     assert(!isImplicitAccess());
03256     return cast<Expr>(Base);
03257   }
03258   const Expr *getBase() const {
03259     assert(!isImplicitAccess());
03260     return cast<Expr>(Base);
03261   }
03262 
03263   QualType getBaseType() const { return BaseType; }
03264 
03265   /// \brief Determine whether the lookup results contain an unresolved using
03266   /// declaration.
03267   bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
03268 
03269   /// \brief Determine whether this member expression used the '->'
03270   /// operator; otherwise, it used the '.' operator.
03271   bool isArrow() const { return IsArrow; }
03272 
03273   /// \brief Retrieve the location of the '->' or '.' operator.
03274   SourceLocation getOperatorLoc() const { return OperatorLoc; }
03275 
03276   /// \brief Retrieve the naming class of this lookup.
03277   CXXRecordDecl *getNamingClass() const;
03278 
03279   /// \brief Retrieve the full name info for the member that this expression
03280   /// refers to.
03281   const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
03282 
03283   /// \brief Retrieve the name of the member that this expression
03284   /// refers to.
03285   DeclarationName getMemberName() const { return getName(); }
03286 
03287   // \brief Retrieve the location of the name of the member that this
03288   // expression refers to.
03289   SourceLocation getMemberLoc() const { return getNameLoc(); }
03290 
03291   // \brief Return the preferred location (the member name) for the arrow when
03292   // diagnosing a problem with this expression.
03293   SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
03294 
03295   SourceLocation getLocStart() const LLVM_READONLY {
03296     if (!isImplicitAccess())
03297       return Base->getLocStart();
03298     if (NestedNameSpecifierLoc l = getQualifierLoc())
03299       return l.getBeginLoc();
03300     return getMemberNameInfo().getLocStart();
03301   }
03302   SourceLocation getLocEnd() const LLVM_READONLY {
03303     if (hasExplicitTemplateArgs())
03304       return getRAngleLoc();
03305     return getMemberNameInfo().getLocEnd();
03306   }
03307 
03308   static bool classof(const Stmt *T) {
03309     return T->getStmtClass() == UnresolvedMemberExprClass;
03310   }
03311 
03312   // Iterators
03313   child_range children() {
03314     if (isImplicitAccess()) return child_range();
03315     return child_range(&Base, &Base + 1);
03316   }
03317 };
03318 
03319 /// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
03320 ///
03321 /// The noexcept expression tests whether a given expression might throw. Its
03322 /// result is a boolean constant.
03323 class CXXNoexceptExpr : public Expr {
03324   bool Value : 1;
03325   Stmt *Operand;
03326   SourceRange Range;
03327 
03328   friend class ASTStmtReader;
03329 
03330 public:
03331   CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
03332                   SourceLocation Keyword, SourceLocation RParen)
03333     : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
03334            /*TypeDependent*/false,
03335            /*ValueDependent*/Val == CT_Dependent,
03336            Val == CT_Dependent || Operand->isInstantiationDependent(),
03337            Operand->containsUnexpandedParameterPack()),
03338       Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
03339   { }
03340 
03341   CXXNoexceptExpr(EmptyShell Empty)
03342     : Expr(CXXNoexceptExprClass, Empty)
03343   { }
03344 
03345   Expr *getOperand() const { return static_cast<Expr*>(Operand); }
03346 
03347   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
03348   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
03349   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
03350 
03351   bool getValue() const { return Value; }
03352 
03353   static bool classof(const Stmt *T) {
03354     return T->getStmtClass() == CXXNoexceptExprClass;
03355   }
03356 
03357   // Iterators
03358   child_range children() { return child_range(&Operand, &Operand + 1); }
03359 };
03360 
03361 /// \brief Represents a C++11 pack expansion that produces a sequence of
03362 /// expressions.
03363 ///
03364 /// A pack expansion expression contains a pattern (which itself is an
03365 /// expression) followed by an ellipsis. For example:
03366 ///
03367 /// \code
03368 /// template<typename F, typename ...Types>
03369 /// void forward(F f, Types &&...args) {
03370 ///   f(static_cast<Types&&>(args)...);
03371 /// }
03372 /// \endcode
03373 ///
03374 /// Here, the argument to the function object \c f is a pack expansion whose
03375 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
03376 /// template is instantiated, the pack expansion will instantiate to zero or
03377 /// or more function arguments to the function object \c f.
03378 class PackExpansionExpr : public Expr {
03379   SourceLocation EllipsisLoc;
03380 
03381   /// \brief The number of expansions that will be produced by this pack
03382   /// expansion expression, if known.
03383   ///
03384   /// When zero, the number of expansions is not known. Otherwise, this value
03385   /// is the number of expansions + 1.
03386   unsigned NumExpansions;
03387 
03388   Stmt *Pattern;
03389 
03390   friend class ASTStmtReader;
03391   friend class ASTStmtWriter;
03392 
03393 public:
03394   PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
03395                     Optional<unsigned> NumExpansions)
03396     : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
03397            Pattern->getObjectKind(), /*TypeDependent=*/true,
03398            /*ValueDependent=*/true, /*InstantiationDependent=*/true,
03399            /*ContainsUnexpandedParameterPack=*/false),
03400       EllipsisLoc(EllipsisLoc),
03401       NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
03402       Pattern(Pattern) { }
03403 
03404   PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
03405 
03406   /// \brief Retrieve the pattern of the pack expansion.
03407   Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
03408 
03409   /// \brief Retrieve the pattern of the pack expansion.
03410   const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
03411 
03412   /// \brief Retrieve the location of the ellipsis that describes this pack
03413   /// expansion.
03414   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
03415 
03416   /// \brief Determine the number of expansions that will be produced when
03417   /// this pack expansion is instantiated, if already known.
03418   Optional<unsigned> getNumExpansions() const {
03419     if (NumExpansions)
03420       return NumExpansions - 1;
03421 
03422     return None;
03423   }
03424 
03425   SourceLocation getLocStart() const LLVM_READONLY {
03426     return Pattern->getLocStart();
03427   }
03428   SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; }
03429 
03430   static bool classof(const Stmt *T) {
03431     return T->getStmtClass() == PackExpansionExprClass;
03432   }
03433 
03434   // Iterators
03435   child_range children() {
03436     return child_range(&Pattern, &Pattern + 1);
03437   }
03438 };
03439 
03440 inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
03441   if (!HasTemplateKWAndArgsInfo) return nullptr;
03442   if (isa<UnresolvedLookupExpr>(this))
03443     return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
03444       (cast<UnresolvedLookupExpr>(this) + 1);
03445   else
03446     return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
03447       (cast<UnresolvedMemberExpr>(this) + 1);
03448 }
03449 
03450 /// \brief Represents an expression that computes the length of a parameter
03451 /// pack.
03452 ///
03453 /// \code
03454 /// template<typename ...Types>
03455 /// struct count {
03456 ///   static const unsigned value = sizeof...(Types);
03457 /// };
03458 /// \endcode
03459 class SizeOfPackExpr : public Expr {
03460   /// \brief The location of the \c sizeof keyword.
03461   SourceLocation OperatorLoc;
03462 
03463   /// \brief The location of the name of the parameter pack.
03464   SourceLocation PackLoc;
03465 
03466   /// \brief The location of the closing parenthesis.
03467   SourceLocation RParenLoc;
03468 
03469   /// \brief The length of the parameter pack, if known.
03470   ///
03471   /// When this expression is value-dependent, the length of the parameter pack
03472   /// is unknown. When this expression is not value-dependent, the length is
03473   /// known.
03474   unsigned Length;
03475 
03476   /// \brief The parameter pack itself.
03477   NamedDecl *Pack;
03478 
03479   friend class ASTStmtReader;
03480   friend class ASTStmtWriter;
03481 
03482 public:
03483   /// \brief Create a value-dependent expression that computes the length of
03484   /// the given parameter pack.
03485   SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
03486                  SourceLocation PackLoc, SourceLocation RParenLoc)
03487     : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
03488            /*TypeDependent=*/false, /*ValueDependent=*/true,
03489            /*InstantiationDependent=*/true,
03490            /*ContainsUnexpandedParameterPack=*/false),
03491       OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
03492       Length(0), Pack(Pack) { }
03493 
03494   /// \brief Create an expression that computes the length of
03495   /// the given parameter pack, which is already known.
03496   SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
03497                  SourceLocation PackLoc, SourceLocation RParenLoc,
03498                  unsigned Length)
03499   : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
03500          /*TypeDependent=*/false, /*ValueDependent=*/false,
03501          /*InstantiationDependent=*/false,
03502          /*ContainsUnexpandedParameterPack=*/false),
03503     OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
03504     Length(Length), Pack(Pack) { }
03505 
03506   /// \brief Create an empty expression.
03507   SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
03508 
03509   /// \brief Determine the location of the 'sizeof' keyword.
03510   SourceLocation getOperatorLoc() const { return OperatorLoc; }
03511 
03512   /// \brief Determine the location of the parameter pack.
03513   SourceLocation getPackLoc() const { return PackLoc; }
03514 
03515   /// \brief Determine the location of the right parenthesis.
03516   SourceLocation getRParenLoc() const { return RParenLoc; }
03517 
03518   /// \brief Retrieve the parameter pack.
03519   NamedDecl *getPack() const { return Pack; }
03520 
03521   /// \brief Retrieve the length of the parameter pack.
03522   ///
03523   /// This routine may only be invoked when the expression is not
03524   /// value-dependent.
03525   unsigned getPackLength() const {
03526     assert(!isValueDependent() &&
03527            "Cannot get the length of a value-dependent pack size expression");
03528     return Length;
03529   }
03530 
03531   SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
03532   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
03533 
03534   static bool classof(const Stmt *T) {
03535     return T->getStmtClass() == SizeOfPackExprClass;
03536   }
03537 
03538   // Iterators
03539   child_range children() { return child_range(); }
03540 };
03541 
03542 /// \brief Represents a reference to a non-type template parameter
03543 /// that has been substituted with a template argument.
03544 class SubstNonTypeTemplateParmExpr : public Expr {
03545   /// \brief The replaced parameter.
03546   NonTypeTemplateParmDecl *Param;
03547 
03548   /// \brief The replacement expression.
03549   Stmt *Replacement;
03550 
03551   /// \brief The location of the non-type template parameter reference.
03552   SourceLocation NameLoc;
03553 
03554   friend class ASTReader;
03555   friend class ASTStmtReader;
03556   explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
03557     : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
03558 
03559 public:
03560   SubstNonTypeTemplateParmExpr(QualType type,
03561                                ExprValueKind valueKind,
03562                                SourceLocation loc,
03563                                NonTypeTemplateParmDecl *param,
03564                                Expr *replacement)
03565     : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
03566            replacement->isTypeDependent(), replacement->isValueDependent(),
03567            replacement->isInstantiationDependent(),
03568            replacement->containsUnexpandedParameterPack()),
03569       Param(param), Replacement(replacement), NameLoc(loc) {}
03570 
03571   SourceLocation getNameLoc() const { return NameLoc; }
03572   SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
03573   SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
03574 
03575   Expr *getReplacement() const { return cast<Expr>(Replacement); }
03576 
03577   NonTypeTemplateParmDecl *getParameter() const { return Param; }
03578 
03579   static bool classof(const Stmt *s) {
03580     return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
03581   }
03582 
03583   // Iterators
03584   child_range children() { return child_range(&Replacement, &Replacement+1); }
03585 };
03586 
03587 /// \brief Represents a reference to a non-type template parameter pack that
03588 /// has been substituted with a non-template argument pack.
03589 ///
03590 /// When a pack expansion in the source code contains multiple parameter packs
03591 /// and those parameter packs correspond to different levels of template
03592 /// parameter lists, this node is used to represent a non-type template
03593 /// parameter pack from an outer level, which has already had its argument pack
03594 /// substituted but that still lives within a pack expansion that itself
03595 /// could not be instantiated. When actually performing a substitution into
03596 /// that pack expansion (e.g., when all template parameters have corresponding
03597 /// arguments), this type will be replaced with the appropriate underlying
03598 /// expression at the current pack substitution index.
03599 class SubstNonTypeTemplateParmPackExpr : public Expr {
03600   /// \brief The non-type template parameter pack itself.
03601   NonTypeTemplateParmDecl *Param;
03602 
03603   /// \brief A pointer to the set of template arguments that this
03604   /// parameter pack is instantiated with.
03605   const TemplateArgument *Arguments;
03606 
03607   /// \brief The number of template arguments in \c Arguments.
03608   unsigned NumArguments;
03609 
03610   /// \brief The location of the non-type template parameter pack reference.
03611   SourceLocation NameLoc;
03612 
03613   friend class ASTReader;
03614   friend class ASTStmtReader;
03615   explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
03616     : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
03617 
03618 public:
03619   SubstNonTypeTemplateParmPackExpr(QualType T,
03620                                    NonTypeTemplateParmDecl *Param,
03621                                    SourceLocation NameLoc,
03622                                    const TemplateArgument &ArgPack);
03623 
03624   /// \brief Retrieve the non-type template parameter pack being substituted.
03625   NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
03626 
03627   /// \brief Retrieve the location of the parameter pack name.
03628   SourceLocation getParameterPackLocation() const { return NameLoc; }
03629 
03630   /// \brief Retrieve the template argument pack containing the substituted
03631   /// template arguments.
03632   TemplateArgument getArgumentPack() const;
03633 
03634   SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
03635   SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
03636 
03637   static bool classof(const Stmt *T) {
03638     return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
03639   }
03640 
03641   // Iterators
03642   child_range children() { return child_range(); }
03643 };
03644 
03645 /// \brief Represents a reference to a function parameter pack that has been
03646 /// substituted but not yet expanded.
03647 ///
03648 /// When a pack expansion contains multiple parameter packs at different levels,
03649 /// this node is used to represent a function parameter pack at an outer level
03650 /// which we have already substituted to refer to expanded parameters, but where
03651 /// the containing pack expansion cannot yet be expanded.
03652 ///
03653 /// \code
03654 /// template<typename...Ts> struct S {
03655 ///   template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
03656 /// };
03657 /// template struct S<int, int>;
03658 /// \endcode
03659 class FunctionParmPackExpr : public Expr {
03660   /// \brief The function parameter pack which was referenced.
03661   ParmVarDecl *ParamPack;
03662 
03663   /// \brief The location of the function parameter pack reference.
03664   SourceLocation NameLoc;
03665 
03666   /// \brief The number of expansions of this pack.
03667   unsigned NumParameters;
03668 
03669   FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
03670                        SourceLocation NameLoc, unsigned NumParams,
03671                        Decl * const *Params);
03672 
03673   friend class ASTReader;
03674   friend class ASTStmtReader;
03675 
03676 public:
03677   static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
03678                                       ParmVarDecl *ParamPack,
03679                                       SourceLocation NameLoc,
03680                                       ArrayRef<Decl *> Params);
03681   static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
03682                                            unsigned NumParams);
03683 
03684   /// \brief Get the parameter pack which this expression refers to.
03685   ParmVarDecl *getParameterPack() const { return ParamPack; }
03686 
03687   /// \brief Get the location of the parameter pack.
03688   SourceLocation getParameterPackLocation() const { return NameLoc; }
03689 
03690   /// \brief Iterators over the parameters which the parameter pack expanded
03691   /// into.
03692   typedef ParmVarDecl * const *iterator;
03693   iterator begin() const { return reinterpret_cast<iterator>(this+1); }
03694   iterator end() const { return begin() + NumParameters; }
03695 
03696   /// \brief Get the number of parameters in this parameter pack.
03697   unsigned getNumExpansions() const { return NumParameters; }
03698 
03699   /// \brief Get an expansion of the parameter pack by index.
03700   ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
03701 
03702   SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
03703   SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
03704 
03705   static bool classof(const Stmt *T) {
03706     return T->getStmtClass() == FunctionParmPackExprClass;
03707   }
03708 
03709   child_range children() { return child_range(); }
03710 };
03711 
03712 /// \brief Represents a prvalue temporary that is written into memory so that
03713 /// a reference can bind to it.
03714 ///
03715 /// Prvalue expressions are materialized when they need to have an address
03716 /// in memory for a reference to bind to. This happens when binding a
03717 /// reference to the result of a conversion, e.g.,
03718 ///
03719 /// \code
03720 /// const int &r = 1.0;
03721 /// \endcode
03722 ///
03723 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
03724 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
03725 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
03726 /// (either an lvalue or an xvalue, depending on the kind of reference binding
03727 /// to it), maintaining the invariant that references always bind to glvalues.
03728 ///
03729 /// Reference binding and copy-elision can both extend the lifetime of a
03730 /// temporary. When either happens, the expression will also track the
03731 /// declaration which is responsible for the lifetime extension.
03732 class MaterializeTemporaryExpr : public Expr {
03733 private:
03734   struct ExtraState {
03735     /// \brief The temporary-generating expression whose value will be
03736     /// materialized.
03737     Stmt *Temporary;
03738 
03739     /// \brief The declaration which lifetime-extended this reference, if any.
03740     /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
03741     const ValueDecl *ExtendingDecl;
03742 
03743     unsigned ManglingNumber;
03744   };
03745   llvm::PointerUnion<Stmt *, ExtraState *> State;
03746 
03747   friend class ASTStmtReader;
03748   friend class ASTStmtWriter;
03749 
03750   void initializeExtraState(const ValueDecl *ExtendedBy,
03751                             unsigned ManglingNumber);
03752 
03753 public:
03754   MaterializeTemporaryExpr(QualType T, Expr *Temporary,
03755                            bool BoundToLvalueReference)
03756     : Expr(MaterializeTemporaryExprClass, T,
03757            BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
03758            Temporary->isTypeDependent(), Temporary->isValueDependent(),
03759            Temporary->isInstantiationDependent(),
03760            Temporary->containsUnexpandedParameterPack()),
03761         State(Temporary) {}
03762 
03763   MaterializeTemporaryExpr(EmptyShell Empty)
03764     : Expr(MaterializeTemporaryExprClass, Empty) { }
03765 
03766   Stmt *getTemporary() const {
03767     return State.is<Stmt *>() ? State.get<Stmt *>()
03768                               : State.get<ExtraState *>()->Temporary;
03769   }
03770 
03771   /// \brief Retrieve the temporary-generating subexpression whose value will
03772   /// be materialized into a glvalue.
03773   Expr *GetTemporaryExpr() const { return static_cast<Expr *>(getTemporary()); }
03774 
03775   /// \brief Retrieve the storage duration for the materialized temporary.
03776   StorageDuration getStorageDuration() const {
03777     const ValueDecl *ExtendingDecl = getExtendingDecl();
03778     if (!ExtendingDecl)
03779       return SD_FullExpression;
03780     // FIXME: This is not necessarily correct for a temporary materialized
03781     // within a default initializer.
03782     if (isa<FieldDecl>(ExtendingDecl))
03783       return SD_Automatic;
03784     return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
03785   }
03786 
03787   /// \brief Get the declaration which triggered the lifetime-extension of this
03788   /// temporary, if any.
03789   const ValueDecl *getExtendingDecl() const {
03790     return State.is<Stmt *>() ? nullptr
03791                               : State.get<ExtraState *>()->ExtendingDecl;
03792   }
03793 
03794   void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber);
03795 
03796   unsigned getManglingNumber() const {
03797     return State.is<Stmt *>() ? 0 : State.get<ExtraState *>()->ManglingNumber;
03798   }
03799 
03800   /// \brief Determine whether this materialized temporary is bound to an
03801   /// lvalue reference; otherwise, it's bound to an rvalue reference.
03802   bool isBoundToLvalueReference() const {
03803     return getValueKind() == VK_LValue;
03804   }
03805 
03806   SourceLocation getLocStart() const LLVM_READONLY {
03807     return getTemporary()->getLocStart();
03808   }
03809   SourceLocation getLocEnd() const LLVM_READONLY {
03810     return getTemporary()->getLocEnd();
03811   }
03812 
03813   static bool classof(const Stmt *T) {
03814     return T->getStmtClass() == MaterializeTemporaryExprClass;
03815   }
03816 
03817   // Iterators
03818   child_range children() {
03819     if (State.is<Stmt *>())
03820       return child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1);
03821 
03822     auto ES = State.get<ExtraState *>();
03823     return child_range(&ES->Temporary, &ES->Temporary + 1);
03824   }
03825 };
03826 
03827 /// \brief Represents a folding of a pack over an operator.
03828 ///
03829 /// This expression is always dependent and represents a pack expansion of the
03830 /// forms:
03831 ///
03832 ///    ( expr op ... )
03833 ///    ( ... op expr )
03834 ///    ( expr op ... op expr )
03835 class CXXFoldExpr : public Expr {
03836   SourceLocation LParenLoc;
03837   SourceLocation EllipsisLoc;
03838   SourceLocation RParenLoc;
03839   Stmt *SubExprs[2];
03840   BinaryOperatorKind Opcode;
03841 
03842   friend class ASTStmtReader;
03843   friend class ASTStmtWriter;
03844 public:
03845   CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS,
03846               BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS,
03847               SourceLocation RParenLoc)
03848       : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary,
03849              /*Dependent*/ true, true, true,
03850              /*ContainsUnexpandedParameterPack*/ false),
03851         LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
03852         Opcode(Opcode) {
03853     SubExprs[0] = LHS;
03854     SubExprs[1] = RHS;
03855   }
03856   CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
03857 
03858   Expr *getLHS() const { return static_cast<Expr*>(SubExprs[0]); }
03859   Expr *getRHS() const { return static_cast<Expr*>(SubExprs[1]); }
03860 
03861   /// Does this produce a right-associated sequence of operators?
03862   bool isRightFold() const {
03863     return getLHS() && getLHS()->containsUnexpandedParameterPack();
03864   }
03865   /// Does this produce a left-associated sequence of operators?
03866   bool isLeftFold() const { return !isRightFold(); }
03867   /// Get the pattern, that is, the operand that contains an unexpanded pack.
03868   Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
03869   /// Get the operand that doesn't contain a pack, for a binary fold.
03870   Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
03871 
03872   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
03873   BinaryOperatorKind getOperator() const { return Opcode; }
03874 
03875   SourceLocation getLocStart() const LLVM_READONLY {
03876     return LParenLoc;
03877   }
03878   SourceLocation getLocEnd() const LLVM_READONLY {
03879     return RParenLoc;
03880   }
03881 
03882   static bool classof(const Stmt *T) {
03883     return T->getStmtClass() == CXXFoldExprClass;
03884   }
03885 
03886   // Iterators
03887   child_range children() { return child_range(SubExprs, SubExprs + 2); }
03888 };
03889 
03890 }  // end namespace clang
03891 
03892 #endif