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