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