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   /// Whether this is a generic lambda.
isGenericLambda()2033   bool isGenericLambda() const { return getTemplateParameterList(); }
2034 
2035   /// Retrieve the body of the lambda. This will be most of the time
2036   /// a \p CompoundStmt, but can also be \p CoroutineBodyStmt wrapping
2037   /// a \p CompoundStmt. Note that unlike functions, lambda-expressions
2038   /// cannot have a function-try-block.
2039   Stmt *getBody() const;
2040 
2041   /// Retrieve the \p CompoundStmt representing the body of the lambda.
2042   /// This is a convenience function for callers who do not need
2043   /// to handle node(s) which may wrap a \p CompoundStmt.
2044   const CompoundStmt *getCompoundStmtBody() const;
getCompoundStmtBody()2045   CompoundStmt *getCompoundStmtBody() {
2046     const auto *ConstThis = this;
2047     return const_cast<CompoundStmt *>(ConstThis->getCompoundStmtBody());
2048   }
2049 
2050   /// Determine whether the lambda is mutable, meaning that any
2051   /// captures values can be modified.
2052   bool isMutable() const;
2053 
2054   /// Determine whether this lambda has an explicit parameter
2055   /// list vs. an implicit (empty) parameter list.
hasExplicitParameters()2056   bool hasExplicitParameters() const { return LambdaExprBits.ExplicitParams; }
2057 
2058   /// Whether this lambda had its result type explicitly specified.
hasExplicitResultType()2059   bool hasExplicitResultType() const {
2060     return LambdaExprBits.ExplicitResultType;
2061   }
2062 
classof(const Stmt * T)2063   static bool classof(const Stmt *T) {
2064     return T->getStmtClass() == LambdaExprClass;
2065   }
2066 
getBeginLoc()2067   SourceLocation getBeginLoc() const LLVM_READONLY {
2068     return IntroducerRange.getBegin();
2069   }
2070 
getEndLoc()2071   SourceLocation getEndLoc() const LLVM_READONLY { return ClosingBrace; }
2072 
2073   /// Includes the captures and the body of the lambda.
2074   child_range children();
2075   const_child_range children() const;
2076 };
2077 
2078 /// An expression "T()" which creates a value-initialized rvalue of type
2079 /// T, which is a non-class type.  See (C++98 [5.2.3p2]).
2080 class CXXScalarValueInitExpr : public Expr {
2081   friend class ASTStmtReader;
2082 
2083   TypeSourceInfo *TypeInfo;
2084 
2085 public:
2086   /// Create an explicitly-written scalar-value initialization
2087   /// expression.
CXXScalarValueInitExpr(QualType Type,TypeSourceInfo * TypeInfo,SourceLocation RParenLoc)2088   CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
2089                          SourceLocation RParenLoc)
2090       : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary),
2091         TypeInfo(TypeInfo) {
2092     CXXScalarValueInitExprBits.RParenLoc = RParenLoc;
2093     setDependence(computeDependence(this));
2094   }
2095 
CXXScalarValueInitExpr(EmptyShell Shell)2096   explicit CXXScalarValueInitExpr(EmptyShell Shell)
2097       : Expr(CXXScalarValueInitExprClass, Shell) {}
2098 
getTypeSourceInfo()2099   TypeSourceInfo *getTypeSourceInfo() const {
2100     return TypeInfo;
2101   }
2102 
getRParenLoc()2103   SourceLocation getRParenLoc() const {
2104     return CXXScalarValueInitExprBits.RParenLoc;
2105   }
2106 
2107   SourceLocation getBeginLoc() const LLVM_READONLY;
getEndLoc()2108   SourceLocation getEndLoc() const { return getRParenLoc(); }
2109 
classof(const Stmt * T)2110   static bool classof(const Stmt *T) {
2111     return T->getStmtClass() == CXXScalarValueInitExprClass;
2112   }
2113 
2114   // Iterators
children()2115   child_range children() {
2116     return child_range(child_iterator(), child_iterator());
2117   }
2118 
children()2119   const_child_range children() const {
2120     return const_child_range(const_child_iterator(), const_child_iterator());
2121   }
2122 };
2123 
2124 /// Represents a new-expression for memory allocation and constructor
2125 /// calls, e.g: "new CXXNewExpr(foo)".
2126 class CXXNewExpr final
2127     : public Expr,
2128       private llvm::TrailingObjects<CXXNewExpr, Stmt *, SourceRange> {
2129   friend class ASTStmtReader;
2130   friend class ASTStmtWriter;
2131   friend TrailingObjects;
2132 
2133   /// Points to the allocation function used.
2134   FunctionDecl *OperatorNew;
2135 
2136   /// Points to the deallocation function used in case of error. May be null.
2137   FunctionDecl *OperatorDelete;
2138 
2139   /// The allocated type-source information, as written in the source.
2140   TypeSourceInfo *AllocatedTypeInfo;
2141 
2142   /// Range of the entire new expression.
2143   SourceRange Range;
2144 
2145   /// Source-range of a paren-delimited initializer.
2146   SourceRange DirectInitRange;
2147 
2148   // CXXNewExpr is followed by several optional trailing objects.
2149   // They are in order:
2150   //
2151   // * An optional "Stmt *" for the array size expression.
2152   //    Present if and ony if isArray().
2153   //
2154   // * An optional "Stmt *" for the init expression.
2155   //    Present if and only if hasInitializer().
2156   //
2157   // * An array of getNumPlacementArgs() "Stmt *" for the placement new
2158   //   arguments, if any.
2159   //
2160   // * An optional SourceRange for the range covering the parenthesized type-id
2161   //    if the allocated type was expressed as a parenthesized type-id.
2162   //    Present if and only if isParenTypeId().
arraySizeOffset()2163   unsigned arraySizeOffset() const { return 0; }
initExprOffset()2164   unsigned initExprOffset() const { return arraySizeOffset() + isArray(); }
placementNewArgsOffset()2165   unsigned placementNewArgsOffset() const {
2166     return initExprOffset() + hasInitializer();
2167   }
2168 
numTrailingObjects(OverloadToken<Stmt * >)2169   unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2170     return isArray() + hasInitializer() + getNumPlacementArgs();
2171   }
2172 
numTrailingObjects(OverloadToken<SourceRange>)2173   unsigned numTrailingObjects(OverloadToken<SourceRange>) const {
2174     return isParenTypeId();
2175   }
2176 
2177 public:
2178   enum InitializationStyle {
2179     /// New-expression has no initializer as written.
2180     NoInit,
2181 
2182     /// New-expression has a C++98 paren-delimited initializer.
2183     CallInit,
2184 
2185     /// New-expression has a C++11 list-initializer.
2186     ListInit
2187   };
2188 
2189 private:
2190   /// Build a c++ new expression.
2191   CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
2192              FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
2193              bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs,
2194              SourceRange TypeIdParens, Optional<Expr *> ArraySize,
2195              InitializationStyle InitializationStyle, Expr *Initializer,
2196              QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
2197              SourceRange DirectInitRange);
2198 
2199   /// Build an empty c++ new expression.
2200   CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs,
2201              bool IsParenTypeId);
2202 
2203 public:
2204   /// Create a c++ new expression.
2205   static CXXNewExpr *
2206   Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew,
2207          FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
2208          bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs,
2209          SourceRange TypeIdParens, Optional<Expr *> ArraySize,
2210          InitializationStyle InitializationStyle, Expr *Initializer,
2211          QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
2212          SourceRange DirectInitRange);
2213 
2214   /// Create an empty c++ new expression.
2215   static CXXNewExpr *CreateEmpty(const ASTContext &Ctx, bool IsArray,
2216                                  bool HasInit, unsigned NumPlacementArgs,
2217                                  bool IsParenTypeId);
2218 
getAllocatedType()2219   QualType getAllocatedType() const {
2220     return getType()->castAs<PointerType>()->getPointeeType();
2221   }
2222 
getAllocatedTypeSourceInfo()2223   TypeSourceInfo *getAllocatedTypeSourceInfo() const {
2224     return AllocatedTypeInfo;
2225   }
2226 
2227   /// True if the allocation result needs to be null-checked.
2228   ///
2229   /// C++11 [expr.new]p13:
2230   ///   If the allocation function returns null, initialization shall
2231   ///   not be done, the deallocation function shall not be called,
2232   ///   and the value of the new-expression shall be null.
2233   ///
2234   /// C++ DR1748:
2235   ///   If the allocation function is a reserved placement allocation
2236   ///   function that returns null, the behavior is undefined.
2237   ///
2238   /// An allocation function is not allowed to return null unless it
2239   /// has a non-throwing exception-specification.  The '03 rule is
2240   /// identical except that the definition of a non-throwing
2241   /// exception specification is just "is it throw()?".
2242   bool shouldNullCheckAllocation() const;
2243 
getOperatorNew()2244   FunctionDecl *getOperatorNew() const { return OperatorNew; }
setOperatorNew(FunctionDecl * D)2245   void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
getOperatorDelete()2246   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
setOperatorDelete(FunctionDecl * D)2247   void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
2248 
isArray()2249   bool isArray() const { return CXXNewExprBits.IsArray; }
2250 
getArraySize()2251   Optional<Expr *> getArraySize() {
2252     if (!isArray())
2253       return None;
2254     return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]);
2255   }
getArraySize()2256   Optional<const Expr *> getArraySize() const {
2257     if (!isArray())
2258       return None;
2259     return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]);
2260   }
2261 
getNumPlacementArgs()2262   unsigned getNumPlacementArgs() const {
2263     return CXXNewExprBits.NumPlacementArgs;
2264   }
2265 
getPlacementArgs()2266   Expr **getPlacementArgs() {
2267     return reinterpret_cast<Expr **>(getTrailingObjects<Stmt *>() +
2268                                      placementNewArgsOffset());
2269   }
2270 
getPlacementArg(unsigned I)2271   Expr *getPlacementArg(unsigned I) {
2272     assert((I < getNumPlacementArgs()) && "Index out of range!");
2273     return getPlacementArgs()[I];
2274   }
getPlacementArg(unsigned I)2275   const Expr *getPlacementArg(unsigned I) const {
2276     return const_cast<CXXNewExpr *>(this)->getPlacementArg(I);
2277   }
2278 
isParenTypeId()2279   bool isParenTypeId() const { return CXXNewExprBits.IsParenTypeId; }
getTypeIdParens()2280   SourceRange getTypeIdParens() const {
2281     return isParenTypeId() ? getTrailingObjects<SourceRange>()[0]
2282                            : SourceRange();
2283   }
2284 
isGlobalNew()2285   bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; }
2286 
2287   /// Whether this new-expression has any initializer at all.
hasInitializer()2288   bool hasInitializer() const {
2289     return CXXNewExprBits.StoredInitializationStyle > 0;
2290   }
2291 
2292   /// The kind of initializer this new-expression has.
getInitializationStyle()2293   InitializationStyle getInitializationStyle() const {
2294     if (CXXNewExprBits.StoredInitializationStyle == 0)
2295       return NoInit;
2296     return static_cast<InitializationStyle>(
2297         CXXNewExprBits.StoredInitializationStyle - 1);
2298   }
2299 
2300   /// The initializer of this new-expression.
getInitializer()2301   Expr *getInitializer() {
2302     return hasInitializer()
2303                ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()])
2304                : nullptr;
2305   }
getInitializer()2306   const Expr *getInitializer() const {
2307     return hasInitializer()
2308                ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()])
2309                : nullptr;
2310   }
2311 
2312   /// Returns the CXXConstructExpr from this new-expression, or null.
getConstructExpr()2313   const CXXConstructExpr *getConstructExpr() const {
2314     return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
2315   }
2316 
2317   /// Indicates whether the required alignment should be implicitly passed to
2318   /// the allocation function.
passAlignment()2319   bool passAlignment() const { return CXXNewExprBits.ShouldPassAlignment; }
2320 
2321   /// Answers whether the usual array deallocation function for the
2322   /// allocated type expects the size of the allocation as a
2323   /// parameter.
doesUsualArrayDeleteWantSize()2324   bool doesUsualArrayDeleteWantSize() const {
2325     return CXXNewExprBits.UsualArrayDeleteWantsSize;
2326   }
2327 
2328   using arg_iterator = ExprIterator;
2329   using const_arg_iterator = ConstExprIterator;
2330 
placement_arguments()2331   llvm::iterator_range<arg_iterator> placement_arguments() {
2332     return llvm::make_range(placement_arg_begin(), placement_arg_end());
2333   }
2334 
placement_arguments()2335   llvm::iterator_range<const_arg_iterator> placement_arguments() const {
2336     return llvm::make_range(placement_arg_begin(), placement_arg_end());
2337   }
2338 
placement_arg_begin()2339   arg_iterator placement_arg_begin() {
2340     return getTrailingObjects<Stmt *>() + placementNewArgsOffset();
2341   }
placement_arg_end()2342   arg_iterator placement_arg_end() {
2343     return placement_arg_begin() + getNumPlacementArgs();
2344   }
placement_arg_begin()2345   const_arg_iterator placement_arg_begin() const {
2346     return getTrailingObjects<Stmt *>() + placementNewArgsOffset();
2347   }
placement_arg_end()2348   const_arg_iterator placement_arg_end() const {
2349     return placement_arg_begin() + getNumPlacementArgs();
2350   }
2351 
2352   using raw_arg_iterator = Stmt **;
2353 
raw_arg_begin()2354   raw_arg_iterator raw_arg_begin() { return getTrailingObjects<Stmt *>(); }
raw_arg_end()2355   raw_arg_iterator raw_arg_end() {
2356     return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>());
2357   }
raw_arg_begin()2358   const_arg_iterator raw_arg_begin() const {
2359     return getTrailingObjects<Stmt *>();
2360   }
raw_arg_end()2361   const_arg_iterator raw_arg_end() const {
2362     return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>());
2363   }
2364 
getBeginLoc()2365   SourceLocation getBeginLoc() const { return Range.getBegin(); }
getEndLoc()2366   SourceLocation getEndLoc() const { return Range.getEnd(); }
2367 
getDirectInitRange()2368   SourceRange getDirectInitRange() const { return DirectInitRange; }
getSourceRange()2369   SourceRange getSourceRange() const { return Range; }
2370 
classof(const Stmt * T)2371   static bool classof(const Stmt *T) {
2372     return T->getStmtClass() == CXXNewExprClass;
2373   }
2374 
2375   // Iterators
children()2376   child_range children() { return child_range(raw_arg_begin(), raw_arg_end()); }
2377 
children()2378   const_child_range children() const {
2379     return const_child_range(const_cast<CXXNewExpr *>(this)->children());
2380   }
2381 };
2382 
2383 /// Represents a \c delete expression for memory deallocation and
2384 /// destructor calls, e.g. "delete[] pArray".
2385 class CXXDeleteExpr : public Expr {
2386   friend class ASTStmtReader;
2387 
2388   /// Points to the operator delete overload that is used. Could be a member.
2389   FunctionDecl *OperatorDelete = nullptr;
2390 
2391   /// The pointer expression to be deleted.
2392   Stmt *Argument = nullptr;
2393 
2394 public:
CXXDeleteExpr(QualType Ty,bool GlobalDelete,bool ArrayForm,bool ArrayFormAsWritten,bool UsualArrayDeleteWantsSize,FunctionDecl * OperatorDelete,Expr * Arg,SourceLocation Loc)2395   CXXDeleteExpr(QualType Ty, bool GlobalDelete, bool ArrayForm,
2396                 bool ArrayFormAsWritten, bool UsualArrayDeleteWantsSize,
2397                 FunctionDecl *OperatorDelete, Expr *Arg, SourceLocation Loc)
2398       : Expr(CXXDeleteExprClass, Ty, VK_RValue, OK_Ordinary),
2399         OperatorDelete(OperatorDelete), Argument(Arg) {
2400     CXXDeleteExprBits.GlobalDelete = GlobalDelete;
2401     CXXDeleteExprBits.ArrayForm = ArrayForm;
2402     CXXDeleteExprBits.ArrayFormAsWritten = ArrayFormAsWritten;
2403     CXXDeleteExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize;
2404     CXXDeleteExprBits.Loc = Loc;
2405     setDependence(computeDependence(this));
2406   }
2407 
CXXDeleteExpr(EmptyShell Shell)2408   explicit CXXDeleteExpr(EmptyShell Shell) : Expr(CXXDeleteExprClass, Shell) {}
2409 
isGlobalDelete()2410   bool isGlobalDelete() const { return CXXDeleteExprBits.GlobalDelete; }
isArrayForm()2411   bool isArrayForm() const { return CXXDeleteExprBits.ArrayForm; }
isArrayFormAsWritten()2412   bool isArrayFormAsWritten() const {
2413     return CXXDeleteExprBits.ArrayFormAsWritten;
2414   }
2415 
2416   /// Answers whether the usual array deallocation function for the
2417   /// allocated type expects the size of the allocation as a
2418   /// parameter.  This can be true even if the actual deallocation
2419   /// function that we're using doesn't want a size.
doesUsualArrayDeleteWantSize()2420   bool doesUsualArrayDeleteWantSize() const {
2421     return CXXDeleteExprBits.UsualArrayDeleteWantsSize;
2422   }
2423 
getOperatorDelete()2424   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2425 
getArgument()2426   Expr *getArgument() { return cast<Expr>(Argument); }
getArgument()2427   const Expr *getArgument() const { return cast<Expr>(Argument); }
2428 
2429   /// Retrieve the type being destroyed.
2430   ///
2431   /// If the type being destroyed is a dependent type which may or may not
2432   /// be a pointer, return an invalid type.
2433   QualType getDestroyedType() const;
2434 
getBeginLoc()2435   SourceLocation getBeginLoc() const { return CXXDeleteExprBits.Loc; }
getEndLoc()2436   SourceLocation getEndLoc() const LLVM_READONLY {
2437     return Argument->getEndLoc();
2438   }
2439 
classof(const Stmt * T)2440   static bool classof(const Stmt *T) {
2441     return T->getStmtClass() == CXXDeleteExprClass;
2442   }
2443 
2444   // Iterators
children()2445   child_range children() { return child_range(&Argument, &Argument + 1); }
2446 
children()2447   const_child_range children() const {
2448     return const_child_range(&Argument, &Argument + 1);
2449   }
2450 };
2451 
2452 /// Stores the type being destroyed by a pseudo-destructor expression.
2453 class PseudoDestructorTypeStorage {
2454   /// Either the type source information or the name of the type, if
2455   /// it couldn't be resolved due to type-dependence.
2456   llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
2457 
2458   /// The starting source location of the pseudo-destructor type.
2459   SourceLocation Location;
2460 
2461 public:
2462   PseudoDestructorTypeStorage() = default;
2463 
PseudoDestructorTypeStorage(IdentifierInfo * II,SourceLocation Loc)2464   PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
2465       : Type(II), Location(Loc) {}
2466 
2467   PseudoDestructorTypeStorage(TypeSourceInfo *Info);
2468 
getTypeSourceInfo()2469   TypeSourceInfo *getTypeSourceInfo() const {
2470     return Type.dyn_cast<TypeSourceInfo *>();
2471   }
2472 
getIdentifier()2473   IdentifierInfo *getIdentifier() const {
2474     return Type.dyn_cast<IdentifierInfo *>();
2475   }
2476 
getLocation()2477   SourceLocation getLocation() const { return Location; }
2478 };
2479 
2480 /// Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
2481 ///
2482 /// A pseudo-destructor is an expression that looks like a member access to a
2483 /// destructor of a scalar type, except that scalar types don't have
2484 /// destructors. For example:
2485 ///
2486 /// \code
2487 /// typedef int T;
2488 /// void f(int *p) {
2489 ///   p->T::~T();
2490 /// }
2491 /// \endcode
2492 ///
2493 /// Pseudo-destructors typically occur when instantiating templates such as:
2494 ///
2495 /// \code
2496 /// template<typename T>
2497 /// void destroy(T* ptr) {
2498 ///   ptr->T::~T();
2499 /// }
2500 /// \endcode
2501 ///
2502 /// for scalar types. A pseudo-destructor expression has no run-time semantics
2503 /// beyond evaluating the base expression.
2504 class CXXPseudoDestructorExpr : public Expr {
2505   friend class ASTStmtReader;
2506 
2507   /// The base expression (that is being destroyed).
2508   Stmt *Base = nullptr;
2509 
2510   /// Whether the operator was an arrow ('->'); otherwise, it was a
2511   /// period ('.').
2512   bool IsArrow : 1;
2513 
2514   /// The location of the '.' or '->' operator.
2515   SourceLocation OperatorLoc;
2516 
2517   /// The nested-name-specifier that follows the operator, if present.
2518   NestedNameSpecifierLoc QualifierLoc;
2519 
2520   /// The type that precedes the '::' in a qualified pseudo-destructor
2521   /// expression.
2522   TypeSourceInfo *ScopeType = nullptr;
2523 
2524   /// The location of the '::' in a qualified pseudo-destructor
2525   /// expression.
2526   SourceLocation ColonColonLoc;
2527 
2528   /// The location of the '~'.
2529   SourceLocation TildeLoc;
2530 
2531   /// The type being destroyed, or its name if we were unable to
2532   /// resolve the name.
2533   PseudoDestructorTypeStorage DestroyedType;
2534 
2535 public:
2536   CXXPseudoDestructorExpr(const ASTContext &Context,
2537                           Expr *Base, bool isArrow, SourceLocation OperatorLoc,
2538                           NestedNameSpecifierLoc QualifierLoc,
2539                           TypeSourceInfo *ScopeType,
2540                           SourceLocation ColonColonLoc,
2541                           SourceLocation TildeLoc,
2542                           PseudoDestructorTypeStorage DestroyedType);
2543 
CXXPseudoDestructorExpr(EmptyShell Shell)2544   explicit CXXPseudoDestructorExpr(EmptyShell Shell)
2545       : Expr(CXXPseudoDestructorExprClass, Shell), IsArrow(false) {}
2546 
getBase()2547   Expr *getBase() const { return cast<Expr>(Base); }
2548 
2549   /// Determines whether this member expression actually had
2550   /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2551   /// x->Base::foo.
hasQualifier()2552   bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
2553 
2554   /// Retrieves the nested-name-specifier that qualifies the type name,
2555   /// with source-location information.
getQualifierLoc()2556   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2557 
2558   /// If the member name was qualified, retrieves the
2559   /// nested-name-specifier that precedes the member name. Otherwise, returns
2560   /// null.
getQualifier()2561   NestedNameSpecifier *getQualifier() const {
2562     return QualifierLoc.getNestedNameSpecifier();
2563   }
2564 
2565   /// Determine whether this pseudo-destructor expression was written
2566   /// using an '->' (otherwise, it used a '.').
isArrow()2567   bool isArrow() const { return IsArrow; }
2568 
2569   /// Retrieve the location of the '.' or '->' operator.
getOperatorLoc()2570   SourceLocation getOperatorLoc() const { return OperatorLoc; }
2571 
2572   /// Retrieve the scope type in a qualified pseudo-destructor
2573   /// expression.
2574   ///
2575   /// Pseudo-destructor expressions can have extra qualification within them
2576   /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
2577   /// Here, if the object type of the expression is (or may be) a scalar type,
2578   /// \p T may also be a scalar type and, therefore, cannot be part of a
2579   /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
2580   /// destructor expression.
getScopeTypeInfo()2581   TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
2582 
2583   /// Retrieve the location of the '::' in a qualified pseudo-destructor
2584   /// expression.
getColonColonLoc()2585   SourceLocation getColonColonLoc() const { return ColonColonLoc; }
2586 
2587   /// Retrieve the location of the '~'.
getTildeLoc()2588   SourceLocation getTildeLoc() const { return TildeLoc; }
2589 
2590   /// Retrieve the source location information for the type
2591   /// being destroyed.
2592   ///
2593   /// This type-source information is available for non-dependent
2594   /// pseudo-destructor expressions and some dependent pseudo-destructor
2595   /// expressions. Returns null if we only have the identifier for a
2596   /// dependent pseudo-destructor expression.
getDestroyedTypeInfo()2597   TypeSourceInfo *getDestroyedTypeInfo() const {
2598     return DestroyedType.getTypeSourceInfo();
2599   }
2600 
2601   /// In a dependent pseudo-destructor expression for which we do not
2602   /// have full type information on the destroyed type, provides the name
2603   /// of the destroyed type.
getDestroyedTypeIdentifier()2604   IdentifierInfo *getDestroyedTypeIdentifier() const {
2605     return DestroyedType.getIdentifier();
2606   }
2607 
2608   /// Retrieve the type being destroyed.
2609   QualType getDestroyedType() const;
2610 
2611   /// Retrieve the starting location of the type being destroyed.
getDestroyedTypeLoc()2612   SourceLocation getDestroyedTypeLoc() const {
2613     return DestroyedType.getLocation();
2614   }
2615 
2616   /// Set the name of destroyed type for a dependent pseudo-destructor
2617   /// expression.
setDestroyedType(IdentifierInfo * II,SourceLocation Loc)2618   void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2619     DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2620   }
2621 
2622   /// Set the destroyed type.
setDestroyedType(TypeSourceInfo * Info)2623   void setDestroyedType(TypeSourceInfo *Info) {
2624     DestroyedType = PseudoDestructorTypeStorage(Info);
2625   }
2626 
getBeginLoc()2627   SourceLocation getBeginLoc() const LLVM_READONLY {
2628     return Base->getBeginLoc();
2629   }
2630   SourceLocation getEndLoc() const LLVM_READONLY;
2631 
classof(const Stmt * T)2632   static bool classof(const Stmt *T) {
2633     return T->getStmtClass() == CXXPseudoDestructorExprClass;
2634   }
2635 
2636   // Iterators
children()2637   child_range children() { return child_range(&Base, &Base + 1); }
2638 
children()2639   const_child_range children() const {
2640     return const_child_range(&Base, &Base + 1);
2641   }
2642 };
2643 
2644 /// A type trait used in the implementation of various C++11 and
2645 /// Library TR1 trait templates.
2646 ///
2647 /// \code
2648 ///   __is_pod(int) == true
2649 ///   __is_enum(std::string) == false
2650 ///   __is_trivially_constructible(vector<int>, int*, int*)
2651 /// \endcode
2652 class TypeTraitExpr final
2653     : public Expr,
2654       private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
2655   /// The location of the type trait keyword.
2656   SourceLocation Loc;
2657 
2658   ///  The location of the closing parenthesis.
2659   SourceLocation RParenLoc;
2660 
2661   // Note: The TypeSourceInfos for the arguments are allocated after the
2662   // TypeTraitExpr.
2663 
2664   TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2665                 ArrayRef<TypeSourceInfo *> Args,
2666                 SourceLocation RParenLoc,
2667                 bool Value);
2668 
TypeTraitExpr(EmptyShell Empty)2669   TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {}
2670 
numTrailingObjects(OverloadToken<TypeSourceInfo * >)2671   size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
2672     return getNumArgs();
2673   }
2674 
2675 public:
2676   friend class ASTStmtReader;
2677   friend class ASTStmtWriter;
2678   friend TrailingObjects;
2679 
2680   /// Create a new type trait expression.
2681   static TypeTraitExpr *Create(const ASTContext &C, QualType T,
2682                                SourceLocation Loc, TypeTrait Kind,
2683                                ArrayRef<TypeSourceInfo *> Args,
2684                                SourceLocation RParenLoc,
2685                                bool Value);
2686 
2687   static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
2688                                            unsigned NumArgs);
2689 
2690   /// Determine which type trait this expression uses.
getTrait()2691   TypeTrait getTrait() const {
2692     return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2693   }
2694 
getValue()2695   bool getValue() const {
2696     assert(!isValueDependent());
2697     return TypeTraitExprBits.Value;
2698   }
2699 
2700   /// Determine the number of arguments to this type trait.
getNumArgs()2701   unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2702 
2703   /// Retrieve the Ith argument.
getArg(unsigned I)2704   TypeSourceInfo *getArg(unsigned I) const {
2705     assert(I < getNumArgs() && "Argument out-of-range");
2706     return getArgs()[I];
2707   }
2708 
2709   /// Retrieve the argument types.
getArgs()2710   ArrayRef<TypeSourceInfo *> getArgs() const {
2711     return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(),
2712                               getNumArgs());
2713   }
2714 
getBeginLoc()2715   SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
getEndLoc()2716   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2717 
classof(const Stmt * T)2718   static bool classof(const Stmt *T) {
2719     return T->getStmtClass() == TypeTraitExprClass;
2720   }
2721 
2722   // Iterators
children()2723   child_range children() {
2724     return child_range(child_iterator(), child_iterator());
2725   }
2726 
children()2727   const_child_range children() const {
2728     return const_child_range(const_child_iterator(), const_child_iterator());
2729   }
2730 };
2731 
2732 /// An Embarcadero array type trait, as used in the implementation of
2733 /// __array_rank and __array_extent.
2734 ///
2735 /// Example:
2736 /// \code
2737 ///   __array_rank(int[10][20]) == 2
2738 ///   __array_extent(int, 1)    == 20
2739 /// \endcode
2740 class ArrayTypeTraitExpr : public Expr {
2741   /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2742   unsigned ATT : 2;
2743 
2744   /// The value of the type trait. Unspecified if dependent.
2745   uint64_t Value = 0;
2746 
2747   /// The array dimension being queried, or -1 if not used.
2748   Expr *Dimension;
2749 
2750   /// The location of the type trait keyword.
2751   SourceLocation Loc;
2752 
2753   /// The location of the closing paren.
2754   SourceLocation RParen;
2755 
2756   /// The type being queried.
2757   TypeSourceInfo *QueriedType = nullptr;
2758 
2759 public:
2760   friend class ASTStmtReader;
2761 
ArrayTypeTraitExpr(SourceLocation loc,ArrayTypeTrait att,TypeSourceInfo * queried,uint64_t value,Expr * dimension,SourceLocation rparen,QualType ty)2762   ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2763                      TypeSourceInfo *queried, uint64_t value, Expr *dimension,
2764                      SourceLocation rparen, QualType ty)
2765       : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary), ATT(att),
2766         Value(value), Dimension(dimension), Loc(loc), RParen(rparen),
2767         QueriedType(queried) {
2768     assert(att <= ATT_Last && "invalid enum value!");
2769     assert(static_cast<unsigned>(att) == ATT && "ATT overflow!");
2770     setDependence(computeDependence(this));
2771   }
2772 
ArrayTypeTraitExpr(EmptyShell Empty)2773   explicit ArrayTypeTraitExpr(EmptyShell Empty)
2774       : Expr(ArrayTypeTraitExprClass, Empty), ATT(0) {}
2775 
getBeginLoc()2776   SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
getEndLoc()2777   SourceLocation getEndLoc() const LLVM_READONLY { return RParen; }
2778 
getTrait()2779   ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2780 
getQueriedType()2781   QualType getQueriedType() const { return QueriedType->getType(); }
2782 
getQueriedTypeSourceInfo()2783   TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2784 
getValue()2785   uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2786 
getDimensionExpression()2787   Expr *getDimensionExpression() const { return Dimension; }
2788 
classof(const Stmt * T)2789   static bool classof(const Stmt *T) {
2790     return T->getStmtClass() == ArrayTypeTraitExprClass;
2791   }
2792 
2793   // Iterators
children()2794   child_range children() {
2795     return child_range(child_iterator(), child_iterator());
2796   }
2797 
children()2798   const_child_range children() const {
2799     return const_child_range(const_child_iterator(), const_child_iterator());
2800   }
2801 };
2802 
2803 /// An expression trait intrinsic.
2804 ///
2805 /// Example:
2806 /// \code
2807 ///   __is_lvalue_expr(std::cout) == true
2808 ///   __is_lvalue_expr(1) == false
2809 /// \endcode
2810 class ExpressionTraitExpr : public Expr {
2811   /// The trait. A ExpressionTrait enum in MSVC compatible unsigned.
2812   unsigned ET : 31;
2813 
2814   /// The value of the type trait. Unspecified if dependent.
2815   unsigned Value : 1;
2816 
2817   /// The location of the type trait keyword.
2818   SourceLocation Loc;
2819 
2820   /// The location of the closing paren.
2821   SourceLocation RParen;
2822 
2823   /// The expression being queried.
2824   Expr* QueriedExpression = nullptr;
2825 
2826 public:
2827   friend class ASTStmtReader;
2828 
ExpressionTraitExpr(SourceLocation loc,ExpressionTrait et,Expr * queried,bool value,SourceLocation rparen,QualType resultType)2829   ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, Expr *queried,
2830                       bool value, SourceLocation rparen, QualType resultType)
2831       : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary),
2832         ET(et), Value(value), Loc(loc), RParen(rparen),
2833         QueriedExpression(queried) {
2834     assert(et <= ET_Last && "invalid enum value!");
2835     assert(static_cast<unsigned>(et) == ET && "ET overflow!");
2836     setDependence(computeDependence(this));
2837   }
2838 
ExpressionTraitExpr(EmptyShell Empty)2839   explicit ExpressionTraitExpr(EmptyShell Empty)
2840       : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false) {}
2841 
getBeginLoc()2842   SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
getEndLoc()2843   SourceLocation getEndLoc() const LLVM_READONLY { return RParen; }
2844 
getTrait()2845   ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2846 
getQueriedExpression()2847   Expr *getQueriedExpression() const { return QueriedExpression; }
2848 
getValue()2849   bool getValue() const { return Value; }
2850 
classof(const Stmt * T)2851   static bool classof(const Stmt *T) {
2852     return T->getStmtClass() == ExpressionTraitExprClass;
2853   }
2854 
2855   // Iterators
children()2856   child_range children() {
2857     return child_range(child_iterator(), child_iterator());
2858   }
2859 
children()2860   const_child_range children() const {
2861     return const_child_range(const_child_iterator(), const_child_iterator());
2862   }
2863 };
2864 
2865 /// A reference to an overloaded function set, either an
2866 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2867 class OverloadExpr : public Expr {
2868   friend class ASTStmtReader;
2869   friend class ASTStmtWriter;
2870 
2871   /// The common name of these declarations.
2872   DeclarationNameInfo NameInfo;
2873 
2874   /// The nested-name-specifier that qualifies the name, if any.
2875   NestedNameSpecifierLoc QualifierLoc;
2876 
2877 protected:
2878   OverloadExpr(StmtClass SC, const ASTContext &Context,
2879                NestedNameSpecifierLoc QualifierLoc,
2880                SourceLocation TemplateKWLoc,
2881                const DeclarationNameInfo &NameInfo,
2882                const TemplateArgumentListInfo *TemplateArgs,
2883                UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2884                bool KnownDependent, bool KnownInstantiationDependent,
2885                bool KnownContainsUnexpandedParameterPack);
2886 
2887   OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
2888                bool HasTemplateKWAndArgsInfo);
2889 
2890   /// Return the results. Defined after UnresolvedMemberExpr.
2891   inline DeclAccessPair *getTrailingResults();
getTrailingResults()2892   const DeclAccessPair *getTrailingResults() const {
2893     return const_cast<OverloadExpr *>(this)->getTrailingResults();
2894   }
2895 
2896   /// Return the optional template keyword and arguments info.
2897   /// Defined after UnresolvedMemberExpr.
2898   inline ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo();
getTrailingASTTemplateKWAndArgsInfo()2899   const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const {
2900     return const_cast<OverloadExpr *>(this)
2901         ->getTrailingASTTemplateKWAndArgsInfo();
2902   }
2903 
2904   /// Return the optional template arguments. Defined after
2905   /// UnresolvedMemberExpr.
2906   inline TemplateArgumentLoc *getTrailingTemplateArgumentLoc();
getTrailingTemplateArgumentLoc()2907   const TemplateArgumentLoc *getTrailingTemplateArgumentLoc() const {
2908     return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
2909   }
2910 
hasTemplateKWAndArgsInfo()2911   bool hasTemplateKWAndArgsInfo() const {
2912     return OverloadExprBits.HasTemplateKWAndArgsInfo;
2913   }
2914 
2915 public:
2916   struct FindResult {
2917     OverloadExpr *Expression;
2918     bool IsAddressOfOperand;
2919     bool HasFormOfMemberPointer;
2920   };
2921 
2922   /// Finds the overloaded expression in the given expression \p E of
2923   /// OverloadTy.
2924   ///
2925   /// \return the expression (which must be there) and true if it has
2926   /// the particular form of a member pointer expression
find(Expr * E)2927   static FindResult find(Expr *E) {
2928     assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2929 
2930     FindResult Result;
2931 
2932     E = E->IgnoreParens();
2933     if (isa<UnaryOperator>(E)) {
2934       assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2935       E = cast<UnaryOperator>(E)->getSubExpr();
2936       auto *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2937 
2938       Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2939       Result.IsAddressOfOperand = true;
2940       Result.Expression = Ovl;
2941     } else {
2942       Result.HasFormOfMemberPointer = false;
2943       Result.IsAddressOfOperand = false;
2944       Result.Expression = cast<OverloadExpr>(E);
2945     }
2946 
2947     return Result;
2948   }
2949 
2950   /// Gets the naming class of this lookup, if any.
2951   /// Defined after UnresolvedMemberExpr.
2952   inline CXXRecordDecl *getNamingClass();
getNamingClass()2953   const CXXRecordDecl *getNamingClass() const {
2954     return const_cast<OverloadExpr *>(this)->getNamingClass();
2955   }
2956 
2957   using decls_iterator = UnresolvedSetImpl::iterator;
2958 
decls_begin()2959   decls_iterator decls_begin() const {
2960     return UnresolvedSetIterator(getTrailingResults());
2961   }
decls_end()2962   decls_iterator decls_end() const {
2963     return UnresolvedSetIterator(getTrailingResults() + getNumDecls());
2964   }
decls()2965   llvm::iterator_range<decls_iterator> decls() const {
2966     return llvm::make_range(decls_begin(), decls_end());
2967   }
2968 
2969   /// Gets the number of declarations in the unresolved set.
getNumDecls()2970   unsigned getNumDecls() const { return OverloadExprBits.NumResults; }
2971 
2972   /// Gets the full name info.
getNameInfo()2973   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2974 
2975   /// Gets the name looked up.
getName()2976   DeclarationName getName() const { return NameInfo.getName(); }
2977 
2978   /// Gets the location of the name.
getNameLoc()2979   SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2980 
2981   /// Fetches the nested-name qualifier, if one was given.
getQualifier()2982   NestedNameSpecifier *getQualifier() const {
2983     return QualifierLoc.getNestedNameSpecifier();
2984   }
2985 
2986   /// Fetches the nested-name qualifier with source-location
2987   /// information, if one was given.
getQualifierLoc()2988   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2989 
2990   /// Retrieve the location of the template keyword preceding
2991   /// this name, if any.
getTemplateKeywordLoc()2992   SourceLocation getTemplateKeywordLoc() const {
2993     if (!hasTemplateKWAndArgsInfo())
2994       return SourceLocation();
2995     return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc;
2996   }
2997 
2998   /// Retrieve the location of the left angle bracket starting the
2999   /// explicit template argument list following the name, if any.
getLAngleLoc()3000   SourceLocation getLAngleLoc() const {
3001     if (!hasTemplateKWAndArgsInfo())
3002       return SourceLocation();
3003     return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc;
3004   }
3005 
3006   /// Retrieve the location of the right angle bracket ending the
3007   /// explicit template argument list following the name, if any.
getRAngleLoc()3008   SourceLocation getRAngleLoc() const {
3009     if (!hasTemplateKWAndArgsInfo())
3010       return SourceLocation();
3011     return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc;
3012   }
3013 
3014   /// Determines whether the name was preceded by the template keyword.
hasTemplateKeyword()3015   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3016 
3017   /// Determines whether this expression had explicit template arguments.
hasExplicitTemplateArgs()3018   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3019 
getTemplateArgs()3020   TemplateArgumentLoc const *getTemplateArgs() const {
3021     if (!hasExplicitTemplateArgs())
3022       return nullptr;
3023     return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
3024   }
3025 
getNumTemplateArgs()3026   unsigned getNumTemplateArgs() const {
3027     if (!hasExplicitTemplateArgs())
3028       return 0;
3029 
3030     return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs;
3031   }
3032 
template_arguments()3033   ArrayRef<TemplateArgumentLoc> template_arguments() const {
3034     return {getTemplateArgs(), getNumTemplateArgs()};
3035   }
3036 
3037   /// Copies the template arguments into the given structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)3038   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3039     if (hasExplicitTemplateArgs())
3040       getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List);
3041   }
3042 
classof(const Stmt * T)3043   static bool classof(const Stmt *T) {
3044     return T->getStmtClass() == UnresolvedLookupExprClass ||
3045            T->getStmtClass() == UnresolvedMemberExprClass;
3046   }
3047 };
3048 
3049 /// A reference to a name which we were able to look up during
3050 /// parsing but could not resolve to a specific declaration.
3051 ///
3052 /// This arises in several ways:
3053 ///   * we might be waiting for argument-dependent lookup;
3054 ///   * the name might resolve to an overloaded function;
3055 /// and eventually:
3056 ///   * the lookup might have included a function template.
3057 ///
3058 /// These never include UnresolvedUsingValueDecls, which are always class
3059 /// members and therefore appear only in UnresolvedMemberLookupExprs.
3060 class UnresolvedLookupExpr final
3061     : public OverloadExpr,
3062       private llvm::TrailingObjects<UnresolvedLookupExpr, DeclAccessPair,
3063                                     ASTTemplateKWAndArgsInfo,
3064                                     TemplateArgumentLoc> {
3065   friend class ASTStmtReader;
3066   friend class OverloadExpr;
3067   friend TrailingObjects;
3068 
3069   /// The naming class (C++ [class.access.base]p5) of the lookup, if
3070   /// any.  This can generally be recalculated from the context chain,
3071   /// but that can be fairly expensive for unqualified lookups.
3072   CXXRecordDecl *NamingClass;
3073 
3074   // UnresolvedLookupExpr is followed by several trailing objects.
3075   // They are in order:
3076   //
3077   // * An array of getNumResults() DeclAccessPair for the results. These are
3078   //   undesugared, which is to say, they may include UsingShadowDecls.
3079   //   Access is relative to the naming class.
3080   //
3081   // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
3082   //   template keyword and arguments. Present if and only if
3083   //   hasTemplateKWAndArgsInfo().
3084   //
3085   // * An array of getNumTemplateArgs() TemplateArgumentLoc containing
3086   //   location information for the explicitly specified template arguments.
3087 
3088   UnresolvedLookupExpr(const ASTContext &Context, CXXRecordDecl *NamingClass,
3089                        NestedNameSpecifierLoc QualifierLoc,
3090                        SourceLocation TemplateKWLoc,
3091                        const DeclarationNameInfo &NameInfo, bool RequiresADL,
3092                        bool Overloaded,
3093                        const TemplateArgumentListInfo *TemplateArgs,
3094                        UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3095 
3096   UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults,
3097                        bool HasTemplateKWAndArgsInfo);
3098 
numTrailingObjects(OverloadToken<DeclAccessPair>)3099   unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const {
3100     return getNumDecls();
3101   }
3102 
numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>)3103   unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3104     return hasTemplateKWAndArgsInfo();
3105   }
3106 
3107 public:
3108   static UnresolvedLookupExpr *
3109   Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
3110          NestedNameSpecifierLoc QualifierLoc,
3111          const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
3112          UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3113 
3114   static UnresolvedLookupExpr *
3115   Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
3116          NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
3117          const DeclarationNameInfo &NameInfo, bool RequiresADL,
3118          const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
3119          UnresolvedSetIterator End);
3120 
3121   static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context,
3122                                            unsigned NumResults,
3123                                            bool HasTemplateKWAndArgsInfo,
3124                                            unsigned NumTemplateArgs);
3125 
3126   /// True if this declaration should be extended by
3127   /// argument-dependent lookup.
requiresADL()3128   bool requiresADL() const { return UnresolvedLookupExprBits.RequiresADL; }
3129 
3130   /// True if this lookup is overloaded.
isOverloaded()3131   bool isOverloaded() const { return UnresolvedLookupExprBits.Overloaded; }
3132 
3133   /// Gets the 'naming class' (in the sense of C++0x
3134   /// [class.access.base]p5) of the lookup.  This is the scope
3135   /// that was looked in to find these results.
getNamingClass()3136   CXXRecordDecl *getNamingClass() { return NamingClass; }
getNamingClass()3137   const CXXRecordDecl *getNamingClass() const { return NamingClass; }
3138 
getBeginLoc()3139   SourceLocation getBeginLoc() const LLVM_READONLY {
3140     if (NestedNameSpecifierLoc l = getQualifierLoc())
3141       return l.getBeginLoc();
3142     return getNameInfo().getBeginLoc();
3143   }
3144 
getEndLoc()3145   SourceLocation getEndLoc() const LLVM_READONLY {
3146     if (hasExplicitTemplateArgs())
3147       return getRAngleLoc();
3148     return getNameInfo().getEndLoc();
3149   }
3150 
children()3151   child_range children() {
3152     return child_range(child_iterator(), child_iterator());
3153   }
3154 
children()3155   const_child_range children() const {
3156     return const_child_range(const_child_iterator(), const_child_iterator());
3157   }
3158 
classof(const Stmt * T)3159   static bool classof(const Stmt *T) {
3160     return T->getStmtClass() == UnresolvedLookupExprClass;
3161   }
3162 };
3163 
3164 /// A qualified reference to a name whose declaration cannot
3165 /// yet be resolved.
3166 ///
3167 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
3168 /// it expresses a reference to a declaration such as
3169 /// X<T>::value. The difference, however, is that an
3170 /// DependentScopeDeclRefExpr node is used only within C++ templates when
3171 /// the qualification (e.g., X<T>::) refers to a dependent type. In
3172 /// this case, X<T>::value cannot resolve to a declaration because the
3173 /// declaration will differ from one instantiation of X<T> to the
3174 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
3175 /// qualifier (X<T>::) and the name of the entity being referenced
3176 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
3177 /// declaration can be found.
3178 class DependentScopeDeclRefExpr final
3179     : public Expr,
3180       private llvm::TrailingObjects<DependentScopeDeclRefExpr,
3181                                     ASTTemplateKWAndArgsInfo,
3182                                     TemplateArgumentLoc> {
3183   friend class ASTStmtReader;
3184   friend class ASTStmtWriter;
3185   friend TrailingObjects;
3186 
3187   /// The nested-name-specifier that qualifies this unresolved
3188   /// declaration name.
3189   NestedNameSpecifierLoc QualifierLoc;
3190 
3191   /// The name of the entity we will be referencing.
3192   DeclarationNameInfo NameInfo;
3193 
3194   DependentScopeDeclRefExpr(QualType Ty, NestedNameSpecifierLoc QualifierLoc,
3195                             SourceLocation TemplateKWLoc,
3196                             const DeclarationNameInfo &NameInfo,
3197                             const TemplateArgumentListInfo *Args);
3198 
numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>)3199   size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3200     return hasTemplateKWAndArgsInfo();
3201   }
3202 
hasTemplateKWAndArgsInfo()3203   bool hasTemplateKWAndArgsInfo() const {
3204     return DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo;
3205   }
3206 
3207 public:
3208   static DependentScopeDeclRefExpr *
3209   Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
3210          SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
3211          const TemplateArgumentListInfo *TemplateArgs);
3212 
3213   static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &Context,
3214                                                 bool HasTemplateKWAndArgsInfo,
3215                                                 unsigned NumTemplateArgs);
3216 
3217   /// Retrieve the name that this expression refers to.
getNameInfo()3218   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3219 
3220   /// Retrieve the name that this expression refers to.
getDeclName()3221   DeclarationName getDeclName() const { return NameInfo.getName(); }
3222 
3223   /// Retrieve the location of the name within the expression.
3224   ///
3225   /// For example, in "X<T>::value" this is the location of "value".
getLocation()3226   SourceLocation getLocation() const { return NameInfo.getLoc(); }
3227 
3228   /// Retrieve the nested-name-specifier that qualifies the
3229   /// name, with source location information.
getQualifierLoc()3230   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3231 
3232   /// Retrieve the nested-name-specifier that qualifies this
3233   /// declaration.
getQualifier()3234   NestedNameSpecifier *getQualifier() const {
3235     return QualifierLoc.getNestedNameSpecifier();
3236   }
3237 
3238   /// Retrieve the location of the template keyword preceding
3239   /// this name, if any.
getTemplateKeywordLoc()3240   SourceLocation getTemplateKeywordLoc() const {
3241     if (!hasTemplateKWAndArgsInfo())
3242       return SourceLocation();
3243     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3244   }
3245 
3246   /// Retrieve the location of the left angle bracket starting the
3247   /// explicit template argument list following the name, if any.
getLAngleLoc()3248   SourceLocation getLAngleLoc() const {
3249     if (!hasTemplateKWAndArgsInfo())
3250       return SourceLocation();
3251     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3252   }
3253 
3254   /// Retrieve the location of the right angle bracket ending the
3255   /// explicit template argument list following the name, if any.
getRAngleLoc()3256   SourceLocation getRAngleLoc() const {
3257     if (!hasTemplateKWAndArgsInfo())
3258       return SourceLocation();
3259     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3260   }
3261 
3262   /// Determines whether the name was preceded by the template keyword.
hasTemplateKeyword()3263   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3264 
3265   /// Determines whether this lookup had explicit template arguments.
hasExplicitTemplateArgs()3266   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3267 
3268   /// Copies the template arguments (if present) into the given
3269   /// structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)3270   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3271     if (hasExplicitTemplateArgs())
3272       getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3273           getTrailingObjects<TemplateArgumentLoc>(), List);
3274   }
3275 
getTemplateArgs()3276   TemplateArgumentLoc const *getTemplateArgs() const {
3277     if (!hasExplicitTemplateArgs())
3278       return nullptr;
3279 
3280     return getTrailingObjects<TemplateArgumentLoc>();
3281   }
3282 
getNumTemplateArgs()3283   unsigned getNumTemplateArgs() const {
3284     if (!hasExplicitTemplateArgs())
3285       return 0;
3286 
3287     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3288   }
3289 
template_arguments()3290   ArrayRef<TemplateArgumentLoc> template_arguments() const {
3291     return {getTemplateArgs(), getNumTemplateArgs()};
3292   }
3293 
3294   /// Note: getBeginLoc() is the start of the whole DependentScopeDeclRefExpr,
3295   /// and differs from getLocation().getStart().
getBeginLoc()3296   SourceLocation getBeginLoc() const LLVM_READONLY {
3297     return QualifierLoc.getBeginLoc();
3298   }
3299 
getEndLoc()3300   SourceLocation getEndLoc() const LLVM_READONLY {
3301     if (hasExplicitTemplateArgs())
3302       return getRAngleLoc();
3303     return getLocation();
3304   }
3305 
classof(const Stmt * T)3306   static bool classof(const Stmt *T) {
3307     return T->getStmtClass() == DependentScopeDeclRefExprClass;
3308   }
3309 
children()3310   child_range children() {
3311     return child_range(child_iterator(), child_iterator());
3312   }
3313 
children()3314   const_child_range children() const {
3315     return const_child_range(const_child_iterator(), const_child_iterator());
3316   }
3317 };
3318 
3319 /// Represents an expression -- generally a full-expression -- that
3320 /// introduces cleanups to be run at the end of the sub-expression's
3321 /// evaluation.  The most common source of expression-introduced
3322 /// cleanups is temporary objects in C++, but several other kinds of
3323 /// expressions can create cleanups, including basically every
3324 /// call in ARC that returns an Objective-C pointer.
3325 ///
3326 /// This expression also tracks whether the sub-expression contains a
3327 /// potentially-evaluated block literal.  The lifetime of a block
3328 /// literal is the extent of the enclosing scope.
3329 class ExprWithCleanups final
3330     : public FullExpr,
3331       private llvm::TrailingObjects<
3332           ExprWithCleanups,
3333           llvm::PointerUnion<BlockDecl *, CompoundLiteralExpr *>> {
3334 public:
3335   /// The type of objects that are kept in the cleanup.
3336   /// It's useful to remember the set of blocks and block-scoped compound
3337   /// literals; we could also remember the set of temporaries, but there's
3338   /// currently no need.
3339   using CleanupObject = llvm::PointerUnion<BlockDecl *, CompoundLiteralExpr *>;
3340 
3341 private:
3342   friend class ASTStmtReader;
3343   friend TrailingObjects;
3344 
3345   ExprWithCleanups(EmptyShell, unsigned NumObjects);
3346   ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects,
3347                    ArrayRef<CleanupObject> Objects);
3348 
3349 public:
3350   static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
3351                                   unsigned numObjects);
3352 
3353   static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
3354                                   bool CleanupsHaveSideEffects,
3355                                   ArrayRef<CleanupObject> objects);
3356 
getObjects()3357   ArrayRef<CleanupObject> getObjects() const {
3358     return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(),
3359                               getNumObjects());
3360   }
3361 
getNumObjects()3362   unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
3363 
getObject(unsigned i)3364   CleanupObject getObject(unsigned i) const {
3365     assert(i < getNumObjects() && "Index out of range");
3366     return getObjects()[i];
3367   }
3368 
cleanupsHaveSideEffects()3369   bool cleanupsHaveSideEffects() const {
3370     return ExprWithCleanupsBits.CleanupsHaveSideEffects;
3371   }
3372 
getBeginLoc()3373   SourceLocation getBeginLoc() const LLVM_READONLY {
3374     return SubExpr->getBeginLoc();
3375   }
3376 
getEndLoc()3377   SourceLocation getEndLoc() const LLVM_READONLY {
3378     return SubExpr->getEndLoc();
3379   }
3380 
3381   // Implement isa/cast/dyncast/etc.
classof(const Stmt * T)3382   static bool classof(const Stmt *T) {
3383     return T->getStmtClass() == ExprWithCleanupsClass;
3384   }
3385 
3386   // Iterators
children()3387   child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
3388 
children()3389   const_child_range children() const {
3390     return const_child_range(&SubExpr, &SubExpr + 1);
3391   }
3392 };
3393 
3394 /// Describes an explicit type conversion that uses functional
3395 /// notion but could not be resolved because one or more arguments are
3396 /// type-dependent.
3397 ///
3398 /// The explicit type conversions expressed by
3399 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
3400 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
3401 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
3402 /// type-dependent. For example, this would occur in a template such
3403 /// as:
3404 ///
3405 /// \code
3406 ///   template<typename T, typename A1>
3407 ///   inline T make_a(const A1& a1) {
3408 ///     return T(a1);
3409 ///   }
3410 /// \endcode
3411 ///
3412 /// When the returned expression is instantiated, it may resolve to a
3413 /// constructor call, conversion function call, or some kind of type
3414 /// conversion.
3415 class CXXUnresolvedConstructExpr final
3416     : public Expr,
3417       private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> {
3418   friend class ASTStmtReader;
3419   friend TrailingObjects;
3420 
3421   /// The type being constructed.
3422   TypeSourceInfo *TSI;
3423 
3424   /// The location of the left parentheses ('(').
3425   SourceLocation LParenLoc;
3426 
3427   /// The location of the right parentheses (')').
3428   SourceLocation RParenLoc;
3429 
3430   CXXUnresolvedConstructExpr(QualType T, TypeSourceInfo *TSI,
3431                              SourceLocation LParenLoc, ArrayRef<Expr *> Args,
3432                              SourceLocation RParenLoc);
3433 
CXXUnresolvedConstructExpr(EmptyShell Empty,unsigned NumArgs)3434   CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
3435       : Expr(CXXUnresolvedConstructExprClass, Empty), TSI(nullptr) {
3436     CXXUnresolvedConstructExprBits.NumArgs = NumArgs;
3437   }
3438 
3439 public:
3440   static CXXUnresolvedConstructExpr *Create(const ASTContext &Context,
3441                                             QualType T, TypeSourceInfo *TSI,
3442                                             SourceLocation LParenLoc,
3443                                             ArrayRef<Expr *> Args,
3444                                             SourceLocation RParenLoc);
3445 
3446   static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &Context,
3447                                                  unsigned NumArgs);
3448 
3449   /// Retrieve the type that is being constructed, as specified
3450   /// in the source code.
getTypeAsWritten()3451   QualType getTypeAsWritten() const { return TSI->getType(); }
3452 
3453   /// Retrieve the type source information for the type being
3454   /// constructed.
getTypeSourceInfo()3455   TypeSourceInfo *getTypeSourceInfo() const { return TSI; }
3456 
3457   /// Retrieve the location of the left parentheses ('(') that
3458   /// precedes the argument list.
getLParenLoc()3459   SourceLocation getLParenLoc() const { return LParenLoc; }
setLParenLoc(SourceLocation L)3460   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3461 
3462   /// Retrieve the location of the right parentheses (')') that
3463   /// follows the argument list.
getRParenLoc()3464   SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)3465   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3466 
3467   /// Determine whether this expression models list-initialization.
3468   /// If so, there will be exactly one subexpression, which will be
3469   /// an InitListExpr.
isListInitialization()3470   bool isListInitialization() const { return LParenLoc.isInvalid(); }
3471 
3472   /// Retrieve the number of arguments.
getNumArgs()3473   unsigned getNumArgs() const { return CXXUnresolvedConstructExprBits.NumArgs; }
3474 
3475   using arg_iterator = Expr **;
3476   using arg_range = llvm::iterator_range<arg_iterator>;
3477 
arg_begin()3478   arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); }
arg_end()3479   arg_iterator arg_end() { return arg_begin() + getNumArgs(); }
arguments()3480   arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
3481 
3482   using const_arg_iterator = const Expr* const *;
3483   using const_arg_range = llvm::iterator_range<const_arg_iterator>;
3484 
arg_begin()3485   const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); }
arg_end()3486   const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); }
arguments()3487   const_arg_range arguments() const {
3488     return const_arg_range(arg_begin(), arg_end());
3489   }
3490 
getArg(unsigned I)3491   Expr *getArg(unsigned I) {
3492     assert(I < getNumArgs() && "Argument index out-of-range");
3493     return arg_begin()[I];
3494   }
3495 
getArg(unsigned I)3496   const Expr *getArg(unsigned I) const {
3497     assert(I < getNumArgs() && "Argument index out-of-range");
3498     return arg_begin()[I];
3499   }
3500 
setArg(unsigned I,Expr * E)3501   void setArg(unsigned I, Expr *E) {
3502     assert(I < getNumArgs() && "Argument index out-of-range");
3503     arg_begin()[I] = E;
3504   }
3505 
3506   SourceLocation getBeginLoc() const LLVM_READONLY;
getEndLoc()3507   SourceLocation getEndLoc() const LLVM_READONLY {
3508     if (!RParenLoc.isValid() && getNumArgs() > 0)
3509       return getArg(getNumArgs() - 1)->getEndLoc();
3510     return RParenLoc;
3511   }
3512 
classof(const Stmt * T)3513   static bool classof(const Stmt *T) {
3514     return T->getStmtClass() == CXXUnresolvedConstructExprClass;
3515   }
3516 
3517   // Iterators
children()3518   child_range children() {
3519     auto **begin = reinterpret_cast<Stmt **>(arg_begin());
3520     return child_range(begin, begin + getNumArgs());
3521   }
3522 
children()3523   const_child_range children() const {
3524     auto **begin = reinterpret_cast<Stmt **>(
3525         const_cast<CXXUnresolvedConstructExpr *>(this)->arg_begin());
3526     return const_child_range(begin, begin + getNumArgs());
3527   }
3528 };
3529 
3530 /// Represents a C++ member access expression where the actual
3531 /// member referenced could not be resolved because the base
3532 /// expression or the member name was dependent.
3533 ///
3534 /// Like UnresolvedMemberExprs, these can be either implicit or
3535 /// explicit accesses.  It is only possible to get one of these with
3536 /// an implicit access if a qualifier is provided.
3537 class CXXDependentScopeMemberExpr final
3538     : public Expr,
3539       private llvm::TrailingObjects<CXXDependentScopeMemberExpr,
3540                                     ASTTemplateKWAndArgsInfo,
3541                                     TemplateArgumentLoc, NamedDecl *> {
3542   friend class ASTStmtReader;
3543   friend class ASTStmtWriter;
3544   friend TrailingObjects;
3545 
3546   /// The expression for the base pointer or class reference,
3547   /// e.g., the \c x in x.f.  Can be null in implicit accesses.
3548   Stmt *Base;
3549 
3550   /// The type of the base expression.  Never null, even for
3551   /// implicit accesses.
3552   QualType BaseType;
3553 
3554   /// The nested-name-specifier that precedes the member name, if any.
3555   /// FIXME: This could be in principle store as a trailing object.
3556   /// However the performance impact of doing so should be investigated first.
3557   NestedNameSpecifierLoc QualifierLoc;
3558 
3559   /// The member to which this member expression refers, which
3560   /// can be name, overloaded operator, or destructor.
3561   ///
3562   /// FIXME: could also be a template-id
3563   DeclarationNameInfo MemberNameInfo;
3564 
3565   // CXXDependentScopeMemberExpr is followed by several trailing objects,
3566   // some of which optional. They are in order:
3567   //
3568   // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
3569   //   template keyword and arguments. Present if and only if
3570   //   hasTemplateKWAndArgsInfo().
3571   //
3572   // * An array of getNumTemplateArgs() TemplateArgumentLoc containing location
3573   //   information for the explicitly specified template arguments.
3574   //
3575   // * An optional NamedDecl *. In a qualified member access expression such
3576   //   as t->Base::f, this member stores the resolves of name lookup in the
3577   //   context of the member access expression, to be used at instantiation
3578   //   time. Present if and only if hasFirstQualifierFoundInScope().
3579 
hasTemplateKWAndArgsInfo()3580   bool hasTemplateKWAndArgsInfo() const {
3581     return CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo;
3582   }
3583 
hasFirstQualifierFoundInScope()3584   bool hasFirstQualifierFoundInScope() const {
3585     return CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope;
3586   }
3587 
numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>)3588   unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3589     return hasTemplateKWAndArgsInfo();
3590   }
3591 
numTrailingObjects(OverloadToken<TemplateArgumentLoc>)3592   unsigned numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const {
3593     return getNumTemplateArgs();
3594   }
3595 
numTrailingObjects(OverloadToken<NamedDecl * >)3596   unsigned numTrailingObjects(OverloadToken<NamedDecl *>) const {
3597     return hasFirstQualifierFoundInScope();
3598   }
3599 
3600   CXXDependentScopeMemberExpr(const ASTContext &Ctx, Expr *Base,
3601                               QualType BaseType, bool IsArrow,
3602                               SourceLocation OperatorLoc,
3603                               NestedNameSpecifierLoc QualifierLoc,
3604                               SourceLocation TemplateKWLoc,
3605                               NamedDecl *FirstQualifierFoundInScope,
3606                               DeclarationNameInfo MemberNameInfo,
3607                               const TemplateArgumentListInfo *TemplateArgs);
3608 
3609   CXXDependentScopeMemberExpr(EmptyShell Empty, bool HasTemplateKWAndArgsInfo,
3610                               bool HasFirstQualifierFoundInScope);
3611 
3612 public:
3613   static CXXDependentScopeMemberExpr *
3614   Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
3615          SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
3616          SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
3617          DeclarationNameInfo MemberNameInfo,
3618          const TemplateArgumentListInfo *TemplateArgs);
3619 
3620   static CXXDependentScopeMemberExpr *
3621   CreateEmpty(const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo,
3622               unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope);
3623 
3624   /// True if this is an implicit access, i.e. one in which the
3625   /// member being accessed was not written in the source.  The source
3626   /// location of the operator is invalid in this case.
isImplicitAccess()3627   bool isImplicitAccess() const {
3628     if (!Base)
3629       return true;
3630     return cast<Expr>(Base)->isImplicitCXXThis();
3631   }
3632 
3633   /// Retrieve the base object of this member expressions,
3634   /// e.g., the \c x in \c x.m.
getBase()3635   Expr *getBase() const {
3636     assert(!isImplicitAccess());
3637     return cast<Expr>(Base);
3638   }
3639 
getBaseType()3640   QualType getBaseType() const { return BaseType; }
3641 
3642   /// Determine whether this member expression used the '->'
3643   /// operator; otherwise, it used the '.' operator.
isArrow()3644   bool isArrow() const { return CXXDependentScopeMemberExprBits.IsArrow; }
3645 
3646   /// Retrieve the location of the '->' or '.' operator.
getOperatorLoc()3647   SourceLocation getOperatorLoc() const {
3648     return CXXDependentScopeMemberExprBits.OperatorLoc;
3649   }
3650 
3651   /// Retrieve the nested-name-specifier that qualifies the member name.
getQualifier()3652   NestedNameSpecifier *getQualifier() const {
3653     return QualifierLoc.getNestedNameSpecifier();
3654   }
3655 
3656   /// Retrieve the nested-name-specifier that qualifies the member
3657   /// name, with source location information.
getQualifierLoc()3658   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3659 
3660   /// Retrieve the first part of the nested-name-specifier that was
3661   /// found in the scope of the member access expression when the member access
3662   /// was initially parsed.
3663   ///
3664   /// This function only returns a useful result when member access expression
3665   /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3666   /// returned by this function describes what was found by unqualified name
3667   /// lookup for the identifier "Base" within the scope of the member access
3668   /// expression itself. At template instantiation time, this information is
3669   /// combined with the results of name lookup into the type of the object
3670   /// expression itself (the class type of x).
getFirstQualifierFoundInScope()3671   NamedDecl *getFirstQualifierFoundInScope() const {
3672     if (!hasFirstQualifierFoundInScope())
3673       return nullptr;
3674     return *getTrailingObjects<NamedDecl *>();
3675   }
3676 
3677   /// Retrieve the name of the member that this expression refers to.
getMemberNameInfo()3678   const DeclarationNameInfo &getMemberNameInfo() const {
3679     return MemberNameInfo;
3680   }
3681 
3682   /// Retrieve the name of the member that this expression refers to.
getMember()3683   DeclarationName getMember() const { return MemberNameInfo.getName(); }
3684 
3685   // Retrieve the location of the name of the member that this
3686   // expression refers to.
getMemberLoc()3687   SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3688 
3689   /// Retrieve the location of the template keyword preceding the
3690   /// member name, if any.
getTemplateKeywordLoc()3691   SourceLocation getTemplateKeywordLoc() const {
3692     if (!hasTemplateKWAndArgsInfo())
3693       return SourceLocation();
3694     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3695   }
3696 
3697   /// Retrieve the location of the left angle bracket starting the
3698   /// explicit template argument list following the member name, if any.
getLAngleLoc()3699   SourceLocation getLAngleLoc() const {
3700     if (!hasTemplateKWAndArgsInfo())
3701       return SourceLocation();
3702     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3703   }
3704 
3705   /// Retrieve the location of the right angle bracket ending the
3706   /// explicit template argument list following the member name, if any.
getRAngleLoc()3707   SourceLocation getRAngleLoc() const {
3708     if (!hasTemplateKWAndArgsInfo())
3709       return SourceLocation();
3710     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3711   }
3712 
3713   /// Determines whether the member name was preceded by the template keyword.
hasTemplateKeyword()3714   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3715 
3716   /// Determines whether this member expression actually had a C++
3717   /// template argument list explicitly specified, e.g., x.f<int>.
hasExplicitTemplateArgs()3718   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3719 
3720   /// Copies the template arguments (if present) into the given
3721   /// structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)3722   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3723     if (hasExplicitTemplateArgs())
3724       getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3725           getTrailingObjects<TemplateArgumentLoc>(), List);
3726   }
3727 
3728   /// Retrieve the template arguments provided as part of this
3729   /// template-id.
getTemplateArgs()3730   const TemplateArgumentLoc *getTemplateArgs() const {
3731     if (!hasExplicitTemplateArgs())
3732       return nullptr;
3733 
3734     return getTrailingObjects<TemplateArgumentLoc>();
3735   }
3736 
3737   /// Retrieve the number of template arguments provided as part of this
3738   /// template-id.
getNumTemplateArgs()3739   unsigned getNumTemplateArgs() const {
3740     if (!hasExplicitTemplateArgs())
3741       return 0;
3742 
3743     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3744   }
3745 
template_arguments()3746   ArrayRef<TemplateArgumentLoc> template_arguments() const {
3747     return {getTemplateArgs(), getNumTemplateArgs()};
3748   }
3749 
getBeginLoc()3750   SourceLocation getBeginLoc() const LLVM_READONLY {
3751     if (!isImplicitAccess())
3752       return Base->getBeginLoc();
3753     if (getQualifier())
3754       return getQualifierLoc().getBeginLoc();
3755     return MemberNameInfo.getBeginLoc();
3756   }
3757 
getEndLoc()3758   SourceLocation getEndLoc() const LLVM_READONLY {
3759     if (hasExplicitTemplateArgs())
3760       return getRAngleLoc();
3761     return MemberNameInfo.getEndLoc();
3762   }
3763 
classof(const Stmt * T)3764   static bool classof(const Stmt *T) {
3765     return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3766   }
3767 
3768   // Iterators
children()3769   child_range children() {
3770     if (isImplicitAccess())
3771       return child_range(child_iterator(), child_iterator());
3772     return child_range(&Base, &Base + 1);
3773   }
3774 
children()3775   const_child_range children() const {
3776     if (isImplicitAccess())
3777       return const_child_range(const_child_iterator(), const_child_iterator());
3778     return const_child_range(&Base, &Base + 1);
3779   }
3780 };
3781 
3782 /// Represents a C++ member access expression for which lookup
3783 /// produced a set of overloaded functions.
3784 ///
3785 /// The member access may be explicit or implicit:
3786 /// \code
3787 ///    struct A {
3788 ///      int a, b;
3789 ///      int explicitAccess() { return this->a + this->A::b; }
3790 ///      int implicitAccess() { return a + A::b; }
3791 ///    };
3792 /// \endcode
3793 ///
3794 /// In the final AST, an explicit access always becomes a MemberExpr.
3795 /// An implicit access may become either a MemberExpr or a
3796 /// DeclRefExpr, depending on whether the member is static.
3797 class UnresolvedMemberExpr final
3798     : public OverloadExpr,
3799       private llvm::TrailingObjects<UnresolvedMemberExpr, DeclAccessPair,
3800                                     ASTTemplateKWAndArgsInfo,
3801                                     TemplateArgumentLoc> {
3802   friend class ASTStmtReader;
3803   friend class OverloadExpr;
3804   friend TrailingObjects;
3805 
3806   /// The expression for the base pointer or class reference,
3807   /// e.g., the \c x in x.f.
3808   ///
3809   /// This can be null if this is an 'unbased' member expression.
3810   Stmt *Base;
3811 
3812   /// The type of the base expression; never null.
3813   QualType BaseType;
3814 
3815   /// The location of the '->' or '.' operator.
3816   SourceLocation OperatorLoc;
3817 
3818   // UnresolvedMemberExpr is followed by several trailing objects.
3819   // They are in order:
3820   //
3821   // * An array of getNumResults() DeclAccessPair for the results. These are
3822   //   undesugared, which is to say, they may include UsingShadowDecls.
3823   //   Access is relative to the naming class.
3824   //
3825   // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
3826   //   template keyword and arguments. Present if and only if
3827   //   hasTemplateKWAndArgsInfo().
3828   //
3829   // * An array of getNumTemplateArgs() TemplateArgumentLoc containing
3830   //   location information for the explicitly specified template arguments.
3831 
3832   UnresolvedMemberExpr(const ASTContext &Context, bool HasUnresolvedUsing,
3833                        Expr *Base, QualType BaseType, bool IsArrow,
3834                        SourceLocation OperatorLoc,
3835                        NestedNameSpecifierLoc QualifierLoc,
3836                        SourceLocation TemplateKWLoc,
3837                        const DeclarationNameInfo &MemberNameInfo,
3838                        const TemplateArgumentListInfo *TemplateArgs,
3839                        UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3840 
3841   UnresolvedMemberExpr(EmptyShell Empty, unsigned NumResults,
3842                        bool HasTemplateKWAndArgsInfo);
3843 
numTrailingObjects(OverloadToken<DeclAccessPair>)3844   unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const {
3845     return getNumDecls();
3846   }
3847 
numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>)3848   unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3849     return hasTemplateKWAndArgsInfo();
3850   }
3851 
3852 public:
3853   static UnresolvedMemberExpr *
3854   Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
3855          QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
3856          NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
3857          const DeclarationNameInfo &MemberNameInfo,
3858          const TemplateArgumentListInfo *TemplateArgs,
3859          UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3860 
3861   static UnresolvedMemberExpr *CreateEmpty(const ASTContext &Context,
3862                                            unsigned NumResults,
3863                                            bool HasTemplateKWAndArgsInfo,
3864                                            unsigned NumTemplateArgs);
3865 
3866   /// True if this is an implicit access, i.e., one in which the
3867   /// member being accessed was not written in the source.
3868   ///
3869   /// The source location of the operator is invalid in this case.
3870   bool isImplicitAccess() const;
3871 
3872   /// Retrieve the base object of this member expressions,
3873   /// e.g., the \c x in \c x.m.
getBase()3874   Expr *getBase() {
3875     assert(!isImplicitAccess());
3876     return cast<Expr>(Base);
3877   }
getBase()3878   const Expr *getBase() const {
3879     assert(!isImplicitAccess());
3880     return cast<Expr>(Base);
3881   }
3882 
getBaseType()3883   QualType getBaseType() const { return BaseType; }
3884 
3885   /// Determine whether the lookup results contain an unresolved using
3886   /// declaration.
hasUnresolvedUsing()3887   bool hasUnresolvedUsing() const {
3888     return UnresolvedMemberExprBits.HasUnresolvedUsing;
3889   }
3890 
3891   /// Determine whether this member expression used the '->'
3892   /// operator; otherwise, it used the '.' operator.
isArrow()3893   bool isArrow() const { return UnresolvedMemberExprBits.IsArrow; }
3894 
3895   /// Retrieve the location of the '->' or '.' operator.
getOperatorLoc()3896   SourceLocation getOperatorLoc() const { return OperatorLoc; }
3897 
3898   /// Retrieve the naming class of this lookup.
3899   CXXRecordDecl *getNamingClass();
getNamingClass()3900   const CXXRecordDecl *getNamingClass() const {
3901     return const_cast<UnresolvedMemberExpr *>(this)->getNamingClass();
3902   }
3903 
3904   /// Retrieve the full name info for the member that this expression
3905   /// refers to.
getMemberNameInfo()3906   const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3907 
3908   /// Retrieve the name of the member that this expression refers to.
getMemberName()3909   DeclarationName getMemberName() const { return getName(); }
3910 
3911   /// Retrieve the location of the name of the member that this
3912   /// expression refers to.
getMemberLoc()3913   SourceLocation getMemberLoc() const { return getNameLoc(); }
3914 
3915   /// Return the preferred location (the member name) for the arrow when
3916   /// diagnosing a problem with this expression.
getExprLoc()3917   SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
3918 
getBeginLoc()3919   SourceLocation getBeginLoc() const LLVM_READONLY {
3920     if (!isImplicitAccess())
3921       return Base->getBeginLoc();
3922     if (NestedNameSpecifierLoc l = getQualifierLoc())
3923       return l.getBeginLoc();
3924     return getMemberNameInfo().getBeginLoc();
3925   }
3926 
getEndLoc()3927   SourceLocation getEndLoc() const LLVM_READONLY {
3928     if (hasExplicitTemplateArgs())
3929       return getRAngleLoc();
3930     return getMemberNameInfo().getEndLoc();
3931   }
3932 
classof(const Stmt * T)3933   static bool classof(const Stmt *T) {
3934     return T->getStmtClass() == UnresolvedMemberExprClass;
3935   }
3936 
3937   // Iterators
children()3938   child_range children() {
3939     if (isImplicitAccess())
3940       return child_range(child_iterator(), child_iterator());
3941     return child_range(&Base, &Base + 1);
3942   }
3943 
children()3944   const_child_range children() const {
3945     if (isImplicitAccess())
3946       return const_child_range(const_child_iterator(), const_child_iterator());
3947     return const_child_range(&Base, &Base + 1);
3948   }
3949 };
3950 
getTrailingResults()3951 DeclAccessPair *OverloadExpr::getTrailingResults() {
3952   if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3953     return ULE->getTrailingObjects<DeclAccessPair>();
3954   return cast<UnresolvedMemberExpr>(this)->getTrailingObjects<DeclAccessPair>();
3955 }
3956 
getTrailingASTTemplateKWAndArgsInfo()3957 ASTTemplateKWAndArgsInfo *OverloadExpr::getTrailingASTTemplateKWAndArgsInfo() {
3958   if (!hasTemplateKWAndArgsInfo())
3959     return nullptr;
3960 
3961   if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3962     return ULE->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3963   return cast<UnresolvedMemberExpr>(this)
3964       ->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3965 }
3966 
getTrailingTemplateArgumentLoc()3967 TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() {
3968   if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3969     return ULE->getTrailingObjects<TemplateArgumentLoc>();
3970   return cast<UnresolvedMemberExpr>(this)
3971       ->getTrailingObjects<TemplateArgumentLoc>();
3972 }
3973 
getNamingClass()3974 CXXRecordDecl *OverloadExpr::getNamingClass() {
3975   if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3976     return ULE->getNamingClass();
3977   return cast<UnresolvedMemberExpr>(this)->getNamingClass();
3978 }
3979 
3980 /// Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
3981 ///
3982 /// The noexcept expression tests whether a given expression might throw. Its
3983 /// result is a boolean constant.
3984 class CXXNoexceptExpr : public Expr {
3985   friend class ASTStmtReader;
3986 
3987   Stmt *Operand;
3988   SourceRange Range;
3989 
3990 public:
CXXNoexceptExpr(QualType Ty,Expr * Operand,CanThrowResult Val,SourceLocation Keyword,SourceLocation RParen)3991   CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3992                   SourceLocation Keyword, SourceLocation RParen)
3993       : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary),
3994         Operand(Operand), Range(Keyword, RParen) {
3995     CXXNoexceptExprBits.Value = Val == CT_Cannot;
3996     setDependence(computeDependence(this, Val));
3997   }
3998 
CXXNoexceptExpr(EmptyShell Empty)3999   CXXNoexceptExpr(EmptyShell Empty) : Expr(CXXNoexceptExprClass, Empty) {}
4000 
getOperand()4001   Expr *getOperand() const { return static_cast<Expr *>(Operand); }
4002 
getBeginLoc()4003   SourceLocation getBeginLoc() const { return Range.getBegin(); }
getEndLoc()4004   SourceLocation getEndLoc() const { return Range.getEnd(); }
getSourceRange()4005   SourceRange getSourceRange() const { return Range; }
4006 
getValue()4007   bool getValue() const { return CXXNoexceptExprBits.Value; }
4008 
classof(const Stmt * T)4009   static bool classof(const Stmt *T) {
4010     return T->getStmtClass() == CXXNoexceptExprClass;
4011   }
4012 
4013   // Iterators
children()4014   child_range children() { return child_range(&Operand, &Operand + 1); }
4015 
children()4016   const_child_range children() const {
4017     return const_child_range(&Operand, &Operand + 1);
4018   }
4019 };
4020 
4021 /// Represents a C++11 pack expansion that produces a sequence of
4022 /// expressions.
4023 ///
4024 /// A pack expansion expression contains a pattern (which itself is an
4025 /// expression) followed by an ellipsis. For example:
4026 ///
4027 /// \code
4028 /// template<typename F, typename ...Types>
4029 /// void forward(F f, Types &&...args) {
4030 ///   f(static_cast<Types&&>(args)...);
4031 /// }
4032 /// \endcode
4033 ///
4034 /// Here, the argument to the function object \c f is a pack expansion whose
4035 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
4036 /// template is instantiated, the pack expansion will instantiate to zero or
4037 /// or more function arguments to the function object \c f.
4038 class PackExpansionExpr : public Expr {
4039   friend class ASTStmtReader;
4040   friend class ASTStmtWriter;
4041 
4042   SourceLocation EllipsisLoc;
4043 
4044   /// The number of expansions that will be produced by this pack
4045   /// expansion expression, if known.
4046   ///
4047   /// When zero, the number of expansions is not known. Otherwise, this value
4048   /// is the number of expansions + 1.
4049   unsigned NumExpansions;
4050 
4051   Stmt *Pattern;
4052 
4053 public:
PackExpansionExpr(QualType T,Expr * Pattern,SourceLocation EllipsisLoc,Optional<unsigned> NumExpansions)4054   PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
4055                     Optional<unsigned> NumExpansions)
4056       : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
4057              Pattern->getObjectKind()),
4058         EllipsisLoc(EllipsisLoc),
4059         NumExpansions(NumExpansions ? *NumExpansions + 1 : 0),
4060         Pattern(Pattern) {
4061     setDependence(computeDependence(this));
4062   }
4063 
PackExpansionExpr(EmptyShell Empty)4064   PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) {}
4065 
4066   /// Retrieve the pattern of the pack expansion.
getPattern()4067   Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
4068 
4069   /// Retrieve the pattern of the pack expansion.
getPattern()4070   const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
4071 
4072   /// Retrieve the location of the ellipsis that describes this pack
4073   /// expansion.
getEllipsisLoc()4074   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
4075 
4076   /// Determine the number of expansions that will be produced when
4077   /// this pack expansion is instantiated, if already known.
getNumExpansions()4078   Optional<unsigned> getNumExpansions() const {
4079     if (NumExpansions)
4080       return NumExpansions - 1;
4081 
4082     return None;
4083   }
4084 
getBeginLoc()4085   SourceLocation getBeginLoc() const LLVM_READONLY {
4086     return Pattern->getBeginLoc();
4087   }
4088 
getEndLoc()4089   SourceLocation getEndLoc() const LLVM_READONLY { return EllipsisLoc; }
4090 
classof(const Stmt * T)4091   static bool classof(const Stmt *T) {
4092     return T->getStmtClass() == PackExpansionExprClass;
4093   }
4094 
4095   // Iterators
children()4096   child_range children() {
4097     return child_range(&Pattern, &Pattern + 1);
4098   }
4099 
children()4100   const_child_range children() const {
4101     return const_child_range(&Pattern, &Pattern + 1);
4102   }
4103 };
4104 
4105 /// Represents an expression that computes the length of a parameter
4106 /// pack.
4107 ///
4108 /// \code
4109 /// template<typename ...Types>
4110 /// struct count {
4111 ///   static const unsigned value = sizeof...(Types);
4112 /// };
4113 /// \endcode
4114 class SizeOfPackExpr final
4115     : public Expr,
4116       private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> {
4117   friend class ASTStmtReader;
4118   friend class ASTStmtWriter;
4119   friend TrailingObjects;
4120 
4121   /// The location of the \c sizeof keyword.
4122   SourceLocation OperatorLoc;
4123 
4124   /// The location of the name of the parameter pack.
4125   SourceLocation PackLoc;
4126 
4127   /// The location of the closing parenthesis.
4128   SourceLocation RParenLoc;
4129 
4130   /// The length of the parameter pack, if known.
4131   ///
4132   /// When this expression is not value-dependent, this is the length of
4133   /// the pack. When the expression was parsed rather than instantiated
4134   /// (and thus is value-dependent), this is zero.
4135   ///
4136   /// After partial substitution into a sizeof...(X) expression (for instance,
4137   /// within an alias template or during function template argument deduction),
4138   /// we store a trailing array of partially-substituted TemplateArguments,
4139   /// and this is the length of that array.
4140   unsigned Length;
4141 
4142   /// The parameter pack.
4143   NamedDecl *Pack = nullptr;
4144 
4145   /// Create an expression that computes the length of
4146   /// the given parameter pack.
SizeOfPackExpr(QualType SizeType,SourceLocation OperatorLoc,NamedDecl * Pack,SourceLocation PackLoc,SourceLocation RParenLoc,Optional<unsigned> Length,ArrayRef<TemplateArgument> PartialArgs)4147   SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
4148                  SourceLocation PackLoc, SourceLocation RParenLoc,
4149                  Optional<unsigned> Length,
4150                  ArrayRef<TemplateArgument> PartialArgs)
4151       : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary),
4152         OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
4153         Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
4154     assert((!Length || PartialArgs.empty()) &&
4155            "have partial args for non-dependent sizeof... expression");
4156     auto *Args = getTrailingObjects<TemplateArgument>();
4157     std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
4158     setDependence(Length ? ExprDependence::None
4159                          : ExprDependence::ValueInstantiation);
4160   }
4161 
4162   /// Create an empty expression.
SizeOfPackExpr(EmptyShell Empty,unsigned NumPartialArgs)4163   SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs)
4164       : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {}
4165 
4166 public:
4167   static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
4168                                 NamedDecl *Pack, SourceLocation PackLoc,
4169                                 SourceLocation RParenLoc,
4170                                 Optional<unsigned> Length = None,
4171                                 ArrayRef<TemplateArgument> PartialArgs = None);
4172   static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
4173                                             unsigned NumPartialArgs);
4174 
4175   /// Determine the location of the 'sizeof' keyword.
getOperatorLoc()4176   SourceLocation getOperatorLoc() const { return OperatorLoc; }
4177 
4178   /// Determine the location of the parameter pack.
getPackLoc()4179   SourceLocation getPackLoc() const { return PackLoc; }
4180 
4181   /// Determine the location of the right parenthesis.
getRParenLoc()4182   SourceLocation getRParenLoc() const { return RParenLoc; }
4183 
4184   /// Retrieve the parameter pack.
getPack()4185   NamedDecl *getPack() const { return Pack; }
4186 
4187   /// Retrieve the length of the parameter pack.
4188   ///
4189   /// This routine may only be invoked when the expression is not
4190   /// value-dependent.
getPackLength()4191   unsigned getPackLength() const {
4192     assert(!isValueDependent() &&
4193            "Cannot get the length of a value-dependent pack size expression");
4194     return Length;
4195   }
4196 
4197   /// Determine whether this represents a partially-substituted sizeof...
4198   /// expression, such as is produced for:
4199   ///
4200   ///   template<typename ...Ts> using X = int[sizeof...(Ts)];
4201   ///   template<typename ...Us> void f(X<Us..., 1, 2, 3, Us...>);
isPartiallySubstituted()4202   bool isPartiallySubstituted() const {
4203     return isValueDependent() && Length;
4204   }
4205 
4206   /// Get
getPartialArguments()4207   ArrayRef<TemplateArgument> getPartialArguments() const {
4208     assert(isPartiallySubstituted());
4209     const auto *Args = getTrailingObjects<TemplateArgument>();
4210     return llvm::makeArrayRef(Args, Args + Length);
4211   }
4212 
getBeginLoc()4213   SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
getEndLoc()4214   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4215 
classof(const Stmt * T)4216   static bool classof(const Stmt *T) {
4217     return T->getStmtClass() == SizeOfPackExprClass;
4218   }
4219 
4220   // Iterators
children()4221   child_range children() {
4222     return child_range(child_iterator(), child_iterator());
4223   }
4224 
children()4225   const_child_range children() const {
4226     return const_child_range(const_child_iterator(), const_child_iterator());
4227   }
4228 };
4229 
4230 /// Represents a reference to a non-type template parameter
4231 /// that has been substituted with a template argument.
4232 class SubstNonTypeTemplateParmExpr : public Expr {
4233   friend class ASTReader;
4234   friend class ASTStmtReader;
4235 
4236   /// The replaced parameter and a flag indicating if it was a reference
4237   /// parameter. For class NTTPs, we can't determine that based on the value
4238   /// category alone.
4239   llvm::PointerIntPair<NonTypeTemplateParmDecl*, 1, bool> ParamAndRef;
4240 
4241   /// The replacement expression.
4242   Stmt *Replacement;
4243 
SubstNonTypeTemplateParmExpr(EmptyShell Empty)4244   explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
4245       : Expr(SubstNonTypeTemplateParmExprClass, Empty) {}
4246 
4247 public:
SubstNonTypeTemplateParmExpr(QualType Ty,ExprValueKind ValueKind,SourceLocation Loc,NonTypeTemplateParmDecl * Param,bool RefParam,Expr * Replacement)4248   SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind,
4249                                SourceLocation Loc,
4250                                NonTypeTemplateParmDecl *Param, bool RefParam,
4251                                Expr *Replacement)
4252       : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary),
4253         ParamAndRef(Param, RefParam), Replacement(Replacement) {
4254     SubstNonTypeTemplateParmExprBits.NameLoc = Loc;
4255     setDependence(computeDependence(this));
4256   }
4257 
getNameLoc()4258   SourceLocation getNameLoc() const {
4259     return SubstNonTypeTemplateParmExprBits.NameLoc;
4260   }
getBeginLoc()4261   SourceLocation getBeginLoc() const { return getNameLoc(); }
getEndLoc()4262   SourceLocation getEndLoc() const { return getNameLoc(); }
4263 
getReplacement()4264   Expr *getReplacement() const { return cast<Expr>(Replacement); }
4265 
getParameter()4266   NonTypeTemplateParmDecl *getParameter() const {
4267     return ParamAndRef.getPointer();
4268   }
4269 
isReferenceParameter()4270   bool isReferenceParameter() const { return ParamAndRef.getInt(); }
4271 
4272   /// Determine the substituted type of the template parameter.
4273   QualType getParameterType(const ASTContext &Ctx) const;
4274 
classof(const Stmt * s)4275   static bool classof(const Stmt *s) {
4276     return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
4277   }
4278 
4279   // Iterators
children()4280   child_range children() { return child_range(&Replacement, &Replacement + 1); }
4281 
children()4282   const_child_range children() const {
4283     return const_child_range(&Replacement, &Replacement + 1);
4284   }
4285 };
4286 
4287 /// Represents a reference to a non-type template parameter pack that
4288 /// has been substituted with a non-template argument pack.
4289 ///
4290 /// When a pack expansion in the source code contains multiple parameter packs
4291 /// and those parameter packs correspond to different levels of template
4292 /// parameter lists, this node is used to represent a non-type template
4293 /// parameter pack from an outer level, which has already had its argument pack
4294 /// substituted but that still lives within a pack expansion that itself
4295 /// could not be instantiated. When actually performing a substitution into
4296 /// that pack expansion (e.g., when all template parameters have corresponding
4297 /// arguments), this type will be replaced with the appropriate underlying
4298 /// expression at the current pack substitution index.
4299 class SubstNonTypeTemplateParmPackExpr : public Expr {
4300   friend class ASTReader;
4301   friend class ASTStmtReader;
4302 
4303   /// The non-type template parameter pack itself.
4304   NonTypeTemplateParmDecl *Param;
4305 
4306   /// A pointer to the set of template arguments that this
4307   /// parameter pack is instantiated with.
4308   const TemplateArgument *Arguments;
4309 
4310   /// The number of template arguments in \c Arguments.
4311   unsigned NumArguments;
4312 
4313   /// The location of the non-type template parameter pack reference.
4314   SourceLocation NameLoc;
4315 
SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)4316   explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
4317       : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) {}
4318 
4319 public:
4320   SubstNonTypeTemplateParmPackExpr(QualType T,
4321                                    ExprValueKind ValueKind,
4322                                    NonTypeTemplateParmDecl *Param,
4323                                    SourceLocation NameLoc,
4324                                    const TemplateArgument &ArgPack);
4325 
4326   /// Retrieve the non-type template parameter pack being substituted.
getParameterPack()4327   NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
4328 
4329   /// Retrieve the location of the parameter pack name.
getParameterPackLocation()4330   SourceLocation getParameterPackLocation() const { return NameLoc; }
4331 
4332   /// Retrieve the template argument pack containing the substituted
4333   /// template arguments.
4334   TemplateArgument getArgumentPack() const;
4335 
getBeginLoc()4336   SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; }
getEndLoc()4337   SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; }
4338 
classof(const Stmt * T)4339   static bool classof(const Stmt *T) {
4340     return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
4341   }
4342 
4343   // Iterators
children()4344   child_range children() {
4345     return child_range(child_iterator(), child_iterator());
4346   }
4347 
children()4348   const_child_range children() const {
4349     return const_child_range(const_child_iterator(), const_child_iterator());
4350   }
4351 };
4352 
4353 /// Represents a reference to a function parameter pack or init-capture pack
4354 /// that has been substituted but not yet expanded.
4355 ///
4356 /// When a pack expansion contains multiple parameter packs at different levels,
4357 /// this node is used to represent a function parameter pack at an outer level
4358 /// which we have already substituted to refer to expanded parameters, but where
4359 /// the containing pack expansion cannot yet be expanded.
4360 ///
4361 /// \code
4362 /// template<typename...Ts> struct S {
4363 ///   template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
4364 /// };
4365 /// template struct S<int, int>;
4366 /// \endcode
4367 class FunctionParmPackExpr final
4368     : public Expr,
4369       private llvm::TrailingObjects<FunctionParmPackExpr, VarDecl *> {
4370   friend class ASTReader;
4371   friend class ASTStmtReader;
4372   friend TrailingObjects;
4373 
4374   /// The function parameter pack which was referenced.
4375   VarDecl *ParamPack;
4376 
4377   /// The location of the function parameter pack reference.
4378   SourceLocation NameLoc;
4379 
4380   /// The number of expansions of this pack.
4381   unsigned NumParameters;
4382 
4383   FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
4384                        SourceLocation NameLoc, unsigned NumParams,
4385                        VarDecl *const *Params);
4386 
4387 public:
4388   static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
4389                                       VarDecl *ParamPack,
4390                                       SourceLocation NameLoc,
4391                                       ArrayRef<VarDecl *> Params);
4392   static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
4393                                            unsigned NumParams);
4394 
4395   /// Get the parameter pack which this expression refers to.
getParameterPack()4396   VarDecl *getParameterPack() const { return ParamPack; }
4397 
4398   /// Get the location of the parameter pack.
getParameterPackLocation()4399   SourceLocation getParameterPackLocation() const { return NameLoc; }
4400 
4401   /// Iterators over the parameters which the parameter pack expanded
4402   /// into.
4403   using iterator = VarDecl * const *;
begin()4404   iterator begin() const { return getTrailingObjects<VarDecl *>(); }
end()4405   iterator end() const { return begin() + NumParameters; }
4406 
4407   /// Get the number of parameters in this parameter pack.
getNumExpansions()4408   unsigned getNumExpansions() const { return NumParameters; }
4409 
4410   /// Get an expansion of the parameter pack by index.
getExpansion(unsigned I)4411   VarDecl *getExpansion(unsigned I) const { return begin()[I]; }
4412 
getBeginLoc()4413   SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; }
getEndLoc()4414   SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; }
4415 
classof(const Stmt * T)4416   static bool classof(const Stmt *T) {
4417     return T->getStmtClass() == FunctionParmPackExprClass;
4418   }
4419 
children()4420   child_range children() {
4421     return child_range(child_iterator(), child_iterator());
4422   }
4423 
children()4424   const_child_range children() const {
4425     return const_child_range(const_child_iterator(), const_child_iterator());
4426   }
4427 };
4428 
4429 /// Represents a prvalue temporary that is written into memory so that
4430 /// a reference can bind to it.
4431 ///
4432 /// Prvalue expressions are materialized when they need to have an address
4433 /// in memory for a reference to bind to. This happens when binding a
4434 /// reference to the result of a conversion, e.g.,
4435 ///
4436 /// \code
4437 /// const int &r = 1.0;
4438 /// \endcode
4439 ///
4440 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
4441 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
4442 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
4443 /// (either an lvalue or an xvalue, depending on the kind of reference binding
4444 /// to it), maintaining the invariant that references always bind to glvalues.
4445 ///
4446 /// Reference binding and copy-elision can both extend the lifetime of a
4447 /// temporary. When either happens, the expression will also track the
4448 /// declaration which is responsible for the lifetime extension.
4449 class MaterializeTemporaryExpr : public Expr {
4450 private:
4451   friend class ASTStmtReader;
4452   friend class ASTStmtWriter;
4453 
4454   llvm::PointerUnion<Stmt *, LifetimeExtendedTemporaryDecl *> State;
4455 
4456 public:
4457   MaterializeTemporaryExpr(QualType T, Expr *Temporary,
4458                            bool BoundToLvalueReference,
4459                            LifetimeExtendedTemporaryDecl *MTD = nullptr);
4460 
MaterializeTemporaryExpr(EmptyShell Empty)4461   MaterializeTemporaryExpr(EmptyShell Empty)
4462       : Expr(MaterializeTemporaryExprClass, Empty) {}
4463 
4464   /// Retrieve the temporary-generating subexpression whose value will
4465   /// be materialized into a glvalue.
getSubExpr()4466   Expr *getSubExpr() const {
4467     return cast<Expr>(
4468         State.is<Stmt *>()
4469             ? State.get<Stmt *>()
4470             : State.get<LifetimeExtendedTemporaryDecl *>()->getTemporaryExpr());
4471   }
4472 
4473   /// Retrieve the storage duration for the materialized temporary.
getStorageDuration()4474   StorageDuration getStorageDuration() const {
4475     return State.is<Stmt *>() ? SD_FullExpression
4476                               : State.get<LifetimeExtendedTemporaryDecl *>()
4477                                     ->getStorageDuration();
4478   }
4479 
4480   /// Get the storage for the constant value of a materialized temporary
4481   /// of static storage duration.
getOrCreateValue(bool MayCreate)4482   APValue *getOrCreateValue(bool MayCreate) const {
4483     assert(State.is<LifetimeExtendedTemporaryDecl *>() &&
4484            "the temporary has not been lifetime extended");
4485     return State.get<LifetimeExtendedTemporaryDecl *>()->getOrCreateValue(
4486         MayCreate);
4487   }
4488 
getLifetimeExtendedTemporaryDecl()4489   LifetimeExtendedTemporaryDecl *getLifetimeExtendedTemporaryDecl() {
4490     return State.dyn_cast<LifetimeExtendedTemporaryDecl *>();
4491   }
4492   const LifetimeExtendedTemporaryDecl *
getLifetimeExtendedTemporaryDecl()4493   getLifetimeExtendedTemporaryDecl() const {
4494     return State.dyn_cast<LifetimeExtendedTemporaryDecl *>();
4495   }
4496 
4497   /// Get the declaration which triggered the lifetime-extension of this
4498   /// temporary, if any.
getExtendingDecl()4499   ValueDecl *getExtendingDecl() {
4500     return State.is<Stmt *>() ? nullptr
4501                               : State.get<LifetimeExtendedTemporaryDecl *>()
4502                                     ->getExtendingDecl();
4503   }
getExtendingDecl()4504   const ValueDecl *getExtendingDecl() const {
4505     return const_cast<MaterializeTemporaryExpr *>(this)->getExtendingDecl();
4506   }
4507 
4508   void setExtendingDecl(ValueDecl *ExtendedBy, unsigned ManglingNumber);
4509 
getManglingNumber()4510   unsigned getManglingNumber() const {
4511     return State.is<Stmt *>() ? 0
4512                               : State.get<LifetimeExtendedTemporaryDecl *>()
4513                                     ->getManglingNumber();
4514   }
4515 
4516   /// Determine whether this materialized temporary is bound to an
4517   /// lvalue reference; otherwise, it's bound to an rvalue reference.
isBoundToLvalueReference()4518   bool isBoundToLvalueReference() const {
4519     return getValueKind() == VK_LValue;
4520   }
4521 
4522   /// Determine whether this temporary object is usable in constant
4523   /// expressions, as specified in C++20 [expr.const]p4.
4524   bool isUsableInConstantExpressions(const ASTContext &Context) const;
4525 
getBeginLoc()4526   SourceLocation getBeginLoc() const LLVM_READONLY {
4527     return getSubExpr()->getBeginLoc();
4528   }
4529 
getEndLoc()4530   SourceLocation getEndLoc() const LLVM_READONLY {
4531     return getSubExpr()->getEndLoc();
4532   }
4533 
classof(const Stmt * T)4534   static bool classof(const Stmt *T) {
4535     return T->getStmtClass() == MaterializeTemporaryExprClass;
4536   }
4537 
4538   // Iterators
children()4539   child_range children() {
4540     return State.is<Stmt *>()
4541                ? child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1)
4542                : State.get<LifetimeExtendedTemporaryDecl *>()->childrenExpr();
4543   }
4544 
children()4545   const_child_range children() const {
4546     return State.is<Stmt *>()
4547                ? const_child_range(State.getAddrOfPtr1(),
4548                                    State.getAddrOfPtr1() + 1)
4549                : const_cast<const LifetimeExtendedTemporaryDecl *>(
4550                      State.get<LifetimeExtendedTemporaryDecl *>())
4551                      ->childrenExpr();
4552   }
4553 };
4554 
4555 /// Represents a folding of a pack over an operator.
4556 ///
4557 /// This expression is always dependent and represents a pack expansion of the
4558 /// forms:
4559 ///
4560 ///    ( expr op ... )
4561 ///    ( ... op expr )
4562 ///    ( expr op ... op expr )
4563 class CXXFoldExpr : public Expr {
4564   friend class ASTStmtReader;
4565   friend class ASTStmtWriter;
4566 
4567   enum SubExpr { Callee, LHS, RHS, Count };
4568 
4569   SourceLocation LParenLoc;
4570   SourceLocation EllipsisLoc;
4571   SourceLocation RParenLoc;
4572   // When 0, the number of expansions is not known. Otherwise, this is one more
4573   // than the number of expansions.
4574   unsigned NumExpansions;
4575   Stmt *SubExprs[SubExpr::Count];
4576   BinaryOperatorKind Opcode;
4577 
4578 public:
CXXFoldExpr(QualType T,UnresolvedLookupExpr * Callee,SourceLocation LParenLoc,Expr * LHS,BinaryOperatorKind Opcode,SourceLocation EllipsisLoc,Expr * RHS,SourceLocation RParenLoc,Optional<unsigned> NumExpansions)4579   CXXFoldExpr(QualType T, UnresolvedLookupExpr *Callee,
4580               SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Opcode,
4581               SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc,
4582               Optional<unsigned> NumExpansions)
4583       : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary), LParenLoc(LParenLoc),
4584         EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
4585         NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), Opcode(Opcode) {
4586     SubExprs[SubExpr::Callee] = Callee;
4587     SubExprs[SubExpr::LHS] = LHS;
4588     SubExprs[SubExpr::RHS] = RHS;
4589     setDependence(computeDependence(this));
4590   }
4591 
CXXFoldExpr(EmptyShell Empty)4592   CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
4593 
getCallee()4594   UnresolvedLookupExpr *getCallee() const {
4595     return static_cast<UnresolvedLookupExpr *>(SubExprs[SubExpr::Callee]);
4596   }
getLHS()4597   Expr *getLHS() const { return static_cast<Expr*>(SubExprs[SubExpr::LHS]); }
getRHS()4598   Expr *getRHS() const { return static_cast<Expr*>(SubExprs[SubExpr::RHS]); }
4599 
4600   /// Does this produce a right-associated sequence of operators?
isRightFold()4601   bool isRightFold() const {
4602     return getLHS() && getLHS()->containsUnexpandedParameterPack();
4603   }
4604 
4605   /// Does this produce a left-associated sequence of operators?
isLeftFold()4606   bool isLeftFold() const { return !isRightFold(); }
4607 
4608   /// Get the pattern, that is, the operand that contains an unexpanded pack.
getPattern()4609   Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
4610 
4611   /// Get the operand that doesn't contain a pack, for a binary fold.
getInit()4612   Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
4613 
getEllipsisLoc()4614   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
getOperator()4615   BinaryOperatorKind getOperator() const { return Opcode; }
4616 
getNumExpansions()4617   Optional<unsigned> getNumExpansions() const {
4618     if (NumExpansions)
4619       return NumExpansions - 1;
4620     return None;
4621   }
4622 
getBeginLoc()4623   SourceLocation getBeginLoc() const LLVM_READONLY {
4624     if (LParenLoc.isValid())
4625       return LParenLoc;
4626     if (isLeftFold())
4627       return getEllipsisLoc();
4628     return getLHS()->getBeginLoc();
4629   }
4630 
getEndLoc()4631   SourceLocation getEndLoc() const LLVM_READONLY {
4632     if (RParenLoc.isValid())
4633       return RParenLoc;
4634     if (isRightFold())
4635       return getEllipsisLoc();
4636     return getRHS()->getEndLoc();
4637   }
4638 
classof(const Stmt * T)4639   static bool classof(const Stmt *T) {
4640     return T->getStmtClass() == CXXFoldExprClass;
4641   }
4642 
4643   // Iterators
children()4644   child_range children() {
4645     return child_range(SubExprs, SubExprs + SubExpr::Count);
4646   }
4647 
children()4648   const_child_range children() const {
4649     return const_child_range(SubExprs, SubExprs + SubExpr::Count);
4650   }
4651 };
4652 
4653 /// Represents an expression that might suspend coroutine execution;
4654 /// either a co_await or co_yield expression.
4655 ///
4656 /// Evaluation of this expression first evaluates its 'ready' expression. If
4657 /// that returns 'false':
4658 ///  -- execution of the coroutine is suspended
4659 ///  -- the 'suspend' expression is evaluated
4660 ///     -- if the 'suspend' expression returns 'false', the coroutine is
4661 ///        resumed
4662 ///     -- otherwise, control passes back to the resumer.
4663 /// If the coroutine is not suspended, or when it is resumed, the 'resume'
4664 /// expression is evaluated, and its result is the result of the overall
4665 /// expression.
4666 class CoroutineSuspendExpr : public Expr {
4667   friend class ASTStmtReader;
4668 
4669   SourceLocation KeywordLoc;
4670 
4671   enum SubExpr { Common, Ready, Suspend, Resume, Count };
4672 
4673   Stmt *SubExprs[SubExpr::Count];
4674   OpaqueValueExpr *OpaqueValue = nullptr;
4675 
4676 public:
CoroutineSuspendExpr(StmtClass SC,SourceLocation KeywordLoc,Expr * Common,Expr * Ready,Expr * Suspend,Expr * Resume,OpaqueValueExpr * OpaqueValue)4677   CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Common,
4678                        Expr *Ready, Expr *Suspend, Expr *Resume,
4679                        OpaqueValueExpr *OpaqueValue)
4680       : Expr(SC, Resume->getType(), Resume->getValueKind(),
4681              Resume->getObjectKind()),
4682         KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) {
4683     SubExprs[SubExpr::Common] = Common;
4684     SubExprs[SubExpr::Ready] = Ready;
4685     SubExprs[SubExpr::Suspend] = Suspend;
4686     SubExprs[SubExpr::Resume] = Resume;
4687     setDependence(computeDependence(this));
4688   }
4689 
CoroutineSuspendExpr(StmtClass SC,SourceLocation KeywordLoc,QualType Ty,Expr * Common)4690   CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty,
4691                        Expr *Common)
4692       : Expr(SC, Ty, VK_RValue, OK_Ordinary), KeywordLoc(KeywordLoc) {
4693     assert(Common->isTypeDependent() && Ty->isDependentType() &&
4694            "wrong constructor for non-dependent co_await/co_yield expression");
4695     SubExprs[SubExpr::Common] = Common;
4696     SubExprs[SubExpr::Ready] = nullptr;
4697     SubExprs[SubExpr::Suspend] = nullptr;
4698     SubExprs[SubExpr::Resume] = nullptr;
4699     setDependence(computeDependence(this));
4700   }
4701 
CoroutineSuspendExpr(StmtClass SC,EmptyShell Empty)4702   CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
4703     SubExprs[SubExpr::Common] = nullptr;
4704     SubExprs[SubExpr::Ready] = nullptr;
4705     SubExprs[SubExpr::Suspend] = nullptr;
4706     SubExprs[SubExpr::Resume] = nullptr;
4707   }
4708 
getKeywordLoc()4709   SourceLocation getKeywordLoc() const { return KeywordLoc; }
4710 
getCommonExpr()4711   Expr *getCommonExpr() const {
4712     return static_cast<Expr*>(SubExprs[SubExpr::Common]);
4713   }
4714 
4715   /// getOpaqueValue - Return the opaque value placeholder.
getOpaqueValue()4716   OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
4717 
getReadyExpr()4718   Expr *getReadyExpr() const {
4719     return static_cast<Expr*>(SubExprs[SubExpr::Ready]);
4720   }
4721 
getSuspendExpr()4722   Expr *getSuspendExpr() const {
4723     return static_cast<Expr*>(SubExprs[SubExpr::Suspend]);
4724   }
4725 
getResumeExpr()4726   Expr *getResumeExpr() const {
4727     return static_cast<Expr*>(SubExprs[SubExpr::Resume]);
4728   }
4729 
getBeginLoc()4730   SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; }
4731 
getEndLoc()4732   SourceLocation getEndLoc() const LLVM_READONLY {
4733     return getCommonExpr()->getEndLoc();
4734   }
4735 
children()4736   child_range children() {
4737     return child_range(SubExprs, SubExprs + SubExpr::Count);
4738   }
4739 
children()4740   const_child_range children() const {
4741     return const_child_range(SubExprs, SubExprs + SubExpr::Count);
4742   }
4743 
classof(const Stmt * T)4744   static bool classof(const Stmt *T) {
4745     return T->getStmtClass() == CoawaitExprClass ||
4746            T->getStmtClass() == CoyieldExprClass;
4747   }
4748 };
4749 
4750 /// Represents a 'co_await' expression.
4751 class CoawaitExpr : public CoroutineSuspendExpr {
4752   friend class ASTStmtReader;
4753 
4754 public:
4755   CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Ready,
4756               Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue,
4757               bool IsImplicit = false)
CoroutineSuspendExpr(CoawaitExprClass,CoawaitLoc,Operand,Ready,Suspend,Resume,OpaqueValue)4758       : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Ready,
4759                              Suspend, Resume, OpaqueValue) {
4760     CoawaitBits.IsImplicit = IsImplicit;
4761   }
4762 
4763   CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand,
4764               bool IsImplicit = false)
CoroutineSuspendExpr(CoawaitExprClass,CoawaitLoc,Ty,Operand)4765       : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand) {
4766     CoawaitBits.IsImplicit = IsImplicit;
4767   }
4768 
CoawaitExpr(EmptyShell Empty)4769   CoawaitExpr(EmptyShell Empty)
4770       : CoroutineSuspendExpr(CoawaitExprClass, Empty) {}
4771 
getOperand()4772   Expr *getOperand() const {
4773     // FIXME: Dig out the actual operand or store it.
4774     return getCommonExpr();
4775   }
4776 
isImplicit()4777   bool isImplicit() const { return CoawaitBits.IsImplicit; }
4778   void setIsImplicit(bool value = true) { CoawaitBits.IsImplicit = value; }
4779 
classof(const Stmt * T)4780   static bool classof(const Stmt *T) {
4781     return T->getStmtClass() == CoawaitExprClass;
4782   }
4783 };
4784 
4785 /// Represents a 'co_await' expression while the type of the promise
4786 /// is dependent.
4787 class DependentCoawaitExpr : public Expr {
4788   friend class ASTStmtReader;
4789 
4790   SourceLocation KeywordLoc;
4791   Stmt *SubExprs[2];
4792 
4793 public:
DependentCoawaitExpr(SourceLocation KeywordLoc,QualType Ty,Expr * Op,UnresolvedLookupExpr * OpCoawait)4794   DependentCoawaitExpr(SourceLocation KeywordLoc, QualType Ty, Expr *Op,
4795                        UnresolvedLookupExpr *OpCoawait)
4796       : Expr(DependentCoawaitExprClass, Ty, VK_RValue, OK_Ordinary),
4797         KeywordLoc(KeywordLoc) {
4798     // NOTE: A co_await expression is dependent on the coroutines promise
4799     // type and may be dependent even when the `Op` expression is not.
4800     assert(Ty->isDependentType() &&
4801            "wrong constructor for non-dependent co_await/co_yield expression");
4802     SubExprs[0] = Op;
4803     SubExprs[1] = OpCoawait;
4804     setDependence(computeDependence(this));
4805   }
4806 
DependentCoawaitExpr(EmptyShell Empty)4807   DependentCoawaitExpr(EmptyShell Empty)
4808       : Expr(DependentCoawaitExprClass, Empty) {}
4809 
getOperand()4810   Expr *getOperand() const { return cast<Expr>(SubExprs[0]); }
4811 
getOperatorCoawaitLookup()4812   UnresolvedLookupExpr *getOperatorCoawaitLookup() const {
4813     return cast<UnresolvedLookupExpr>(SubExprs[1]);
4814   }
4815 
getKeywordLoc()4816   SourceLocation getKeywordLoc() const { return KeywordLoc; }
4817 
getBeginLoc()4818   SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; }
4819 
getEndLoc()4820   SourceLocation getEndLoc() const LLVM_READONLY {
4821     return getOperand()->getEndLoc();
4822   }
4823 
children()4824   child_range children() { return child_range(SubExprs, SubExprs + 2); }
4825 
children()4826   const_child_range children() const {
4827     return const_child_range(SubExprs, SubExprs + 2);
4828   }
4829 
classof(const Stmt * T)4830   static bool classof(const Stmt *T) {
4831     return T->getStmtClass() == DependentCoawaitExprClass;
4832   }
4833 };
4834 
4835 /// Represents a 'co_yield' expression.
4836 class CoyieldExpr : public CoroutineSuspendExpr {
4837   friend class ASTStmtReader;
4838 
4839 public:
CoyieldExpr(SourceLocation CoyieldLoc,Expr * Operand,Expr * Ready,Expr * Suspend,Expr * Resume,OpaqueValueExpr * OpaqueValue)4840   CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Ready,
4841               Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue)
4842       : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Ready,
4843                              Suspend, Resume, OpaqueValue) {}
CoyieldExpr(SourceLocation CoyieldLoc,QualType Ty,Expr * Operand)4844   CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand)
4845       : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand) {}
CoyieldExpr(EmptyShell Empty)4846   CoyieldExpr(EmptyShell Empty)
4847       : CoroutineSuspendExpr(CoyieldExprClass, Empty) {}
4848 
getOperand()4849   Expr *getOperand() const {
4850     // FIXME: Dig out the actual operand or store it.
4851     return getCommonExpr();
4852   }
4853 
classof(const Stmt * T)4854   static bool classof(const Stmt *T) {
4855     return T->getStmtClass() == CoyieldExprClass;
4856   }
4857 };
4858 
4859 /// Represents a C++2a __builtin_bit_cast(T, v) expression. Used to implement
4860 /// std::bit_cast. These can sometimes be evaluated as part of a constant
4861 /// expression, but otherwise CodeGen to a simple memcpy in general.
4862 class BuiltinBitCastExpr final
4863     : public ExplicitCastExpr,
4864       private llvm::TrailingObjects<BuiltinBitCastExpr, CXXBaseSpecifier *> {
4865   friend class ASTStmtReader;
4866   friend class CastExpr;
4867   friend class TrailingObjects;
4868 
4869   SourceLocation KWLoc;
4870   SourceLocation RParenLoc;
4871 
4872 public:
BuiltinBitCastExpr(QualType T,ExprValueKind VK,CastKind CK,Expr * SrcExpr,TypeSourceInfo * DstType,SourceLocation KWLoc,SourceLocation RParenLoc)4873   BuiltinBitCastExpr(QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr,
4874                      TypeSourceInfo *DstType, SourceLocation KWLoc,
4875                      SourceLocation RParenLoc)
4876       : ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0, false,
4877                          DstType),
4878         KWLoc(KWLoc), RParenLoc(RParenLoc) {}
BuiltinBitCastExpr(EmptyShell Empty)4879   BuiltinBitCastExpr(EmptyShell Empty)
4880       : ExplicitCastExpr(BuiltinBitCastExprClass, Empty, 0, false) {}
4881 
getBeginLoc()4882   SourceLocation getBeginLoc() const LLVM_READONLY { return KWLoc; }
getEndLoc()4883   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4884 
classof(const Stmt * T)4885   static bool classof(const Stmt *T) {
4886     return T->getStmtClass() == BuiltinBitCastExprClass;
4887   }
4888 };
4889 
4890 } // namespace clang
4891 
4892 #endif // LLVM_CLANG_AST_EXPRCXX_H
4893