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