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