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