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