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