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