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