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