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