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