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