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