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