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