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