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