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/LambdaCapture.h"
21 #include "clang/AST/TemplateBase.h"
22 #include "clang/AST/UnresolvedSet.h"
23 #include "clang/Basic/ExpressionTraits.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 const 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 {
971     assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
972     return Field->getInClassInitializer();
973   }
getExpr()974   Expr *getExpr() {
975     assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
976     return Field->getInClassInitializer();
977   }
978 
getLocStart()979   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
getLocEnd()980   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
981 
classof(const Stmt * T)982   static bool classof(const Stmt *T) {
983     return T->getStmtClass() == CXXDefaultInitExprClass;
984   }
985 
986   // Iterators
children()987   child_range children() { return child_range(); }
988 
989   friend class ASTReader;
990   friend class ASTStmtReader;
991 };
992 
993 /// \brief Represents a C++ temporary.
994 class CXXTemporary {
995   /// \brief The destructor that needs to be called.
996   const CXXDestructorDecl *Destructor;
997 
CXXTemporary(const CXXDestructorDecl * destructor)998   explicit CXXTemporary(const CXXDestructorDecl *destructor)
999     : Destructor(destructor) { }
1000 
1001 public:
1002   static CXXTemporary *Create(const ASTContext &C,
1003                               const CXXDestructorDecl *Destructor);
1004 
getDestructor()1005   const CXXDestructorDecl *getDestructor() const { return Destructor; }
setDestructor(const CXXDestructorDecl * Dtor)1006   void setDestructor(const CXXDestructorDecl *Dtor) {
1007     Destructor = Dtor;
1008   }
1009 };
1010 
1011 /// \brief Represents binding an expression to a temporary.
1012 ///
1013 /// This ensures the destructor is called for the temporary. It should only be
1014 /// needed for non-POD, non-trivially destructable class types. For example:
1015 ///
1016 /// \code
1017 ///   struct S {
1018 ///     S() { }  // User defined constructor makes S non-POD.
1019 ///     ~S() { } // User defined destructor makes it non-trivial.
1020 ///   };
1021 ///   void test() {
1022 ///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
1023 ///   }
1024 /// \endcode
1025 class CXXBindTemporaryExpr : public Expr {
1026   CXXTemporary *Temp;
1027 
1028   Stmt *SubExpr;
1029 
CXXBindTemporaryExpr(CXXTemporary * temp,Expr * SubExpr)1030   CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
1031    : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
1032           VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
1033           SubExpr->isValueDependent(),
1034           SubExpr->isInstantiationDependent(),
1035           SubExpr->containsUnexpandedParameterPack()),
1036      Temp(temp), SubExpr(SubExpr) { }
1037 
1038 public:
CXXBindTemporaryExpr(EmptyShell Empty)1039   CXXBindTemporaryExpr(EmptyShell Empty)
1040     : Expr(CXXBindTemporaryExprClass, Empty), Temp(nullptr), SubExpr(nullptr) {}
1041 
1042   static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
1043                                       Expr* SubExpr);
1044 
getTemporary()1045   CXXTemporary *getTemporary() { return Temp; }
getTemporary()1046   const CXXTemporary *getTemporary() const { return Temp; }
setTemporary(CXXTemporary * T)1047   void setTemporary(CXXTemporary *T) { Temp = T; }
1048 
getSubExpr()1049   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
getSubExpr()1050   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
setSubExpr(Expr * E)1051   void setSubExpr(Expr *E) { SubExpr = E; }
1052 
getLocStart()1053   SourceLocation getLocStart() const LLVM_READONLY {
1054     return SubExpr->getLocStart();
1055   }
getLocEnd()1056   SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
1057 
1058   // Implement isa/cast/dyncast/etc.
classof(const Stmt * T)1059   static bool classof(const Stmt *T) {
1060     return T->getStmtClass() == CXXBindTemporaryExprClass;
1061   }
1062 
1063   // Iterators
children()1064   child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
1065 };
1066 
1067 /// \brief Represents a call to a C++ constructor.
1068 class CXXConstructExpr : public Expr {
1069 public:
1070   enum ConstructionKind {
1071     CK_Complete,
1072     CK_NonVirtualBase,
1073     CK_VirtualBase,
1074     CK_Delegating
1075   };
1076 
1077 private:
1078   CXXConstructorDecl *Constructor;
1079 
1080   SourceLocation Loc;
1081   SourceRange ParenOrBraceRange;
1082   unsigned NumArgs : 16;
1083   bool Elidable : 1;
1084   bool HadMultipleCandidates : 1;
1085   bool ListInitialization : 1;
1086   bool StdInitListInitialization : 1;
1087   bool ZeroInitialization : 1;
1088   unsigned ConstructKind : 2;
1089   Stmt **Args;
1090 
1091 protected:
1092   CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T,
1093                    SourceLocation Loc,
1094                    CXXConstructorDecl *d, bool elidable,
1095                    ArrayRef<Expr *> Args,
1096                    bool HadMultipleCandidates,
1097                    bool ListInitialization,
1098                    bool StdInitListInitialization,
1099                    bool ZeroInitialization,
1100                    ConstructionKind ConstructKind,
1101                    SourceRange ParenOrBraceRange);
1102 
1103   /// \brief Construct an empty C++ construction expression.
CXXConstructExpr(StmtClass SC,EmptyShell Empty)1104   CXXConstructExpr(StmtClass SC, EmptyShell Empty)
1105     : Expr(SC, Empty), Constructor(nullptr), NumArgs(0), Elidable(false),
1106       HadMultipleCandidates(false), ListInitialization(false),
1107       ZeroInitialization(false), ConstructKind(0), Args(nullptr)
1108   { }
1109 
1110 public:
1111   /// \brief Construct an empty C++ construction expression.
CXXConstructExpr(EmptyShell Empty)1112   explicit CXXConstructExpr(EmptyShell Empty)
1113     : Expr(CXXConstructExprClass, Empty), Constructor(nullptr),
1114       NumArgs(0), Elidable(false), HadMultipleCandidates(false),
1115       ListInitialization(false), ZeroInitialization(false),
1116       ConstructKind(0), Args(nullptr)
1117   { }
1118 
1119   static CXXConstructExpr *Create(const ASTContext &C, QualType T,
1120                                   SourceLocation Loc,
1121                                   CXXConstructorDecl *D, bool Elidable,
1122                                   ArrayRef<Expr *> Args,
1123                                   bool HadMultipleCandidates,
1124                                   bool ListInitialization,
1125                                   bool StdInitListInitialization,
1126                                   bool ZeroInitialization,
1127                                   ConstructionKind ConstructKind,
1128                                   SourceRange ParenOrBraceRange);
1129 
getConstructor()1130   CXXConstructorDecl* getConstructor() const { return Constructor; }
setConstructor(CXXConstructorDecl * C)1131   void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
1132 
getLocation()1133   SourceLocation getLocation() const { return Loc; }
setLocation(SourceLocation Loc)1134   void setLocation(SourceLocation Loc) { this->Loc = Loc; }
1135 
1136   /// \brief Whether this construction is elidable.
isElidable()1137   bool isElidable() const { return Elidable; }
setElidable(bool E)1138   void setElidable(bool E) { Elidable = E; }
1139 
1140   /// \brief Whether the referred constructor was resolved from
1141   /// an overloaded set having size greater than 1.
hadMultipleCandidates()1142   bool hadMultipleCandidates() const { return HadMultipleCandidates; }
setHadMultipleCandidates(bool V)1143   void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
1144 
1145   /// \brief Whether this constructor call was written as list-initialization.
isListInitialization()1146   bool isListInitialization() const { return ListInitialization; }
setListInitialization(bool V)1147   void setListInitialization(bool V) { ListInitialization = V; }
1148 
1149   /// \brief Whether this constructor call was written as list-initialization,
1150   /// but was interpreted as forming a std::initializer_list<T> from the list
1151   /// and passing that as a single constructor argument.
1152   /// See C++11 [over.match.list]p1 bullet 1.
isStdInitListInitialization()1153   bool isStdInitListInitialization() const { return StdInitListInitialization; }
setStdInitListInitialization(bool V)1154   void setStdInitListInitialization(bool V) { StdInitListInitialization = V; }
1155 
1156   /// \brief Whether this construction first requires
1157   /// zero-initialization before the initializer is called.
requiresZeroInitialization()1158   bool requiresZeroInitialization() const { return ZeroInitialization; }
setRequiresZeroInitialization(bool ZeroInit)1159   void setRequiresZeroInitialization(bool ZeroInit) {
1160     ZeroInitialization = ZeroInit;
1161   }
1162 
1163   /// \brief Determine whether this constructor is actually constructing
1164   /// a base class (rather than a complete object).
getConstructionKind()1165   ConstructionKind getConstructionKind() const {
1166     return (ConstructionKind)ConstructKind;
1167   }
setConstructionKind(ConstructionKind CK)1168   void setConstructionKind(ConstructionKind CK) {
1169     ConstructKind = CK;
1170   }
1171 
1172   typedef ExprIterator arg_iterator;
1173   typedef ConstExprIterator const_arg_iterator;
1174   typedef llvm::iterator_range<arg_iterator> arg_range;
1175   typedef llvm::iterator_range<const_arg_iterator> arg_const_range;
1176 
arguments()1177   arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
arguments()1178   arg_const_range arguments() const {
1179     return arg_const_range(arg_begin(), arg_end());
1180   }
1181 
arg_begin()1182   arg_iterator arg_begin() { return Args; }
arg_end()1183   arg_iterator arg_end() { return Args + NumArgs; }
arg_begin()1184   const_arg_iterator arg_begin() const { return Args; }
arg_end()1185   const_arg_iterator arg_end() const { return Args + NumArgs; }
1186 
getArgs()1187   Expr **getArgs() { return reinterpret_cast<Expr **>(Args); }
getArgs()1188   const Expr *const *getArgs() const {
1189     return const_cast<CXXConstructExpr *>(this)->getArgs();
1190   }
getNumArgs()1191   unsigned getNumArgs() const { return NumArgs; }
1192 
1193   /// \brief Return the specified argument.
getArg(unsigned Arg)1194   Expr *getArg(unsigned Arg) {
1195     assert(Arg < NumArgs && "Arg access out of range!");
1196     return cast<Expr>(Args[Arg]);
1197   }
getArg(unsigned Arg)1198   const Expr *getArg(unsigned Arg) const {
1199     assert(Arg < NumArgs && "Arg access out of range!");
1200     return cast<Expr>(Args[Arg]);
1201   }
1202 
1203   /// \brief Set the specified argument.
setArg(unsigned Arg,Expr * ArgExpr)1204   void setArg(unsigned Arg, Expr *ArgExpr) {
1205     assert(Arg < NumArgs && "Arg access out of range!");
1206     Args[Arg] = ArgExpr;
1207   }
1208 
1209   SourceLocation getLocStart() const LLVM_READONLY;
1210   SourceLocation getLocEnd() const LLVM_READONLY;
getParenOrBraceRange()1211   SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
setParenOrBraceRange(SourceRange Range)1212   void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
1213 
classof(const Stmt * T)1214   static bool classof(const Stmt *T) {
1215     return T->getStmtClass() == CXXConstructExprClass ||
1216       T->getStmtClass() == CXXTemporaryObjectExprClass;
1217   }
1218 
1219   // Iterators
children()1220   child_range children() {
1221     return child_range(&Args[0], &Args[0]+NumArgs);
1222   }
1223 
1224   friend class ASTStmtReader;
1225 };
1226 
1227 /// \brief Represents an explicit C++ type conversion that uses "functional"
1228 /// notation (C++ [expr.type.conv]).
1229 ///
1230 /// Example:
1231 /// \code
1232 ///   x = int(0.5);
1233 /// \endcode
1234 class CXXFunctionalCastExpr : public ExplicitCastExpr {
1235   SourceLocation LParenLoc;
1236   SourceLocation RParenLoc;
1237 
CXXFunctionalCastExpr(QualType ty,ExprValueKind VK,TypeSourceInfo * writtenTy,CastKind kind,Expr * castExpr,unsigned pathSize,SourceLocation lParenLoc,SourceLocation rParenLoc)1238   CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1239                         TypeSourceInfo *writtenTy,
1240                         CastKind kind, Expr *castExpr, unsigned pathSize,
1241                         SourceLocation lParenLoc, SourceLocation rParenLoc)
1242     : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1243                        castExpr, pathSize, writtenTy),
1244       LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
1245 
CXXFunctionalCastExpr(EmptyShell Shell,unsigned PathSize)1246   explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1247     : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1248 
1249 public:
1250   static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
1251                                        ExprValueKind VK,
1252                                        TypeSourceInfo *Written,
1253                                        CastKind Kind, Expr *Op,
1254                                        const CXXCastPath *Path,
1255                                        SourceLocation LPLoc,
1256                                        SourceLocation RPLoc);
1257   static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
1258                                             unsigned PathSize);
1259 
getLParenLoc()1260   SourceLocation getLParenLoc() const { return LParenLoc; }
setLParenLoc(SourceLocation L)1261   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
getRParenLoc()1262   SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)1263   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1264 
1265   SourceLocation getLocStart() const LLVM_READONLY;
1266   SourceLocation getLocEnd() const LLVM_READONLY;
1267 
classof(const Stmt * T)1268   static bool classof(const Stmt *T) {
1269     return T->getStmtClass() == CXXFunctionalCastExprClass;
1270   }
1271 };
1272 
1273 /// @brief Represents a C++ functional cast expression that builds a
1274 /// temporary object.
1275 ///
1276 /// This expression type represents a C++ "functional" cast
1277 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1278 /// constructor to build a temporary object. With N == 1 arguments the
1279 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1280 /// Example:
1281 /// \code
1282 /// struct X { X(int, float); }
1283 ///
1284 /// X create_X() {
1285 ///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1286 /// };
1287 /// \endcode
1288 class CXXTemporaryObjectExpr : public CXXConstructExpr {
1289   TypeSourceInfo *Type;
1290 
1291 public:
1292   CXXTemporaryObjectExpr(const ASTContext &C, CXXConstructorDecl *Cons,
1293                          TypeSourceInfo *Type,
1294                          ArrayRef<Expr *> Args,
1295                          SourceRange ParenOrBraceRange,
1296                          bool HadMultipleCandidates,
1297                          bool ListInitialization,
1298                          bool StdInitListInitialization,
1299                          bool ZeroInitialization);
CXXTemporaryObjectExpr(EmptyShell Empty)1300   explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1301     : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1302 
getTypeSourceInfo()1303   TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1304 
1305   SourceLocation getLocStart() const LLVM_READONLY;
1306   SourceLocation getLocEnd() const LLVM_READONLY;
1307 
classof(const Stmt * T)1308   static bool classof(const Stmt *T) {
1309     return T->getStmtClass() == CXXTemporaryObjectExprClass;
1310   }
1311 
1312   friend class ASTStmtReader;
1313 };
1314 
1315 /// \brief A C++ lambda expression, which produces a function object
1316 /// (of unspecified type) that can be invoked later.
1317 ///
1318 /// Example:
1319 /// \code
1320 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1321 ///   values.erase(std::remove_if(values.begin(), values.end(),
1322 ///                               [=](double value) { return value > cutoff; });
1323 /// }
1324 /// \endcode
1325 ///
1326 /// C++11 lambda expressions can capture local variables, either by copying
1327 /// the values of those local variables at the time the function
1328 /// object is constructed (not when it is called!) or by holding a
1329 /// reference to the local variable. These captures can occur either
1330 /// implicitly or can be written explicitly between the square
1331 /// brackets ([...]) that start the lambda expression.
1332 ///
1333 /// C++1y introduces a new form of "capture" called an init-capture that
1334 /// includes an initializing expression (rather than capturing a variable),
1335 /// and which can never occur implicitly.
1336 class LambdaExpr : public Expr {
1337   /// \brief The source range that covers the lambda introducer ([...]).
1338   SourceRange IntroducerRange;
1339 
1340   /// \brief The source location of this lambda's capture-default ('=' or '&').
1341   SourceLocation CaptureDefaultLoc;
1342 
1343   /// \brief The number of captures.
1344   unsigned NumCaptures : 16;
1345 
1346   /// \brief The default capture kind, which is a value of type
1347   /// LambdaCaptureDefault.
1348   unsigned CaptureDefault : 2;
1349 
1350   /// \brief Whether this lambda had an explicit parameter list vs. an
1351   /// implicit (and empty) parameter list.
1352   unsigned ExplicitParams : 1;
1353 
1354   /// \brief Whether this lambda had the result type explicitly specified.
1355   unsigned ExplicitResultType : 1;
1356 
1357   /// \brief Whether there are any array index variables stored at the end of
1358   /// this lambda expression.
1359   unsigned HasArrayIndexVars : 1;
1360 
1361   /// \brief The location of the closing brace ('}') that completes
1362   /// the lambda.
1363   ///
1364   /// The location of the brace is also available by looking up the
1365   /// function call operator in the lambda class. However, it is
1366   /// stored here to improve the performance of getSourceRange(), and
1367   /// to avoid having to deserialize the function call operator from a
1368   /// module file just to determine the source range.
1369   SourceLocation ClosingBrace;
1370 
1371   // Note: The capture initializers are stored directly after the lambda
1372   // expression, along with the index variables used to initialize by-copy
1373   // array captures.
1374 
1375   typedef LambdaCapture Capture;
1376 
1377   /// \brief Construct a lambda expression.
1378   LambdaExpr(QualType T, SourceRange IntroducerRange,
1379              LambdaCaptureDefault CaptureDefault,
1380              SourceLocation CaptureDefaultLoc,
1381              ArrayRef<Capture> Captures,
1382              bool ExplicitParams,
1383              bool ExplicitResultType,
1384              ArrayRef<Expr *> CaptureInits,
1385              ArrayRef<VarDecl *> ArrayIndexVars,
1386              ArrayRef<unsigned> ArrayIndexStarts,
1387              SourceLocation ClosingBrace,
1388              bool ContainsUnexpandedParameterPack);
1389 
1390   /// \brief Construct an empty lambda expression.
LambdaExpr(EmptyShell Empty,unsigned NumCaptures,bool HasArrayIndexVars)1391   LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
1392     : Expr(LambdaExprClass, Empty),
1393       NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
1394       ExplicitResultType(false), HasArrayIndexVars(true) {
1395     getStoredStmts()[NumCaptures] = nullptr;
1396   }
1397 
getStoredStmts()1398   Stmt **getStoredStmts() const {
1399     return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
1400   }
1401 
1402   /// \brief Retrieve the mapping from captures to the first array index
1403   /// variable.
getArrayIndexStarts()1404   unsigned *getArrayIndexStarts() const {
1405     return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
1406   }
1407 
1408   /// \brief Retrieve the complete set of array-index variables.
getArrayIndexVars()1409   VarDecl **getArrayIndexVars() const {
1410     unsigned ArrayIndexSize =
1411         llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1),
1412                                  llvm::alignOf<VarDecl*>());
1413     return reinterpret_cast<VarDecl **>(
1414         reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize);
1415   }
1416 
1417 public:
1418   /// \brief Construct a new lambda expression.
1419   static LambdaExpr *Create(const ASTContext &C,
1420                             CXXRecordDecl *Class,
1421                             SourceRange IntroducerRange,
1422                             LambdaCaptureDefault CaptureDefault,
1423                             SourceLocation CaptureDefaultLoc,
1424                             ArrayRef<Capture> Captures,
1425                             bool ExplicitParams,
1426                             bool ExplicitResultType,
1427                             ArrayRef<Expr *> CaptureInits,
1428                             ArrayRef<VarDecl *> ArrayIndexVars,
1429                             ArrayRef<unsigned> ArrayIndexStarts,
1430                             SourceLocation ClosingBrace,
1431                             bool ContainsUnexpandedParameterPack);
1432 
1433   /// \brief Construct a new lambda expression that will be deserialized from
1434   /// an external source.
1435   static LambdaExpr *CreateDeserialized(const ASTContext &C,
1436                                         unsigned NumCaptures,
1437                                         unsigned NumArrayIndexVars);
1438 
1439   /// \brief Determine the default capture kind for this lambda.
getCaptureDefault()1440   LambdaCaptureDefault getCaptureDefault() const {
1441     return static_cast<LambdaCaptureDefault>(CaptureDefault);
1442   }
1443 
1444   /// \brief Retrieve the location of this lambda's capture-default, if any.
getCaptureDefaultLoc()1445   SourceLocation getCaptureDefaultLoc() const {
1446     return CaptureDefaultLoc;
1447   }
1448 
1449   /// \brief An iterator that walks over the captures of the lambda,
1450   /// both implicit and explicit.
1451   typedef const Capture *capture_iterator;
1452 
1453   /// \brief An iterator over a range of lambda captures.
1454   typedef llvm::iterator_range<capture_iterator> capture_range;
1455 
1456   /// \brief Retrieve this lambda's captures.
1457   capture_range captures() const;
1458 
1459   /// \brief Retrieve an iterator pointing to the first lambda capture.
1460   capture_iterator capture_begin() const;
1461 
1462   /// \brief Retrieve an iterator pointing past the end of the
1463   /// sequence of lambda captures.
1464   capture_iterator capture_end() const;
1465 
1466   /// \brief Determine the number of captures in this lambda.
capture_size()1467   unsigned capture_size() const { return NumCaptures; }
1468 
1469   /// \brief Retrieve this lambda's explicit captures.
1470   capture_range explicit_captures() const;
1471 
1472   /// \brief Retrieve an iterator pointing to the first explicit
1473   /// lambda capture.
1474   capture_iterator explicit_capture_begin() const;
1475 
1476   /// \brief Retrieve an iterator pointing past the end of the sequence of
1477   /// explicit lambda captures.
1478   capture_iterator explicit_capture_end() const;
1479 
1480   /// \brief Retrieve this lambda's implicit captures.
1481   capture_range implicit_captures() const;
1482 
1483   /// \brief Retrieve an iterator pointing to the first implicit
1484   /// lambda capture.
1485   capture_iterator implicit_capture_begin() const;
1486 
1487   /// \brief Retrieve an iterator pointing past the end of the sequence of
1488   /// implicit lambda captures.
1489   capture_iterator implicit_capture_end() const;
1490 
1491   /// \brief Iterator that walks over the capture initialization
1492   /// arguments.
1493   typedef Expr **capture_init_iterator;
1494 
1495   /// \brief Retrieve the initialization expressions for this lambda's captures.
capture_inits()1496   llvm::iterator_range<capture_init_iterator> capture_inits() const {
1497     return llvm::iterator_range<capture_init_iterator>(capture_init_begin(),
1498                                                        capture_init_end());
1499   }
1500 
1501   /// \brief Retrieve the first initialization argument for this
1502   /// lambda expression (which initializes the first capture field).
capture_init_begin()1503   capture_init_iterator capture_init_begin() const {
1504     return reinterpret_cast<Expr **>(getStoredStmts());
1505   }
1506 
1507   /// \brief Retrieve the iterator pointing one past the last
1508   /// initialization argument for this lambda expression.
capture_init_end()1509   capture_init_iterator capture_init_end() const {
1510     return capture_init_begin() + NumCaptures;
1511   }
1512 
1513   /// \brief Retrieve the set of index variables used in the capture
1514   /// initializer of an array captured by copy.
1515   ///
1516   /// \param Iter The iterator that points at the capture initializer for
1517   /// which we are extracting the corresponding index variables.
1518   ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
1519 
1520   /// \brief Retrieve the source range covering the lambda introducer,
1521   /// which contains the explicit capture list surrounded by square
1522   /// brackets ([...]).
getIntroducerRange()1523   SourceRange getIntroducerRange() const { return IntroducerRange; }
1524 
1525   /// \brief Retrieve the class that corresponds to the lambda.
1526   ///
1527   /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
1528   /// captures in its fields and provides the various operations permitted
1529   /// on a lambda (copying, calling).
1530   CXXRecordDecl *getLambdaClass() const;
1531 
1532   /// \brief Retrieve the function call operator associated with this
1533   /// lambda expression.
1534   CXXMethodDecl *getCallOperator() const;
1535 
1536   /// \brief If this is a generic lambda expression, retrieve the template
1537   /// parameter list associated with it, or else return null.
1538   TemplateParameterList *getTemplateParameterList() const;
1539 
1540   /// \brief Whether this is a generic lambda.
isGenericLambda()1541   bool isGenericLambda() const { return getTemplateParameterList(); }
1542 
1543   /// \brief Retrieve the body of the lambda.
1544   CompoundStmt *getBody() const;
1545 
1546   /// \brief Determine whether the lambda is mutable, meaning that any
1547   /// captures values can be modified.
1548   bool isMutable() const;
1549 
1550   /// \brief Determine whether this lambda has an explicit parameter
1551   /// list vs. an implicit (empty) parameter list.
hasExplicitParameters()1552   bool hasExplicitParameters() const { return ExplicitParams; }
1553 
1554   /// \brief Whether this lambda had its result type explicitly specified.
hasExplicitResultType()1555   bool hasExplicitResultType() const { return ExplicitResultType; }
1556 
classof(const Stmt * T)1557   static bool classof(const Stmt *T) {
1558     return T->getStmtClass() == LambdaExprClass;
1559   }
1560 
getLocStart()1561   SourceLocation getLocStart() const LLVM_READONLY {
1562     return IntroducerRange.getBegin();
1563   }
getLocEnd()1564   SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
1565 
children()1566   child_range children() {
1567     return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1568   }
1569 
1570   friend class ASTStmtReader;
1571   friend class ASTStmtWriter;
1572 };
1573 
1574 /// An expression "T()" which creates a value-initialized rvalue of type
1575 /// T, which is a non-class type.  See (C++98 [5.2.3p2]).
1576 class CXXScalarValueInitExpr : public Expr {
1577   SourceLocation RParenLoc;
1578   TypeSourceInfo *TypeInfo;
1579 
1580   friend class ASTStmtReader;
1581 
1582 public:
1583   /// \brief Create an explicitly-written scalar-value initialization
1584   /// expression.
CXXScalarValueInitExpr(QualType Type,TypeSourceInfo * TypeInfo,SourceLocation rParenLoc)1585   CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
1586                          SourceLocation rParenLoc)
1587       : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1588              false, false, Type->isInstantiationDependentType(),
1589              Type->containsUnexpandedParameterPack()),
1590         RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1591 
CXXScalarValueInitExpr(EmptyShell Shell)1592   explicit CXXScalarValueInitExpr(EmptyShell Shell)
1593     : Expr(CXXScalarValueInitExprClass, Shell) { }
1594 
getTypeSourceInfo()1595   TypeSourceInfo *getTypeSourceInfo() const {
1596     return TypeInfo;
1597   }
1598 
getRParenLoc()1599   SourceLocation getRParenLoc() const { return RParenLoc; }
1600 
1601   SourceLocation getLocStart() const LLVM_READONLY;
getLocEnd()1602   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1603 
classof(const Stmt * T)1604   static bool classof(const Stmt *T) {
1605     return T->getStmtClass() == CXXScalarValueInitExprClass;
1606   }
1607 
1608   // Iterators
children()1609   child_range children() { return child_range(); }
1610 };
1611 
1612 /// \brief Represents a new-expression for memory allocation and constructor
1613 /// calls, e.g: "new CXXNewExpr(foo)".
1614 class CXXNewExpr : public Expr {
1615   /// Contains an optional array size expression, an optional initialization
1616   /// expression, and any number of optional placement arguments, in that order.
1617   Stmt **SubExprs;
1618   /// \brief Points to the allocation function used.
1619   FunctionDecl *OperatorNew;
1620   /// \brief Points to the deallocation function used in case of error. May be
1621   /// null.
1622   FunctionDecl *OperatorDelete;
1623 
1624   /// \brief The allocated type-source information, as written in the source.
1625   TypeSourceInfo *AllocatedTypeInfo;
1626 
1627   /// \brief If the allocated type was expressed as a parenthesized type-id,
1628   /// the source range covering the parenthesized type-id.
1629   SourceRange TypeIdParens;
1630 
1631   /// \brief Range of the entire new expression.
1632   SourceRange Range;
1633 
1634   /// \brief Source-range of a paren-delimited initializer.
1635   SourceRange DirectInitRange;
1636 
1637   /// Was the usage ::new, i.e. is the global new to be used?
1638   bool GlobalNew : 1;
1639   /// Do we allocate an array? If so, the first SubExpr is the size expression.
1640   bool Array : 1;
1641   /// If this is an array allocation, does the usual deallocation
1642   /// function for the allocated type want to know the allocated size?
1643   bool UsualArrayDeleteWantsSize : 1;
1644   /// The number of placement new arguments.
1645   unsigned NumPlacementArgs : 13;
1646   /// What kind of initializer do we have? Could be none, parens, or braces.
1647   /// In storage, we distinguish between "none, and no initializer expr", and
1648   /// "none, but an implicit initializer expr".
1649   unsigned StoredInitializationStyle : 2;
1650 
1651   friend class ASTStmtReader;
1652   friend class ASTStmtWriter;
1653 public:
1654   enum InitializationStyle {
1655     NoInit,   ///< New-expression has no initializer as written.
1656     CallInit, ///< New-expression has a C++98 paren-delimited initializer.
1657     ListInit  ///< New-expression has a C++11 list-initializer.
1658   };
1659 
1660   CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1661              FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1662              ArrayRef<Expr*> placementArgs,
1663              SourceRange typeIdParens, Expr *arraySize,
1664              InitializationStyle initializationStyle, Expr *initializer,
1665              QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1666              SourceRange Range, SourceRange directInitRange);
CXXNewExpr(EmptyShell Shell)1667   explicit CXXNewExpr(EmptyShell Shell)
1668     : Expr(CXXNewExprClass, Shell), SubExprs(nullptr) { }
1669 
1670   void AllocateArgsArray(const ASTContext &C, bool isArray,
1671                          unsigned numPlaceArgs, bool hasInitializer);
1672 
getAllocatedType()1673   QualType getAllocatedType() const {
1674     assert(getType()->isPointerType());
1675     return getType()->getAs<PointerType>()->getPointeeType();
1676   }
1677 
getAllocatedTypeSourceInfo()1678   TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1679     return AllocatedTypeInfo;
1680   }
1681 
1682   /// \brief True if the allocation result needs to be null-checked.
1683   ///
1684   /// C++11 [expr.new]p13:
1685   ///   If the allocation function returns null, initialization shall
1686   ///   not be done, the deallocation function shall not be called,
1687   ///   and the value of the new-expression shall be null.
1688   ///
1689   /// An allocation function is not allowed to return null unless it
1690   /// has a non-throwing exception-specification.  The '03 rule is
1691   /// identical except that the definition of a non-throwing
1692   /// exception specification is just "is it throw()?".
1693   bool shouldNullCheckAllocation(const ASTContext &Ctx) const;
1694 
getOperatorNew()1695   FunctionDecl *getOperatorNew() const { return OperatorNew; }
setOperatorNew(FunctionDecl * D)1696   void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
getOperatorDelete()1697   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
setOperatorDelete(FunctionDecl * D)1698   void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1699 
isArray()1700   bool isArray() const { return Array; }
getArraySize()1701   Expr *getArraySize() {
1702     return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1703   }
getArraySize()1704   const Expr *getArraySize() const {
1705     return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1706   }
1707 
getNumPlacementArgs()1708   unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
getPlacementArgs()1709   Expr **getPlacementArgs() {
1710     return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1711   }
1712 
getPlacementArg(unsigned i)1713   Expr *getPlacementArg(unsigned i) {
1714     assert(i < NumPlacementArgs && "Index out of range");
1715     return getPlacementArgs()[i];
1716   }
getPlacementArg(unsigned i)1717   const Expr *getPlacementArg(unsigned i) const {
1718     assert(i < NumPlacementArgs && "Index out of range");
1719     return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
1720   }
1721 
isParenTypeId()1722   bool isParenTypeId() const { return TypeIdParens.isValid(); }
getTypeIdParens()1723   SourceRange getTypeIdParens() const { return TypeIdParens; }
1724 
isGlobalNew()1725   bool isGlobalNew() const { return GlobalNew; }
1726 
1727   /// \brief Whether this new-expression has any initializer at all.
hasInitializer()1728   bool hasInitializer() const { return StoredInitializationStyle > 0; }
1729 
1730   /// \brief The kind of initializer this new-expression has.
getInitializationStyle()1731   InitializationStyle getInitializationStyle() const {
1732     if (StoredInitializationStyle == 0)
1733       return NoInit;
1734     return static_cast<InitializationStyle>(StoredInitializationStyle-1);
1735   }
1736 
1737   /// \brief The initializer of this new-expression.
getInitializer()1738   Expr *getInitializer() {
1739     return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1740   }
getInitializer()1741   const Expr *getInitializer() const {
1742     return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1743   }
1744 
1745   /// \brief Returns the CXXConstructExpr from this new-expression, or null.
getConstructExpr()1746   const CXXConstructExpr* getConstructExpr() const {
1747     return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1748   }
1749 
1750   /// Answers whether the usual array deallocation function for the
1751   /// allocated type expects the size of the allocation as a
1752   /// parameter.
doesUsualArrayDeleteWantSize()1753   bool doesUsualArrayDeleteWantSize() const {
1754     return UsualArrayDeleteWantsSize;
1755   }
1756 
1757   typedef ExprIterator arg_iterator;
1758   typedef ConstExprIterator const_arg_iterator;
1759 
placement_arg_begin()1760   arg_iterator placement_arg_begin() {
1761     return SubExprs + Array + hasInitializer();
1762   }
placement_arg_end()1763   arg_iterator placement_arg_end() {
1764     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1765   }
placement_arg_begin()1766   const_arg_iterator placement_arg_begin() const {
1767     return SubExprs + Array + hasInitializer();
1768   }
placement_arg_end()1769   const_arg_iterator placement_arg_end() const {
1770     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1771   }
1772 
1773   typedef Stmt **raw_arg_iterator;
raw_arg_begin()1774   raw_arg_iterator raw_arg_begin() { return SubExprs; }
raw_arg_end()1775   raw_arg_iterator raw_arg_end() {
1776     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1777   }
raw_arg_begin()1778   const_arg_iterator raw_arg_begin() const { return SubExprs; }
raw_arg_end()1779   const_arg_iterator raw_arg_end() const {
1780     return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1781   }
1782 
getStartLoc()1783   SourceLocation getStartLoc() const { return Range.getBegin(); }
getEndLoc()1784   SourceLocation getEndLoc() const { return Range.getEnd(); }
1785 
getDirectInitRange()1786   SourceRange getDirectInitRange() const { return DirectInitRange; }
1787 
getSourceRange()1788   SourceRange getSourceRange() const LLVM_READONLY {
1789     return Range;
1790   }
getLocStart()1791   SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
getLocEnd()1792   SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1793 
classof(const Stmt * T)1794   static bool classof(const Stmt *T) {
1795     return T->getStmtClass() == CXXNewExprClass;
1796   }
1797 
1798   // Iterators
children()1799   child_range children() {
1800     return child_range(raw_arg_begin(), raw_arg_end());
1801   }
1802 };
1803 
1804 /// \brief Represents a \c delete expression for memory deallocation and
1805 /// destructor calls, e.g. "delete[] pArray".
1806 class CXXDeleteExpr : public Expr {
1807   /// Points to the operator delete overload that is used. Could be a member.
1808   FunctionDecl *OperatorDelete;
1809   /// The pointer expression to be deleted.
1810   Stmt *Argument;
1811   /// Location of the expression.
1812   SourceLocation Loc;
1813   /// Is this a forced global delete, i.e. "::delete"?
1814   bool GlobalDelete : 1;
1815   /// Is this the array form of delete, i.e. "delete[]"?
1816   bool ArrayForm : 1;
1817   /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1818   /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1819   /// will be true).
1820   bool ArrayFormAsWritten : 1;
1821   /// Does the usual deallocation function for the element type require
1822   /// a size_t argument?
1823   bool UsualArrayDeleteWantsSize : 1;
1824 public:
CXXDeleteExpr(QualType ty,bool globalDelete,bool arrayForm,bool arrayFormAsWritten,bool usualArrayDeleteWantsSize,FunctionDecl * operatorDelete,Expr * arg,SourceLocation loc)1825   CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1826                 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1827                 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1828     : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1829            arg->isInstantiationDependent(),
1830            arg->containsUnexpandedParameterPack()),
1831       OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
1832       GlobalDelete(globalDelete),
1833       ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1834       UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
CXXDeleteExpr(EmptyShell Shell)1835   explicit CXXDeleteExpr(EmptyShell Shell)
1836     : Expr(CXXDeleteExprClass, Shell), OperatorDelete(nullptr),
1837       Argument(nullptr) {}
1838 
isGlobalDelete()1839   bool isGlobalDelete() const { return GlobalDelete; }
isArrayForm()1840   bool isArrayForm() const { return ArrayForm; }
isArrayFormAsWritten()1841   bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1842 
1843   /// Answers whether the usual array deallocation function for the
1844   /// allocated type expects the size of the allocation as a
1845   /// parameter.  This can be true even if the actual deallocation
1846   /// function that we're using doesn't want a size.
doesUsualArrayDeleteWantSize()1847   bool doesUsualArrayDeleteWantSize() const {
1848     return UsualArrayDeleteWantsSize;
1849   }
1850 
getOperatorDelete()1851   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1852 
getArgument()1853   Expr *getArgument() { return cast<Expr>(Argument); }
getArgument()1854   const Expr *getArgument() const { return cast<Expr>(Argument); }
1855 
1856   /// \brief Retrieve the type being destroyed.
1857   ///
1858   /// If the type being destroyed is a dependent type which may or may not
1859   /// be a pointer, return an invalid type.
1860   QualType getDestroyedType() const;
1861 
getLocStart()1862   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
getLocEnd()1863   SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
1864 
classof(const Stmt * T)1865   static bool classof(const Stmt *T) {
1866     return T->getStmtClass() == CXXDeleteExprClass;
1867   }
1868 
1869   // Iterators
children()1870   child_range children() { return child_range(&Argument, &Argument+1); }
1871 
1872   friend class ASTStmtReader;
1873 };
1874 
1875 /// \brief Stores the type being destroyed by a pseudo-destructor expression.
1876 class PseudoDestructorTypeStorage {
1877   /// \brief Either the type source information or the name of the type, if
1878   /// it couldn't be resolved due to type-dependence.
1879   llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1880 
1881   /// \brief The starting source location of the pseudo-destructor type.
1882   SourceLocation Location;
1883 
1884 public:
PseudoDestructorTypeStorage()1885   PseudoDestructorTypeStorage() { }
1886 
PseudoDestructorTypeStorage(IdentifierInfo * II,SourceLocation Loc)1887   PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1888     : Type(II), Location(Loc) { }
1889 
1890   PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1891 
getTypeSourceInfo()1892   TypeSourceInfo *getTypeSourceInfo() const {
1893     return Type.dyn_cast<TypeSourceInfo *>();
1894   }
1895 
getIdentifier()1896   IdentifierInfo *getIdentifier() const {
1897     return Type.dyn_cast<IdentifierInfo *>();
1898   }
1899 
getLocation()1900   SourceLocation getLocation() const { return Location; }
1901 };
1902 
1903 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1904 ///
1905 /// A pseudo-destructor is an expression that looks like a member access to a
1906 /// destructor of a scalar type, except that scalar types don't have
1907 /// destructors. For example:
1908 ///
1909 /// \code
1910 /// typedef int T;
1911 /// void f(int *p) {
1912 ///   p->T::~T();
1913 /// }
1914 /// \endcode
1915 ///
1916 /// Pseudo-destructors typically occur when instantiating templates such as:
1917 ///
1918 /// \code
1919 /// template<typename T>
1920 /// void destroy(T* ptr) {
1921 ///   ptr->T::~T();
1922 /// }
1923 /// \endcode
1924 ///
1925 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1926 /// beyond evaluating the base expression.
1927 class CXXPseudoDestructorExpr : public Expr {
1928   /// \brief The base expression (that is being destroyed).
1929   Stmt *Base;
1930 
1931   /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1932   /// period ('.').
1933   bool IsArrow : 1;
1934 
1935   /// \brief The location of the '.' or '->' operator.
1936   SourceLocation OperatorLoc;
1937 
1938   /// \brief The nested-name-specifier that follows the operator, if present.
1939   NestedNameSpecifierLoc QualifierLoc;
1940 
1941   /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1942   /// expression.
1943   TypeSourceInfo *ScopeType;
1944 
1945   /// \brief The location of the '::' in a qualified pseudo-destructor
1946   /// expression.
1947   SourceLocation ColonColonLoc;
1948 
1949   /// \brief The location of the '~'.
1950   SourceLocation TildeLoc;
1951 
1952   /// \brief The type being destroyed, or its name if we were unable to
1953   /// resolve the name.
1954   PseudoDestructorTypeStorage DestroyedType;
1955 
1956   friend class ASTStmtReader;
1957 
1958 public:
1959   CXXPseudoDestructorExpr(const ASTContext &Context,
1960                           Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1961                           NestedNameSpecifierLoc QualifierLoc,
1962                           TypeSourceInfo *ScopeType,
1963                           SourceLocation ColonColonLoc,
1964                           SourceLocation TildeLoc,
1965                           PseudoDestructorTypeStorage DestroyedType);
1966 
CXXPseudoDestructorExpr(EmptyShell Shell)1967   explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1968     : Expr(CXXPseudoDestructorExprClass, Shell),
1969       Base(nullptr), IsArrow(false), QualifierLoc(), ScopeType(nullptr) { }
1970 
getBase()1971   Expr *getBase() const { return cast<Expr>(Base); }
1972 
1973   /// \brief Determines whether this member expression actually had
1974   /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1975   /// x->Base::foo.
hasQualifier()1976   bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
1977 
1978   /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1979   /// with source-location information.
getQualifierLoc()1980   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1981 
1982   /// \brief If the member name was qualified, retrieves the
1983   /// nested-name-specifier that precedes the member name. Otherwise, returns
1984   /// null.
getQualifier()1985   NestedNameSpecifier *getQualifier() const {
1986     return QualifierLoc.getNestedNameSpecifier();
1987   }
1988 
1989   /// \brief Determine whether this pseudo-destructor expression was written
1990   /// using an '->' (otherwise, it used a '.').
isArrow()1991   bool isArrow() const { return IsArrow; }
1992 
1993   /// \brief Retrieve the location of the '.' or '->' operator.
getOperatorLoc()1994   SourceLocation getOperatorLoc() const { return OperatorLoc; }
1995 
1996   /// \brief Retrieve the scope type in a qualified pseudo-destructor
1997   /// expression.
1998   ///
1999   /// Pseudo-destructor expressions can have extra qualification within them
2000   /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
2001   /// Here, if the object type of the expression is (or may be) a scalar type,
2002   /// \p T may also be a scalar type and, therefore, cannot be part of a
2003   /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
2004   /// destructor expression.
getScopeTypeInfo()2005   TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
2006 
2007   /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
2008   /// expression.
getColonColonLoc()2009   SourceLocation getColonColonLoc() const { return ColonColonLoc; }
2010 
2011   /// \brief Retrieve the location of the '~'.
getTildeLoc()2012   SourceLocation getTildeLoc() const { return TildeLoc; }
2013 
2014   /// \brief Retrieve the source location information for the type
2015   /// being destroyed.
2016   ///
2017   /// This type-source information is available for non-dependent
2018   /// pseudo-destructor expressions and some dependent pseudo-destructor
2019   /// expressions. Returns null if we only have the identifier for a
2020   /// dependent pseudo-destructor expression.
getDestroyedTypeInfo()2021   TypeSourceInfo *getDestroyedTypeInfo() const {
2022     return DestroyedType.getTypeSourceInfo();
2023   }
2024 
2025   /// \brief In a dependent pseudo-destructor expression for which we do not
2026   /// have full type information on the destroyed type, provides the name
2027   /// of the destroyed type.
getDestroyedTypeIdentifier()2028   IdentifierInfo *getDestroyedTypeIdentifier() const {
2029     return DestroyedType.getIdentifier();
2030   }
2031 
2032   /// \brief Retrieve the type being destroyed.
2033   QualType getDestroyedType() const;
2034 
2035   /// \brief Retrieve the starting location of the type being destroyed.
getDestroyedTypeLoc()2036   SourceLocation getDestroyedTypeLoc() const {
2037     return DestroyedType.getLocation();
2038   }
2039 
2040   /// \brief Set the name of destroyed type for a dependent pseudo-destructor
2041   /// expression.
setDestroyedType(IdentifierInfo * II,SourceLocation Loc)2042   void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2043     DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2044   }
2045 
2046   /// \brief Set the destroyed type.
setDestroyedType(TypeSourceInfo * Info)2047   void setDestroyedType(TypeSourceInfo *Info) {
2048     DestroyedType = PseudoDestructorTypeStorage(Info);
2049   }
2050 
getLocStart()2051   SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
2052   SourceLocation getLocEnd() const LLVM_READONLY;
2053 
classof(const Stmt * T)2054   static bool classof(const Stmt *T) {
2055     return T->getStmtClass() == CXXPseudoDestructorExprClass;
2056   }
2057 
2058   // Iterators
children()2059   child_range children() { return child_range(&Base, &Base + 1); }
2060 };
2061 
2062 /// \brief A type trait used in the implementation of various C++11 and
2063 /// Library TR1 trait templates.
2064 ///
2065 /// \code
2066 ///   __is_pod(int) == true
2067 ///   __is_enum(std::string) == false
2068 ///   __is_trivially_constructible(vector<int>, int*, int*)
2069 /// \endcode
2070 class TypeTraitExpr : public Expr {
2071   /// \brief The location of the type trait keyword.
2072   SourceLocation Loc;
2073 
2074   /// \brief  The location of the closing parenthesis.
2075   SourceLocation RParenLoc;
2076 
2077   // Note: The TypeSourceInfos for the arguments are allocated after the
2078   // TypeTraitExpr.
2079 
2080   TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2081                 ArrayRef<TypeSourceInfo *> Args,
2082                 SourceLocation RParenLoc,
2083                 bool Value);
2084 
TypeTraitExpr(EmptyShell Empty)2085   TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
2086 
2087   /// \brief Retrieve the argument types.
getTypeSourceInfos()2088   TypeSourceInfo **getTypeSourceInfos() {
2089     return reinterpret_cast<TypeSourceInfo **>(this+1);
2090   }
2091 
2092   /// \brief Retrieve the argument types.
getTypeSourceInfos()2093   TypeSourceInfo * const *getTypeSourceInfos() const {
2094     return reinterpret_cast<TypeSourceInfo * const*>(this+1);
2095   }
2096 
2097 public:
2098   /// \brief Create a new type trait expression.
2099   static TypeTraitExpr *Create(const ASTContext &C, QualType T,
2100                                SourceLocation Loc, TypeTrait Kind,
2101                                ArrayRef<TypeSourceInfo *> Args,
2102                                SourceLocation RParenLoc,
2103                                bool Value);
2104 
2105   static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
2106                                            unsigned NumArgs);
2107 
2108   /// \brief Determine which type trait this expression uses.
getTrait()2109   TypeTrait getTrait() const {
2110     return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2111   }
2112 
getValue()2113   bool getValue() const {
2114     assert(!isValueDependent());
2115     return TypeTraitExprBits.Value;
2116   }
2117 
2118   /// \brief Determine the number of arguments to this type trait.
getNumArgs()2119   unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2120 
2121   /// \brief Retrieve the Ith argument.
getArg(unsigned I)2122   TypeSourceInfo *getArg(unsigned I) const {
2123     assert(I < getNumArgs() && "Argument out-of-range");
2124     return getArgs()[I];
2125   }
2126 
2127   /// \brief Retrieve the argument types.
getArgs()2128   ArrayRef<TypeSourceInfo *> getArgs() const {
2129     return llvm::makeArrayRef(getTypeSourceInfos(), getNumArgs());
2130   }
2131 
2132   typedef TypeSourceInfo **arg_iterator;
arg_begin()2133   arg_iterator arg_begin() {
2134     return getTypeSourceInfos();
2135   }
arg_end()2136   arg_iterator arg_end() {
2137     return getTypeSourceInfos() + getNumArgs();
2138   }
2139 
2140   typedef TypeSourceInfo const * const *arg_const_iterator;
arg_begin()2141   arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
arg_end()2142   arg_const_iterator arg_end() const {
2143     return getTypeSourceInfos() + getNumArgs();
2144   }
2145 
getLocStart()2146   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
getLocEnd()2147   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
2148 
classof(const Stmt * T)2149   static bool classof(const Stmt *T) {
2150     return T->getStmtClass() == TypeTraitExprClass;
2151   }
2152 
2153   // Iterators
children()2154   child_range children() { return child_range(); }
2155 
2156   friend class ASTStmtReader;
2157   friend class ASTStmtWriter;
2158 
2159 };
2160 
2161 /// \brief An Embarcadero array type trait, as used in the implementation of
2162 /// __array_rank and __array_extent.
2163 ///
2164 /// Example:
2165 /// \code
2166 ///   __array_rank(int[10][20]) == 2
2167 ///   __array_extent(int, 1)    == 20
2168 /// \endcode
2169 class ArrayTypeTraitExpr : public Expr {
2170   virtual void anchor();
2171 
2172   /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2173   unsigned ATT : 2;
2174 
2175   /// \brief The value of the type trait. Unspecified if dependent.
2176   uint64_t Value;
2177 
2178   /// \brief The array dimension being queried, or -1 if not used.
2179   Expr *Dimension;
2180 
2181   /// \brief The location of the type trait keyword.
2182   SourceLocation Loc;
2183 
2184   /// \brief The location of the closing paren.
2185   SourceLocation RParen;
2186 
2187   /// \brief The type being queried.
2188   TypeSourceInfo *QueriedType;
2189 
2190 public:
ArrayTypeTraitExpr(SourceLocation loc,ArrayTypeTrait att,TypeSourceInfo * queried,uint64_t value,Expr * dimension,SourceLocation rparen,QualType ty)2191   ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2192                      TypeSourceInfo *queried, uint64_t value,
2193                      Expr *dimension, SourceLocation rparen, QualType ty)
2194     : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2195            false, queried->getType()->isDependentType(),
2196            (queried->getType()->isInstantiationDependentType() ||
2197             (dimension && dimension->isInstantiationDependent())),
2198            queried->getType()->containsUnexpandedParameterPack()),
2199       ATT(att), Value(value), Dimension(dimension),
2200       Loc(loc), RParen(rparen), QueriedType(queried) { }
2201 
2202 
ArrayTypeTraitExpr(EmptyShell Empty)2203   explicit ArrayTypeTraitExpr(EmptyShell Empty)
2204     : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
2205       QueriedType() { }
2206 
~ArrayTypeTraitExpr()2207   virtual ~ArrayTypeTraitExpr() { }
2208 
getLocStart()2209   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
getLocEnd()2210   SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2211 
getTrait()2212   ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2213 
getQueriedType()2214   QualType getQueriedType() const { return QueriedType->getType(); }
2215 
getQueriedTypeSourceInfo()2216   TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2217 
getValue()2218   uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2219 
getDimensionExpression()2220   Expr *getDimensionExpression() const { return Dimension; }
2221 
classof(const Stmt * T)2222   static bool classof(const Stmt *T) {
2223     return T->getStmtClass() == ArrayTypeTraitExprClass;
2224   }
2225 
2226   // Iterators
children()2227   child_range children() { return child_range(); }
2228 
2229   friend class ASTStmtReader;
2230 };
2231 
2232 /// \brief An expression trait intrinsic.
2233 ///
2234 /// Example:
2235 /// \code
2236 ///   __is_lvalue_expr(std::cout) == true
2237 ///   __is_lvalue_expr(1) == false
2238 /// \endcode
2239 class ExpressionTraitExpr : public Expr {
2240   /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned.
2241   unsigned ET : 31;
2242   /// \brief The value of the type trait. Unspecified if dependent.
2243   bool Value : 1;
2244 
2245   /// \brief The location of the type trait keyword.
2246   SourceLocation Loc;
2247 
2248   /// \brief The location of the closing paren.
2249   SourceLocation RParen;
2250 
2251   /// \brief The expression being queried.
2252   Expr* QueriedExpression;
2253 public:
ExpressionTraitExpr(SourceLocation loc,ExpressionTrait et,Expr * queried,bool value,SourceLocation rparen,QualType resultType)2254   ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2255                      Expr *queried, bool value,
2256                      SourceLocation rparen, QualType resultType)
2257     : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2258            false, // Not type-dependent
2259            // Value-dependent if the argument is type-dependent.
2260            queried->isTypeDependent(),
2261            queried->isInstantiationDependent(),
2262            queried->containsUnexpandedParameterPack()),
2263       ET(et), Value(value), Loc(loc), RParen(rparen),
2264       QueriedExpression(queried) { }
2265 
ExpressionTraitExpr(EmptyShell Empty)2266   explicit ExpressionTraitExpr(EmptyShell Empty)
2267     : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2268       QueriedExpression() { }
2269 
getLocStart()2270   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
getLocEnd()2271   SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2272 
getTrait()2273   ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2274 
getQueriedExpression()2275   Expr *getQueriedExpression() const { return QueriedExpression; }
2276 
getValue()2277   bool getValue() const { return Value; }
2278 
classof(const Stmt * T)2279   static bool classof(const Stmt *T) {
2280     return T->getStmtClass() == ExpressionTraitExprClass;
2281   }
2282 
2283   // Iterators
children()2284   child_range children() { return child_range(); }
2285 
2286   friend class ASTStmtReader;
2287 };
2288 
2289 
2290 /// \brief A reference to an overloaded function set, either an
2291 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2292 class OverloadExpr : public Expr {
2293   /// \brief The common name of these declarations.
2294   DeclarationNameInfo NameInfo;
2295 
2296   /// \brief The nested-name-specifier that qualifies the name, if any.
2297   NestedNameSpecifierLoc QualifierLoc;
2298 
2299   /// The results.  These are undesugared, which is to say, they may
2300   /// include UsingShadowDecls.  Access is relative to the naming
2301   /// class.
2302   // FIXME: Allocate this data after the OverloadExpr subclass.
2303   DeclAccessPair *Results;
2304   unsigned NumResults;
2305 
2306 protected:
2307   /// \brief Whether the name includes info for explicit template
2308   /// keyword and arguments.
2309   bool HasTemplateKWAndArgsInfo;
2310 
2311   /// \brief Return the optional template keyword and arguments info.
2312   ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2313 
2314   /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2315   const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2316     return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2317   }
2318 
2319   OverloadExpr(StmtClass K, const ASTContext &C,
2320                NestedNameSpecifierLoc QualifierLoc,
2321                SourceLocation TemplateKWLoc,
2322                const DeclarationNameInfo &NameInfo,
2323                const TemplateArgumentListInfo *TemplateArgs,
2324                UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2325                bool KnownDependent,
2326                bool KnownInstantiationDependent,
2327                bool KnownContainsUnexpandedParameterPack);
2328 
OverloadExpr(StmtClass K,EmptyShell Empty)2329   OverloadExpr(StmtClass K, EmptyShell Empty)
2330     : Expr(K, Empty), QualifierLoc(), Results(nullptr), NumResults(0),
2331       HasTemplateKWAndArgsInfo(false) { }
2332 
2333   void initializeResults(const ASTContext &C,
2334                          UnresolvedSetIterator Begin,
2335                          UnresolvedSetIterator End);
2336 
2337 public:
2338   struct FindResult {
2339     OverloadExpr *Expression;
2340     bool IsAddressOfOperand;
2341     bool HasFormOfMemberPointer;
2342   };
2343 
2344   /// \brief Finds the overloaded expression in the given expression \p E of
2345   /// OverloadTy.
2346   ///
2347   /// \return the expression (which must be there) and true if it has
2348   /// the particular form of a member pointer expression
find(Expr * E)2349   static FindResult find(Expr *E) {
2350     assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2351 
2352     FindResult Result;
2353 
2354     E = E->IgnoreParens();
2355     if (isa<UnaryOperator>(E)) {
2356       assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2357       E = cast<UnaryOperator>(E)->getSubExpr();
2358       OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2359 
2360       Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2361       Result.IsAddressOfOperand = true;
2362       Result.Expression = Ovl;
2363     } else {
2364       Result.HasFormOfMemberPointer = false;
2365       Result.IsAddressOfOperand = false;
2366       Result.Expression = cast<OverloadExpr>(E);
2367     }
2368 
2369     return Result;
2370   }
2371 
2372   /// \brief Gets the naming class of this lookup, if any.
2373   CXXRecordDecl *getNamingClass() const;
2374 
2375   typedef UnresolvedSetImpl::iterator decls_iterator;
decls_begin()2376   decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
decls_end()2377   decls_iterator decls_end() const {
2378     return UnresolvedSetIterator(Results + NumResults);
2379   }
decls()2380   llvm::iterator_range<decls_iterator> decls() const {
2381     return llvm::iterator_range<decls_iterator>(decls_begin(), decls_end());
2382   }
2383 
2384   /// \brief Gets the number of declarations in the unresolved set.
getNumDecls()2385   unsigned getNumDecls() const { return NumResults; }
2386 
2387   /// \brief Gets the full name info.
getNameInfo()2388   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2389 
2390   /// \brief Gets the name looked up.
getName()2391   DeclarationName getName() const { return NameInfo.getName(); }
2392 
2393   /// \brief Gets the location of the name.
getNameLoc()2394   SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2395 
2396   /// \brief Fetches the nested-name qualifier, if one was given.
getQualifier()2397   NestedNameSpecifier *getQualifier() const {
2398     return QualifierLoc.getNestedNameSpecifier();
2399   }
2400 
2401   /// \brief Fetches the nested-name qualifier with source-location
2402   /// information, if one was given.
getQualifierLoc()2403   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2404 
2405   /// \brief Retrieve the location of the template keyword preceding
2406   /// this name, if any.
getTemplateKeywordLoc()2407   SourceLocation getTemplateKeywordLoc() const {
2408     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2409     return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2410   }
2411 
2412   /// \brief Retrieve the location of the left angle bracket starting the
2413   /// explicit template argument list following the name, if any.
getLAngleLoc()2414   SourceLocation getLAngleLoc() const {
2415     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2416     return getTemplateKWAndArgsInfo()->LAngleLoc;
2417   }
2418 
2419   /// \brief Retrieve the location of the right angle bracket ending the
2420   /// explicit template argument list following the name, if any.
getRAngleLoc()2421   SourceLocation getRAngleLoc() const {
2422     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2423     return getTemplateKWAndArgsInfo()->RAngleLoc;
2424   }
2425 
2426   /// \brief Determines whether the name was preceded by the template keyword.
hasTemplateKeyword()2427   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2428 
2429   /// \brief Determines whether this expression had explicit template arguments.
hasExplicitTemplateArgs()2430   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2431 
2432   // Note that, inconsistently with the explicit-template-argument AST
2433   // nodes, users are *forbidden* from calling these methods on objects
2434   // without explicit template arguments.
2435 
getExplicitTemplateArgs()2436   ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2437     assert(hasExplicitTemplateArgs());
2438     return *getTemplateKWAndArgsInfo();
2439   }
2440 
getExplicitTemplateArgs()2441   const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2442     return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
2443   }
2444 
getTemplateArgs()2445   TemplateArgumentLoc const *getTemplateArgs() const {
2446     return getExplicitTemplateArgs().getTemplateArgs();
2447   }
2448 
getNumTemplateArgs()2449   unsigned getNumTemplateArgs() const {
2450     return getExplicitTemplateArgs().NumTemplateArgs;
2451   }
2452 
2453   /// \brief Copies the template arguments into the given structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)2454   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2455     getExplicitTemplateArgs().copyInto(List);
2456   }
2457 
2458   /// \brief Retrieves the optional explicit template arguments.
2459   ///
2460   /// This points to the same data as getExplicitTemplateArgs(), but
2461   /// returns null if there are no explicit template arguments.
getOptionalExplicitTemplateArgs()2462   const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2463     if (!hasExplicitTemplateArgs()) return nullptr;
2464     return &getExplicitTemplateArgs();
2465   }
2466 
classof(const Stmt * T)2467   static bool classof(const Stmt *T) {
2468     return T->getStmtClass() == UnresolvedLookupExprClass ||
2469            T->getStmtClass() == UnresolvedMemberExprClass;
2470   }
2471 
2472   friend class ASTStmtReader;
2473   friend class ASTStmtWriter;
2474 };
2475 
2476 /// \brief A reference to a name which we were able to look up during
2477 /// parsing but could not resolve to a specific declaration.
2478 ///
2479 /// This arises in several ways:
2480 ///   * we might be waiting for argument-dependent lookup;
2481 ///   * the name might resolve to an overloaded function;
2482 /// and eventually:
2483 ///   * the lookup might have included a function template.
2484 ///
2485 /// These never include UnresolvedUsingValueDecls, which are always class
2486 /// members and therefore appear only in UnresolvedMemberLookupExprs.
2487 class UnresolvedLookupExpr : public OverloadExpr {
2488   /// True if these lookup results should be extended by
2489   /// argument-dependent lookup if this is the operand of a function
2490   /// call.
2491   bool RequiresADL;
2492 
2493   /// True if these lookup results are overloaded.  This is pretty
2494   /// trivially rederivable if we urgently need to kill this field.
2495   bool Overloaded;
2496 
2497   /// The naming class (C++ [class.access.base]p5) of the lookup, if
2498   /// any.  This can generally be recalculated from the context chain,
2499   /// but that can be fairly expensive for unqualified lookups.  If we
2500   /// want to improve memory use here, this could go in a union
2501   /// against the qualified-lookup bits.
2502   CXXRecordDecl *NamingClass;
2503 
UnresolvedLookupExpr(const ASTContext & C,CXXRecordDecl * NamingClass,NestedNameSpecifierLoc QualifierLoc,SourceLocation TemplateKWLoc,const DeclarationNameInfo & NameInfo,bool RequiresADL,bool Overloaded,const TemplateArgumentListInfo * TemplateArgs,UnresolvedSetIterator Begin,UnresolvedSetIterator End)2504   UnresolvedLookupExpr(const ASTContext &C,
2505                        CXXRecordDecl *NamingClass,
2506                        NestedNameSpecifierLoc QualifierLoc,
2507                        SourceLocation TemplateKWLoc,
2508                        const DeclarationNameInfo &NameInfo,
2509                        bool RequiresADL, bool Overloaded,
2510                        const TemplateArgumentListInfo *TemplateArgs,
2511                        UnresolvedSetIterator Begin, UnresolvedSetIterator End)
2512     : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2513                    NameInfo, TemplateArgs, Begin, End, false, false, false),
2514       RequiresADL(RequiresADL),
2515       Overloaded(Overloaded), NamingClass(NamingClass)
2516   {}
2517 
UnresolvedLookupExpr(EmptyShell Empty)2518   UnresolvedLookupExpr(EmptyShell Empty)
2519     : OverloadExpr(UnresolvedLookupExprClass, Empty),
2520       RequiresADL(false), Overloaded(false), NamingClass(nullptr)
2521   {}
2522 
2523   friend class ASTStmtReader;
2524 
2525 public:
Create(const ASTContext & C,CXXRecordDecl * NamingClass,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo,bool ADL,bool Overloaded,UnresolvedSetIterator Begin,UnresolvedSetIterator End)2526   static UnresolvedLookupExpr *Create(const ASTContext &C,
2527                                       CXXRecordDecl *NamingClass,
2528                                       NestedNameSpecifierLoc QualifierLoc,
2529                                       const DeclarationNameInfo &NameInfo,
2530                                       bool ADL, bool Overloaded,
2531                                       UnresolvedSetIterator Begin,
2532                                       UnresolvedSetIterator End) {
2533     return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2534                                        SourceLocation(), NameInfo,
2535                                        ADL, Overloaded, nullptr, Begin, End);
2536   }
2537 
2538   static UnresolvedLookupExpr *Create(const ASTContext &C,
2539                                       CXXRecordDecl *NamingClass,
2540                                       NestedNameSpecifierLoc QualifierLoc,
2541                                       SourceLocation TemplateKWLoc,
2542                                       const DeclarationNameInfo &NameInfo,
2543                                       bool ADL,
2544                                       const TemplateArgumentListInfo *Args,
2545                                       UnresolvedSetIterator Begin,
2546                                       UnresolvedSetIterator End);
2547 
2548   static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C,
2549                                            bool HasTemplateKWAndArgsInfo,
2550                                            unsigned NumTemplateArgs);
2551 
2552   /// True if this declaration should be extended by
2553   /// argument-dependent lookup.
requiresADL()2554   bool requiresADL() const { return RequiresADL; }
2555 
2556   /// True if this lookup is overloaded.
isOverloaded()2557   bool isOverloaded() const { return Overloaded; }
2558 
2559   /// Gets the 'naming class' (in the sense of C++0x
2560   /// [class.access.base]p5) of the lookup.  This is the scope
2561   /// that was looked in to find these results.
getNamingClass()2562   CXXRecordDecl *getNamingClass() const { return NamingClass; }
2563 
getLocStart()2564   SourceLocation getLocStart() const LLVM_READONLY {
2565     if (NestedNameSpecifierLoc l = getQualifierLoc())
2566       return l.getBeginLoc();
2567     return getNameInfo().getLocStart();
2568   }
getLocEnd()2569   SourceLocation getLocEnd() const LLVM_READONLY {
2570     if (hasExplicitTemplateArgs())
2571       return getRAngleLoc();
2572     return getNameInfo().getLocEnd();
2573   }
2574 
children()2575   child_range children() { return child_range(); }
2576 
classof(const Stmt * T)2577   static bool classof(const Stmt *T) {
2578     return T->getStmtClass() == UnresolvedLookupExprClass;
2579   }
2580 };
2581 
2582 /// \brief A qualified reference to a name whose declaration cannot
2583 /// yet be resolved.
2584 ///
2585 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2586 /// it expresses a reference to a declaration such as
2587 /// X<T>::value. The difference, however, is that an
2588 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2589 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2590 /// this case, X<T>::value cannot resolve to a declaration because the
2591 /// declaration will differ from one instantiation of X<T> to the
2592 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2593 /// qualifier (X<T>::) and the name of the entity being referenced
2594 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2595 /// declaration can be found.
2596 class DependentScopeDeclRefExpr : public Expr {
2597   /// \brief The nested-name-specifier that qualifies this unresolved
2598   /// declaration name.
2599   NestedNameSpecifierLoc QualifierLoc;
2600 
2601   /// \brief The name of the entity we will be referencing.
2602   DeclarationNameInfo NameInfo;
2603 
2604   /// \brief Whether the name includes info for explicit template
2605   /// keyword and arguments.
2606   bool HasTemplateKWAndArgsInfo;
2607 
2608   /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2609   ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2610     if (!HasTemplateKWAndArgsInfo) return nullptr;
2611     return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2612   }
2613   /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2614   const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2615     return const_cast<DependentScopeDeclRefExpr*>(this)
2616       ->getTemplateKWAndArgsInfo();
2617   }
2618 
2619   DependentScopeDeclRefExpr(QualType T,
2620                             NestedNameSpecifierLoc QualifierLoc,
2621                             SourceLocation TemplateKWLoc,
2622                             const DeclarationNameInfo &NameInfo,
2623                             const TemplateArgumentListInfo *Args);
2624 
2625 public:
2626   static DependentScopeDeclRefExpr *Create(const ASTContext &C,
2627                                            NestedNameSpecifierLoc QualifierLoc,
2628                                            SourceLocation TemplateKWLoc,
2629                                            const DeclarationNameInfo &NameInfo,
2630                               const TemplateArgumentListInfo *TemplateArgs);
2631 
2632   static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C,
2633                                                 bool HasTemplateKWAndArgsInfo,
2634                                                 unsigned NumTemplateArgs);
2635 
2636   /// \brief Retrieve the name that this expression refers to.
getNameInfo()2637   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2638 
2639   /// \brief Retrieve the name that this expression refers to.
getDeclName()2640   DeclarationName getDeclName() const { return NameInfo.getName(); }
2641 
2642   /// \brief Retrieve the location of the name within the expression.
2643   ///
2644   /// For example, in "X<T>::value" this is the location of "value".
getLocation()2645   SourceLocation getLocation() const { return NameInfo.getLoc(); }
2646 
2647   /// \brief Retrieve the nested-name-specifier that qualifies the
2648   /// name, with source location information.
getQualifierLoc()2649   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2650 
2651   /// \brief Retrieve the nested-name-specifier that qualifies this
2652   /// declaration.
getQualifier()2653   NestedNameSpecifier *getQualifier() const {
2654     return QualifierLoc.getNestedNameSpecifier();
2655   }
2656 
2657   /// \brief Retrieve the location of the template keyword preceding
2658   /// this name, if any.
getTemplateKeywordLoc()2659   SourceLocation getTemplateKeywordLoc() const {
2660     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2661     return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2662   }
2663 
2664   /// \brief Retrieve the location of the left angle bracket starting the
2665   /// explicit template argument list following the name, if any.
getLAngleLoc()2666   SourceLocation getLAngleLoc() const {
2667     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2668     return getTemplateKWAndArgsInfo()->LAngleLoc;
2669   }
2670 
2671   /// \brief Retrieve the location of the right angle bracket ending the
2672   /// explicit template argument list following the name, if any.
getRAngleLoc()2673   SourceLocation getRAngleLoc() const {
2674     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2675     return getTemplateKWAndArgsInfo()->RAngleLoc;
2676   }
2677 
2678   /// Determines whether the name was preceded by the template keyword.
hasTemplateKeyword()2679   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2680 
2681   /// Determines whether this lookup had explicit template arguments.
hasExplicitTemplateArgs()2682   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2683 
2684   // Note that, inconsistently with the explicit-template-argument AST
2685   // nodes, users are *forbidden* from calling these methods on objects
2686   // without explicit template arguments.
2687 
getExplicitTemplateArgs()2688   ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2689     assert(hasExplicitTemplateArgs());
2690     return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
2691   }
2692 
2693   /// Gets a reference to the explicit template argument list.
getExplicitTemplateArgs()2694   const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2695     assert(hasExplicitTemplateArgs());
2696     return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2697   }
2698 
2699   /// \brief Retrieves the optional explicit template arguments.
2700   ///
2701   /// This points to the same data as getExplicitTemplateArgs(), but
2702   /// returns null if there are no explicit template arguments.
getOptionalExplicitTemplateArgs()2703   const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2704     if (!hasExplicitTemplateArgs()) return nullptr;
2705     return &getExplicitTemplateArgs();
2706   }
2707 
2708   /// \brief Copies the template arguments (if present) into the given
2709   /// structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)2710   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2711     getExplicitTemplateArgs().copyInto(List);
2712   }
2713 
getTemplateArgs()2714   TemplateArgumentLoc const *getTemplateArgs() const {
2715     return getExplicitTemplateArgs().getTemplateArgs();
2716   }
2717 
getNumTemplateArgs()2718   unsigned getNumTemplateArgs() const {
2719     return getExplicitTemplateArgs().NumTemplateArgs;
2720   }
2721 
2722   /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr,
2723   /// and differs from getLocation().getStart().
getLocStart()2724   SourceLocation getLocStart() const LLVM_READONLY {
2725     return QualifierLoc.getBeginLoc();
2726   }
getLocEnd()2727   SourceLocation getLocEnd() const LLVM_READONLY {
2728     if (hasExplicitTemplateArgs())
2729       return getRAngleLoc();
2730     return getLocation();
2731   }
2732 
classof(const Stmt * T)2733   static bool classof(const Stmt *T) {
2734     return T->getStmtClass() == DependentScopeDeclRefExprClass;
2735   }
2736 
children()2737   child_range children() { return child_range(); }
2738 
2739   friend class ASTStmtReader;
2740   friend class ASTStmtWriter;
2741 };
2742 
2743 /// Represents an expression -- generally a full-expression -- that
2744 /// introduces cleanups to be run at the end of the sub-expression's
2745 /// evaluation.  The most common source of expression-introduced
2746 /// cleanups is temporary objects in C++, but several other kinds of
2747 /// expressions can create cleanups, including basically every
2748 /// call in ARC that returns an Objective-C pointer.
2749 ///
2750 /// This expression also tracks whether the sub-expression contains a
2751 /// potentially-evaluated block literal.  The lifetime of a block
2752 /// literal is the extent of the enclosing scope.
2753 class ExprWithCleanups : public Expr {
2754 public:
2755   /// The type of objects that are kept in the cleanup.
2756   /// It's useful to remember the set of blocks;  we could also
2757   /// remember the set of temporaries, but there's currently
2758   /// no need.
2759   typedef BlockDecl *CleanupObject;
2760 
2761 private:
2762   Stmt *SubExpr;
2763 
2764   ExprWithCleanups(EmptyShell, unsigned NumObjects);
2765   ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
2766 
getObjectsBuffer()2767   CleanupObject *getObjectsBuffer() {
2768     return reinterpret_cast<CleanupObject*>(this + 1);
2769   }
getObjectsBuffer()2770   const CleanupObject *getObjectsBuffer() const {
2771     return reinterpret_cast<const CleanupObject*>(this + 1);
2772   }
2773   friend class ASTStmtReader;
2774 
2775 public:
2776   static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
2777                                   unsigned numObjects);
2778 
2779   static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
2780                                   ArrayRef<CleanupObject> objects);
2781 
getObjects()2782   ArrayRef<CleanupObject> getObjects() const {
2783     return llvm::makeArrayRef(getObjectsBuffer(), getNumObjects());
2784   }
2785 
getNumObjects()2786   unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
2787 
getObject(unsigned i)2788   CleanupObject getObject(unsigned i) const {
2789     assert(i < getNumObjects() && "Index out of range");
2790     return getObjects()[i];
2791   }
2792 
getSubExpr()2793   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
getSubExpr()2794   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2795 
2796   /// As with any mutator of the AST, be very careful
2797   /// when modifying an existing AST to preserve its invariants.
setSubExpr(Expr * E)2798   void setSubExpr(Expr *E) { SubExpr = E; }
2799 
getLocStart()2800   SourceLocation getLocStart() const LLVM_READONLY {
2801     return SubExpr->getLocStart();
2802   }
getLocEnd()2803   SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
2804 
2805   // Implement isa/cast/dyncast/etc.
classof(const Stmt * T)2806   static bool classof(const Stmt *T) {
2807     return T->getStmtClass() == ExprWithCleanupsClass;
2808   }
2809 
2810   // Iterators
children()2811   child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2812 };
2813 
2814 /// \brief Describes an explicit type conversion that uses functional
2815 /// notion but could not be resolved because one or more arguments are
2816 /// type-dependent.
2817 ///
2818 /// The explicit type conversions expressed by
2819 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
2820 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
2821 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
2822 /// type-dependent. For example, this would occur in a template such
2823 /// as:
2824 ///
2825 /// \code
2826 ///   template<typename T, typename A1>
2827 ///   inline T make_a(const A1& a1) {
2828 ///     return T(a1);
2829 ///   }
2830 /// \endcode
2831 ///
2832 /// When the returned expression is instantiated, it may resolve to a
2833 /// constructor call, conversion function call, or some kind of type
2834 /// conversion.
2835 class CXXUnresolvedConstructExpr : public Expr {
2836   /// \brief The type being constructed.
2837   TypeSourceInfo *Type;
2838 
2839   /// \brief The location of the left parentheses ('(').
2840   SourceLocation LParenLoc;
2841 
2842   /// \brief The location of the right parentheses (')').
2843   SourceLocation RParenLoc;
2844 
2845   /// \brief The number of arguments used to construct the type.
2846   unsigned NumArgs;
2847 
2848   CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2849                              SourceLocation LParenLoc,
2850                              ArrayRef<Expr*> Args,
2851                              SourceLocation RParenLoc);
2852 
CXXUnresolvedConstructExpr(EmptyShell Empty,unsigned NumArgs)2853   CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2854     : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2855 
2856   friend class ASTStmtReader;
2857 
2858 public:
2859   static CXXUnresolvedConstructExpr *Create(const ASTContext &C,
2860                                             TypeSourceInfo *Type,
2861                                             SourceLocation LParenLoc,
2862                                             ArrayRef<Expr*> Args,
2863                                             SourceLocation RParenLoc);
2864 
2865   static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C,
2866                                                  unsigned NumArgs);
2867 
2868   /// \brief Retrieve the type that is being constructed, as specified
2869   /// in the source code.
getTypeAsWritten()2870   QualType getTypeAsWritten() const { return Type->getType(); }
2871 
2872   /// \brief Retrieve the type source information for the type being
2873   /// constructed.
getTypeSourceInfo()2874   TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2875 
2876   /// \brief Retrieve the location of the left parentheses ('(') that
2877   /// precedes the argument list.
getLParenLoc()2878   SourceLocation getLParenLoc() const { return LParenLoc; }
setLParenLoc(SourceLocation L)2879   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2880 
2881   /// \brief Retrieve the location of the right parentheses (')') that
2882   /// follows the argument list.
getRParenLoc()2883   SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)2884   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2885 
2886   /// \brief Retrieve the number of arguments.
arg_size()2887   unsigned arg_size() const { return NumArgs; }
2888 
2889   typedef Expr** arg_iterator;
arg_begin()2890   arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
arg_end()2891   arg_iterator arg_end() { return arg_begin() + NumArgs; }
2892 
2893   typedef const Expr* const * const_arg_iterator;
arg_begin()2894   const_arg_iterator arg_begin() const {
2895     return reinterpret_cast<const Expr* const *>(this + 1);
2896   }
arg_end()2897   const_arg_iterator arg_end() const {
2898     return arg_begin() + NumArgs;
2899   }
2900 
getArg(unsigned I)2901   Expr *getArg(unsigned I) {
2902     assert(I < NumArgs && "Argument index out-of-range");
2903     return *(arg_begin() + I);
2904   }
2905 
getArg(unsigned I)2906   const Expr *getArg(unsigned I) const {
2907     assert(I < NumArgs && "Argument index out-of-range");
2908     return *(arg_begin() + I);
2909   }
2910 
setArg(unsigned I,Expr * E)2911   void setArg(unsigned I, Expr *E) {
2912     assert(I < NumArgs && "Argument index out-of-range");
2913     *(arg_begin() + I) = E;
2914   }
2915 
2916   SourceLocation getLocStart() const LLVM_READONLY;
getLocEnd()2917   SourceLocation getLocEnd() const LLVM_READONLY {
2918     if (!RParenLoc.isValid() && NumArgs > 0)
2919       return getArg(NumArgs - 1)->getLocEnd();
2920     return RParenLoc;
2921   }
2922 
classof(const Stmt * T)2923   static bool classof(const Stmt *T) {
2924     return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2925   }
2926 
2927   // Iterators
children()2928   child_range children() {
2929     Stmt **begin = reinterpret_cast<Stmt**>(this+1);
2930     return child_range(begin, begin + NumArgs);
2931   }
2932 };
2933 
2934 /// \brief Represents a C++ member access expression where the actual
2935 /// member referenced could not be resolved because the base
2936 /// expression or the member name was dependent.
2937 ///
2938 /// Like UnresolvedMemberExprs, these can be either implicit or
2939 /// explicit accesses.  It is only possible to get one of these with
2940 /// an implicit access if a qualifier is provided.
2941 class CXXDependentScopeMemberExpr : public Expr {
2942   /// \brief The expression for the base pointer or class reference,
2943   /// e.g., the \c x in x.f.  Can be null in implicit accesses.
2944   Stmt *Base;
2945 
2946   /// \brief The type of the base expression.  Never null, even for
2947   /// implicit accesses.
2948   QualType BaseType;
2949 
2950   /// \brief Whether this member expression used the '->' operator or
2951   /// the '.' operator.
2952   bool IsArrow : 1;
2953 
2954   /// \brief Whether this member expression has info for explicit template
2955   /// keyword and arguments.
2956   bool HasTemplateKWAndArgsInfo : 1;
2957 
2958   /// \brief The location of the '->' or '.' operator.
2959   SourceLocation OperatorLoc;
2960 
2961   /// \brief The nested-name-specifier that precedes the member name, if any.
2962   NestedNameSpecifierLoc QualifierLoc;
2963 
2964   /// \brief In a qualified member access expression such as t->Base::f, this
2965   /// member stores the resolves of name lookup in the context of the member
2966   /// access expression, to be used at instantiation time.
2967   ///
2968   /// FIXME: This member, along with the QualifierLoc, could
2969   /// be stuck into a structure that is optionally allocated at the end of
2970   /// the CXXDependentScopeMemberExpr, to save space in the common case.
2971   NamedDecl *FirstQualifierFoundInScope;
2972 
2973   /// \brief The member to which this member expression refers, which
2974   /// can be name, overloaded operator, or destructor.
2975   ///
2976   /// FIXME: could also be a template-id
2977   DeclarationNameInfo MemberNameInfo;
2978 
2979   /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2980   ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2981     if (!HasTemplateKWAndArgsInfo) return nullptr;
2982     return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2983   }
2984   /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2985   const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2986     return const_cast<CXXDependentScopeMemberExpr*>(this)
2987       ->getTemplateKWAndArgsInfo();
2988   }
2989 
2990   CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
2991                               QualType BaseType, bool IsArrow,
2992                               SourceLocation OperatorLoc,
2993                               NestedNameSpecifierLoc QualifierLoc,
2994                               SourceLocation TemplateKWLoc,
2995                               NamedDecl *FirstQualifierFoundInScope,
2996                               DeclarationNameInfo MemberNameInfo,
2997                               const TemplateArgumentListInfo *TemplateArgs);
2998 
2999 public:
3000   CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3001                               QualType BaseType, bool IsArrow,
3002                               SourceLocation OperatorLoc,
3003                               NestedNameSpecifierLoc QualifierLoc,
3004                               NamedDecl *FirstQualifierFoundInScope,
3005                               DeclarationNameInfo MemberNameInfo);
3006 
3007   static CXXDependentScopeMemberExpr *
3008   Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
3009          SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
3010          SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
3011          DeclarationNameInfo MemberNameInfo,
3012          const TemplateArgumentListInfo *TemplateArgs);
3013 
3014   static CXXDependentScopeMemberExpr *
3015   CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3016               unsigned NumTemplateArgs);
3017 
3018   /// \brief True if this is an implicit access, i.e. one in which the
3019   /// member being accessed was not written in the source.  The source
3020   /// location of the operator is invalid in this case.
3021   bool isImplicitAccess() const;
3022 
3023   /// \brief Retrieve the base object of this member expressions,
3024   /// e.g., the \c x in \c x.m.
getBase()3025   Expr *getBase() const {
3026     assert(!isImplicitAccess());
3027     return cast<Expr>(Base);
3028   }
3029 
getBaseType()3030   QualType getBaseType() const { return BaseType; }
3031 
3032   /// \brief Determine whether this member expression used the '->'
3033   /// operator; otherwise, it used the '.' operator.
isArrow()3034   bool isArrow() const { return IsArrow; }
3035 
3036   /// \brief Retrieve the location of the '->' or '.' operator.
getOperatorLoc()3037   SourceLocation getOperatorLoc() const { return OperatorLoc; }
3038 
3039   /// \brief Retrieve the nested-name-specifier that qualifies the member
3040   /// name.
getQualifier()3041   NestedNameSpecifier *getQualifier() const {
3042     return QualifierLoc.getNestedNameSpecifier();
3043   }
3044 
3045   /// \brief Retrieve the nested-name-specifier that qualifies the member
3046   /// name, with source location information.
getQualifierLoc()3047   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3048 
3049 
3050   /// \brief Retrieve the first part of the nested-name-specifier that was
3051   /// found in the scope of the member access expression when the member access
3052   /// was initially parsed.
3053   ///
3054   /// This function only returns a useful result when member access expression
3055   /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3056   /// returned by this function describes what was found by unqualified name
3057   /// lookup for the identifier "Base" within the scope of the member access
3058   /// expression itself. At template instantiation time, this information is
3059   /// combined with the results of name lookup into the type of the object
3060   /// expression itself (the class type of x).
getFirstQualifierFoundInScope()3061   NamedDecl *getFirstQualifierFoundInScope() const {
3062     return FirstQualifierFoundInScope;
3063   }
3064 
3065   /// \brief Retrieve the name of the member that this expression
3066   /// refers to.
getMemberNameInfo()3067   const DeclarationNameInfo &getMemberNameInfo() const {
3068     return MemberNameInfo;
3069   }
3070 
3071   /// \brief Retrieve the name of the member that this expression
3072   /// refers to.
getMember()3073   DeclarationName getMember() const { return MemberNameInfo.getName(); }
3074 
3075   // \brief Retrieve the location of the name of the member that this
3076   // expression refers to.
getMemberLoc()3077   SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3078 
3079   /// \brief Retrieve the location of the template keyword preceding the
3080   /// member name, if any.
getTemplateKeywordLoc()3081   SourceLocation getTemplateKeywordLoc() const {
3082     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3083     return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
3084   }
3085 
3086   /// \brief Retrieve the location of the left angle bracket starting the
3087   /// explicit template argument list following the member name, if any.
getLAngleLoc()3088   SourceLocation getLAngleLoc() const {
3089     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3090     return getTemplateKWAndArgsInfo()->LAngleLoc;
3091   }
3092 
3093   /// \brief Retrieve the location of the right angle bracket ending the
3094   /// explicit template argument list following the member name, if any.
getRAngleLoc()3095   SourceLocation getRAngleLoc() const {
3096     if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3097     return getTemplateKWAndArgsInfo()->RAngleLoc;
3098   }
3099 
3100   /// Determines whether the member name was preceded by the template keyword.
hasTemplateKeyword()3101   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3102 
3103   /// \brief Determines whether this member expression actually had a C++
3104   /// template argument list explicitly specified, e.g., x.f<int>.
hasExplicitTemplateArgs()3105   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3106 
3107   /// \brief Retrieve the explicit template argument list that followed the
3108   /// member template name, if any.
getExplicitTemplateArgs()3109   ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
3110     assert(hasExplicitTemplateArgs());
3111     return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
3112   }
3113 
3114   /// \brief Retrieve the explicit template argument list that followed the
3115   /// member template name, if any.
getExplicitTemplateArgs()3116   const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
3117     return const_cast<CXXDependentScopeMemberExpr *>(this)
3118              ->getExplicitTemplateArgs();
3119   }
3120 
3121   /// \brief Retrieves the optional explicit template arguments.
3122   ///
3123   /// This points to the same data as getExplicitTemplateArgs(), but
3124   /// returns null if there are no explicit template arguments.
getOptionalExplicitTemplateArgs()3125   const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
3126     if (!hasExplicitTemplateArgs()) return nullptr;
3127     return &getExplicitTemplateArgs();
3128   }
3129 
3130   /// \brief Copies the template arguments (if present) into the given
3131   /// structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)3132   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3133     getExplicitTemplateArgs().copyInto(List);
3134   }
3135 
3136   /// \brief Initializes the template arguments using the given structure.
initializeTemplateArgumentsFrom(const TemplateArgumentListInfo & List)3137   void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
3138     getExplicitTemplateArgs().initializeFrom(List);
3139   }
3140 
3141   /// \brief Retrieve the template arguments provided as part of this
3142   /// template-id.
getTemplateArgs()3143   const TemplateArgumentLoc *getTemplateArgs() const {
3144     return getExplicitTemplateArgs().getTemplateArgs();
3145   }
3146 
3147   /// \brief Retrieve the number of template arguments provided as part of this
3148   /// template-id.
getNumTemplateArgs()3149   unsigned getNumTemplateArgs() const {
3150     return getExplicitTemplateArgs().NumTemplateArgs;
3151   }
3152 
getLocStart()3153   SourceLocation getLocStart() const LLVM_READONLY {
3154     if (!isImplicitAccess())
3155       return Base->getLocStart();
3156     if (getQualifier())
3157       return getQualifierLoc().getBeginLoc();
3158     return MemberNameInfo.getBeginLoc();
3159 
3160   }
getLocEnd()3161   SourceLocation getLocEnd() const LLVM_READONLY {
3162     if (hasExplicitTemplateArgs())
3163       return getRAngleLoc();
3164     return MemberNameInfo.getEndLoc();
3165   }
3166 
classof(const Stmt * T)3167   static bool classof(const Stmt *T) {
3168     return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3169   }
3170 
3171   // Iterators
children()3172   child_range children() {
3173     if (isImplicitAccess()) return child_range();
3174     return child_range(&Base, &Base + 1);
3175   }
3176 
3177   friend class ASTStmtReader;
3178   friend class ASTStmtWriter;
3179 };
3180 
3181 /// \brief Represents a C++ member access expression for which lookup
3182 /// produced a set of overloaded functions.
3183 ///
3184 /// The member access may be explicit or implicit:
3185 /// \code
3186 ///    struct A {
3187 ///      int a, b;
3188 ///      int explicitAccess() { return this->a + this->A::b; }
3189 ///      int implicitAccess() { return a + A::b; }
3190 ///    };
3191 /// \endcode
3192 ///
3193 /// In the final AST, an explicit access always becomes a MemberExpr.
3194 /// An implicit access may become either a MemberExpr or a
3195 /// DeclRefExpr, depending on whether the member is static.
3196 class UnresolvedMemberExpr : public OverloadExpr {
3197   /// \brief Whether this member expression used the '->' operator or
3198   /// the '.' operator.
3199   bool IsArrow : 1;
3200 
3201   /// \brief Whether the lookup results contain an unresolved using
3202   /// declaration.
3203   bool HasUnresolvedUsing : 1;
3204 
3205   /// \brief The expression for the base pointer or class reference,
3206   /// e.g., the \c x in x.f.
3207   ///
3208   /// This can be null if this is an 'unbased' member expression.
3209   Stmt *Base;
3210 
3211   /// \brief The type of the base expression; never null.
3212   QualType BaseType;
3213 
3214   /// \brief The location of the '->' or '.' operator.
3215   SourceLocation OperatorLoc;
3216 
3217   UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing,
3218                        Expr *Base, QualType BaseType, bool IsArrow,
3219                        SourceLocation OperatorLoc,
3220                        NestedNameSpecifierLoc QualifierLoc,
3221                        SourceLocation TemplateKWLoc,
3222                        const DeclarationNameInfo &MemberNameInfo,
3223                        const TemplateArgumentListInfo *TemplateArgs,
3224                        UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3225 
UnresolvedMemberExpr(EmptyShell Empty)3226   UnresolvedMemberExpr(EmptyShell Empty)
3227     : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3228       HasUnresolvedUsing(false), Base(nullptr) { }
3229 
3230   friend class ASTStmtReader;
3231 
3232 public:
3233   static UnresolvedMemberExpr *
3234   Create(const ASTContext &C, bool HasUnresolvedUsing,
3235          Expr *Base, QualType BaseType, bool IsArrow,
3236          SourceLocation OperatorLoc,
3237          NestedNameSpecifierLoc QualifierLoc,
3238          SourceLocation TemplateKWLoc,
3239          const DeclarationNameInfo &MemberNameInfo,
3240          const TemplateArgumentListInfo *TemplateArgs,
3241          UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3242 
3243   static UnresolvedMemberExpr *
3244   CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3245               unsigned NumTemplateArgs);
3246 
3247   /// \brief True if this is an implicit access, i.e., one in which the
3248   /// member being accessed was not written in the source.
3249   ///
3250   /// The source location of the operator is invalid in this case.
3251   bool isImplicitAccess() const;
3252 
3253   /// \brief Retrieve the base object of this member expressions,
3254   /// e.g., the \c x in \c x.m.
getBase()3255   Expr *getBase() {
3256     assert(!isImplicitAccess());
3257     return cast<Expr>(Base);
3258   }
getBase()3259   const Expr *getBase() const {
3260     assert(!isImplicitAccess());
3261     return cast<Expr>(Base);
3262   }
3263 
getBaseType()3264   QualType getBaseType() const { return BaseType; }
3265 
3266   /// \brief Determine whether the lookup results contain an unresolved using
3267   /// declaration.
hasUnresolvedUsing()3268   bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3269 
3270   /// \brief Determine whether this member expression used the '->'
3271   /// operator; otherwise, it used the '.' operator.
isArrow()3272   bool isArrow() const { return IsArrow; }
3273 
3274   /// \brief Retrieve the location of the '->' or '.' operator.
getOperatorLoc()3275   SourceLocation getOperatorLoc() const { return OperatorLoc; }
3276 
3277   /// \brief Retrieve the naming class of this lookup.
3278   CXXRecordDecl *getNamingClass() const;
3279 
3280   /// \brief Retrieve the full name info for the member that this expression
3281   /// refers to.
getMemberNameInfo()3282   const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3283 
3284   /// \brief Retrieve the name of the member that this expression
3285   /// refers to.
getMemberName()3286   DeclarationName getMemberName() const { return getName(); }
3287 
3288   // \brief Retrieve the location of the name of the member that this
3289   // expression refers to.
getMemberLoc()3290   SourceLocation getMemberLoc() const { return getNameLoc(); }
3291 
3292   // \brief Return the preferred location (the member name) for the arrow when
3293   // diagnosing a problem with this expression.
getExprLoc()3294   SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
3295 
getLocStart()3296   SourceLocation getLocStart() const LLVM_READONLY {
3297     if (!isImplicitAccess())
3298       return Base->getLocStart();
3299     if (NestedNameSpecifierLoc l = getQualifierLoc())
3300       return l.getBeginLoc();
3301     return getMemberNameInfo().getLocStart();
3302   }
getLocEnd()3303   SourceLocation getLocEnd() const LLVM_READONLY {
3304     if (hasExplicitTemplateArgs())
3305       return getRAngleLoc();
3306     return getMemberNameInfo().getLocEnd();
3307   }
3308 
classof(const Stmt * T)3309   static bool classof(const Stmt *T) {
3310     return T->getStmtClass() == UnresolvedMemberExprClass;
3311   }
3312 
3313   // Iterators
children()3314   child_range children() {
3315     if (isImplicitAccess()) return child_range();
3316     return child_range(&Base, &Base + 1);
3317   }
3318 };
3319 
3320 /// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
3321 ///
3322 /// The noexcept expression tests whether a given expression might throw. Its
3323 /// result is a boolean constant.
3324 class CXXNoexceptExpr : public Expr {
3325   bool Value : 1;
3326   Stmt *Operand;
3327   SourceRange Range;
3328 
3329   friend class ASTStmtReader;
3330 
3331 public:
CXXNoexceptExpr(QualType Ty,Expr * Operand,CanThrowResult Val,SourceLocation Keyword,SourceLocation RParen)3332   CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3333                   SourceLocation Keyword, SourceLocation RParen)
3334     : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3335            /*TypeDependent*/false,
3336            /*ValueDependent*/Val == CT_Dependent,
3337            Val == CT_Dependent || Operand->isInstantiationDependent(),
3338            Operand->containsUnexpandedParameterPack()),
3339       Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
3340   { }
3341 
CXXNoexceptExpr(EmptyShell Empty)3342   CXXNoexceptExpr(EmptyShell Empty)
3343     : Expr(CXXNoexceptExprClass, Empty)
3344   { }
3345 
getOperand()3346   Expr *getOperand() const { return static_cast<Expr*>(Operand); }
3347 
getLocStart()3348   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
getLocEnd()3349   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
getSourceRange()3350   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
3351 
getValue()3352   bool getValue() const { return Value; }
3353 
classof(const Stmt * T)3354   static bool classof(const Stmt *T) {
3355     return T->getStmtClass() == CXXNoexceptExprClass;
3356   }
3357 
3358   // Iterators
children()3359   child_range children() { return child_range(&Operand, &Operand + 1); }
3360 };
3361 
3362 /// \brief Represents a C++11 pack expansion that produces a sequence of
3363 /// expressions.
3364 ///
3365 /// A pack expansion expression contains a pattern (which itself is an
3366 /// expression) followed by an ellipsis. For example:
3367 ///
3368 /// \code
3369 /// template<typename F, typename ...Types>
3370 /// void forward(F f, Types &&...args) {
3371 ///   f(static_cast<Types&&>(args)...);
3372 /// }
3373 /// \endcode
3374 ///
3375 /// Here, the argument to the function object \c f is a pack expansion whose
3376 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
3377 /// template is instantiated, the pack expansion will instantiate to zero or
3378 /// or more function arguments to the function object \c f.
3379 class PackExpansionExpr : public Expr {
3380   SourceLocation EllipsisLoc;
3381 
3382   /// \brief The number of expansions that will be produced by this pack
3383   /// expansion expression, if known.
3384   ///
3385   /// When zero, the number of expansions is not known. Otherwise, this value
3386   /// is the number of expansions + 1.
3387   unsigned NumExpansions;
3388 
3389   Stmt *Pattern;
3390 
3391   friend class ASTStmtReader;
3392   friend class ASTStmtWriter;
3393 
3394 public:
PackExpansionExpr(QualType T,Expr * Pattern,SourceLocation EllipsisLoc,Optional<unsigned> NumExpansions)3395   PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3396                     Optional<unsigned> NumExpansions)
3397     : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3398            Pattern->getObjectKind(), /*TypeDependent=*/true,
3399            /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3400            /*ContainsUnexpandedParameterPack=*/false),
3401       EllipsisLoc(EllipsisLoc),
3402       NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3403       Pattern(Pattern) { }
3404 
PackExpansionExpr(EmptyShell Empty)3405   PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3406 
3407   /// \brief Retrieve the pattern of the pack expansion.
getPattern()3408   Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3409 
3410   /// \brief Retrieve the pattern of the pack expansion.
getPattern()3411   const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3412 
3413   /// \brief Retrieve the location of the ellipsis that describes this pack
3414   /// expansion.
getEllipsisLoc()3415   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3416 
3417   /// \brief Determine the number of expansions that will be produced when
3418   /// this pack expansion is instantiated, if already known.
getNumExpansions()3419   Optional<unsigned> getNumExpansions() const {
3420     if (NumExpansions)
3421       return NumExpansions - 1;
3422 
3423     return None;
3424   }
3425 
getLocStart()3426   SourceLocation getLocStart() const LLVM_READONLY {
3427     return Pattern->getLocStart();
3428   }
getLocEnd()3429   SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; }
3430 
classof(const Stmt * T)3431   static bool classof(const Stmt *T) {
3432     return T->getStmtClass() == PackExpansionExprClass;
3433   }
3434 
3435   // Iterators
children()3436   child_range children() {
3437     return child_range(&Pattern, &Pattern + 1);
3438   }
3439 };
3440 
getTemplateKWAndArgsInfo()3441 inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3442   if (!HasTemplateKWAndArgsInfo) return nullptr;
3443   if (isa<UnresolvedLookupExpr>(this))
3444     return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3445       (cast<UnresolvedLookupExpr>(this) + 1);
3446   else
3447     return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3448       (cast<UnresolvedMemberExpr>(this) + 1);
3449 }
3450 
3451 /// \brief Represents an expression that computes the length of a parameter
3452 /// pack.
3453 ///
3454 /// \code
3455 /// template<typename ...Types>
3456 /// struct count {
3457 ///   static const unsigned value = sizeof...(Types);
3458 /// };
3459 /// \endcode
3460 class SizeOfPackExpr : public Expr {
3461   /// \brief The location of the \c sizeof keyword.
3462   SourceLocation OperatorLoc;
3463 
3464   /// \brief The location of the name of the parameter pack.
3465   SourceLocation PackLoc;
3466 
3467   /// \brief The location of the closing parenthesis.
3468   SourceLocation RParenLoc;
3469 
3470   /// \brief The length of the parameter pack, if known.
3471   ///
3472   /// When this expression is value-dependent, the length of the parameter pack
3473   /// is unknown. When this expression is not value-dependent, the length is
3474   /// known.
3475   unsigned Length;
3476 
3477   /// \brief The parameter pack itself.
3478   NamedDecl *Pack;
3479 
3480   friend class ASTStmtReader;
3481   friend class ASTStmtWriter;
3482 
3483 public:
3484   /// \brief Create a value-dependent expression that computes the length of
3485   /// the given parameter pack.
SizeOfPackExpr(QualType SizeType,SourceLocation OperatorLoc,NamedDecl * Pack,SourceLocation PackLoc,SourceLocation RParenLoc)3486   SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3487                  SourceLocation PackLoc, SourceLocation RParenLoc)
3488     : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3489            /*TypeDependent=*/false, /*ValueDependent=*/true,
3490            /*InstantiationDependent=*/true,
3491            /*ContainsUnexpandedParameterPack=*/false),
3492       OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3493       Length(0), Pack(Pack) { }
3494 
3495   /// \brief Create an expression that computes the length of
3496   /// the given parameter pack, which is already known.
SizeOfPackExpr(QualType SizeType,SourceLocation OperatorLoc,NamedDecl * Pack,SourceLocation PackLoc,SourceLocation RParenLoc,unsigned Length)3497   SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3498                  SourceLocation PackLoc, SourceLocation RParenLoc,
3499                  unsigned Length)
3500   : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3501          /*TypeDependent=*/false, /*ValueDependent=*/false,
3502          /*InstantiationDependent=*/false,
3503          /*ContainsUnexpandedParameterPack=*/false),
3504     OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3505     Length(Length), Pack(Pack) { }
3506 
3507   /// \brief Create an empty expression.
SizeOfPackExpr(EmptyShell Empty)3508   SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3509 
3510   /// \brief Determine the location of the 'sizeof' keyword.
getOperatorLoc()3511   SourceLocation getOperatorLoc() const { return OperatorLoc; }
3512 
3513   /// \brief Determine the location of the parameter pack.
getPackLoc()3514   SourceLocation getPackLoc() const { return PackLoc; }
3515 
3516   /// \brief Determine the location of the right parenthesis.
getRParenLoc()3517   SourceLocation getRParenLoc() const { return RParenLoc; }
3518 
3519   /// \brief Retrieve the parameter pack.
getPack()3520   NamedDecl *getPack() const { return Pack; }
3521 
3522   /// \brief Retrieve the length of the parameter pack.
3523   ///
3524   /// This routine may only be invoked when the expression is not
3525   /// value-dependent.
getPackLength()3526   unsigned getPackLength() const {
3527     assert(!isValueDependent() &&
3528            "Cannot get the length of a value-dependent pack size expression");
3529     return Length;
3530   }
3531 
getLocStart()3532   SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
getLocEnd()3533   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
3534 
classof(const Stmt * T)3535   static bool classof(const Stmt *T) {
3536     return T->getStmtClass() == SizeOfPackExprClass;
3537   }
3538 
3539   // Iterators
children()3540   child_range children() { return child_range(); }
3541 };
3542 
3543 /// \brief Represents a reference to a non-type template parameter
3544 /// that has been substituted with a template argument.
3545 class SubstNonTypeTemplateParmExpr : public Expr {
3546   /// \brief The replaced parameter.
3547   NonTypeTemplateParmDecl *Param;
3548 
3549   /// \brief The replacement expression.
3550   Stmt *Replacement;
3551 
3552   /// \brief The location of the non-type template parameter reference.
3553   SourceLocation NameLoc;
3554 
3555   friend class ASTReader;
3556   friend class ASTStmtReader;
SubstNonTypeTemplateParmExpr(EmptyShell Empty)3557   explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
3558     : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
3559 
3560 public:
SubstNonTypeTemplateParmExpr(QualType type,ExprValueKind valueKind,SourceLocation loc,NonTypeTemplateParmDecl * param,Expr * replacement)3561   SubstNonTypeTemplateParmExpr(QualType type,
3562                                ExprValueKind valueKind,
3563                                SourceLocation loc,
3564                                NonTypeTemplateParmDecl *param,
3565                                Expr *replacement)
3566     : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3567            replacement->isTypeDependent(), replacement->isValueDependent(),
3568            replacement->isInstantiationDependent(),
3569            replacement->containsUnexpandedParameterPack()),
3570       Param(param), Replacement(replacement), NameLoc(loc) {}
3571 
getNameLoc()3572   SourceLocation getNameLoc() const { return NameLoc; }
getLocStart()3573   SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
getLocEnd()3574   SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3575 
getReplacement()3576   Expr *getReplacement() const { return cast<Expr>(Replacement); }
3577 
getParameter()3578   NonTypeTemplateParmDecl *getParameter() const { return Param; }
3579 
classof(const Stmt * s)3580   static bool classof(const Stmt *s) {
3581     return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3582   }
3583 
3584   // Iterators
children()3585   child_range children() { return child_range(&Replacement, &Replacement+1); }
3586 };
3587 
3588 /// \brief Represents a reference to a non-type template parameter pack that
3589 /// has been substituted with a non-template argument pack.
3590 ///
3591 /// When a pack expansion in the source code contains multiple parameter packs
3592 /// and those parameter packs correspond to different levels of template
3593 /// parameter lists, this node is used to represent a non-type template
3594 /// parameter pack from an outer level, which has already had its argument pack
3595 /// substituted but that still lives within a pack expansion that itself
3596 /// could not be instantiated. When actually performing a substitution into
3597 /// that pack expansion (e.g., when all template parameters have corresponding
3598 /// arguments), this type will be replaced with the appropriate underlying
3599 /// expression at the current pack substitution index.
3600 class SubstNonTypeTemplateParmPackExpr : public Expr {
3601   /// \brief The non-type template parameter pack itself.
3602   NonTypeTemplateParmDecl *Param;
3603 
3604   /// \brief A pointer to the set of template arguments that this
3605   /// parameter pack is instantiated with.
3606   const TemplateArgument *Arguments;
3607 
3608   /// \brief The number of template arguments in \c Arguments.
3609   unsigned NumArguments;
3610 
3611   /// \brief The location of the non-type template parameter pack reference.
3612   SourceLocation NameLoc;
3613 
3614   friend class ASTReader;
3615   friend class ASTStmtReader;
SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)3616   explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3617     : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3618 
3619 public:
3620   SubstNonTypeTemplateParmPackExpr(QualType T,
3621                                    NonTypeTemplateParmDecl *Param,
3622                                    SourceLocation NameLoc,
3623                                    const TemplateArgument &ArgPack);
3624 
3625   /// \brief Retrieve the non-type template parameter pack being substituted.
getParameterPack()3626   NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3627 
3628   /// \brief Retrieve the location of the parameter pack name.
getParameterPackLocation()3629   SourceLocation getParameterPackLocation() const { return NameLoc; }
3630 
3631   /// \brief Retrieve the template argument pack containing the substituted
3632   /// template arguments.
3633   TemplateArgument getArgumentPack() const;
3634 
getLocStart()3635   SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
getLocEnd()3636   SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3637 
classof(const Stmt * T)3638   static bool classof(const Stmt *T) {
3639     return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3640   }
3641 
3642   // Iterators
children()3643   child_range children() { return child_range(); }
3644 };
3645 
3646 /// \brief Represents a reference to a function parameter pack that has been
3647 /// substituted but not yet expanded.
3648 ///
3649 /// When a pack expansion contains multiple parameter packs at different levels,
3650 /// this node is used to represent a function parameter pack at an outer level
3651 /// which we have already substituted to refer to expanded parameters, but where
3652 /// the containing pack expansion cannot yet be expanded.
3653 ///
3654 /// \code
3655 /// template<typename...Ts> struct S {
3656 ///   template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
3657 /// };
3658 /// template struct S<int, int>;
3659 /// \endcode
3660 class FunctionParmPackExpr : public Expr {
3661   /// \brief The function parameter pack which was referenced.
3662   ParmVarDecl *ParamPack;
3663 
3664   /// \brief The location of the function parameter pack reference.
3665   SourceLocation NameLoc;
3666 
3667   /// \brief The number of expansions of this pack.
3668   unsigned NumParameters;
3669 
3670   FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
3671                        SourceLocation NameLoc, unsigned NumParams,
3672                        Decl * const *Params);
3673 
3674   friend class ASTReader;
3675   friend class ASTStmtReader;
3676 
3677 public:
3678   static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
3679                                       ParmVarDecl *ParamPack,
3680                                       SourceLocation NameLoc,
3681                                       ArrayRef<Decl *> Params);
3682   static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
3683                                            unsigned NumParams);
3684 
3685   /// \brief Get the parameter pack which this expression refers to.
getParameterPack()3686   ParmVarDecl *getParameterPack() const { return ParamPack; }
3687 
3688   /// \brief Get the location of the parameter pack.
getParameterPackLocation()3689   SourceLocation getParameterPackLocation() const { return NameLoc; }
3690 
3691   /// \brief Iterators over the parameters which the parameter pack expanded
3692   /// into.
3693   typedef ParmVarDecl * const *iterator;
begin()3694   iterator begin() const { return reinterpret_cast<iterator>(this+1); }
end()3695   iterator end() const { return begin() + NumParameters; }
3696 
3697   /// \brief Get the number of parameters in this parameter pack.
getNumExpansions()3698   unsigned getNumExpansions() const { return NumParameters; }
3699 
3700   /// \brief Get an expansion of the parameter pack by index.
getExpansion(unsigned I)3701   ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
3702 
getLocStart()3703   SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
getLocEnd()3704   SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3705 
classof(const Stmt * T)3706   static bool classof(const Stmt *T) {
3707     return T->getStmtClass() == FunctionParmPackExprClass;
3708   }
3709 
children()3710   child_range children() { return child_range(); }
3711 };
3712 
3713 /// \brief Represents a prvalue temporary that is written into memory so that
3714 /// a reference can bind to it.
3715 ///
3716 /// Prvalue expressions are materialized when they need to have an address
3717 /// in memory for a reference to bind to. This happens when binding a
3718 /// reference to the result of a conversion, e.g.,
3719 ///
3720 /// \code
3721 /// const int &r = 1.0;
3722 /// \endcode
3723 ///
3724 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3725 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
3726 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3727 /// (either an lvalue or an xvalue, depending on the kind of reference binding
3728 /// to it), maintaining the invariant that references always bind to glvalues.
3729 ///
3730 /// Reference binding and copy-elision can both extend the lifetime of a
3731 /// temporary. When either happens, the expression will also track the
3732 /// declaration which is responsible for the lifetime extension.
3733 class MaterializeTemporaryExpr : public Expr {
3734 private:
3735   struct ExtraState {
3736     /// \brief The temporary-generating expression whose value will be
3737     /// materialized.
3738     Stmt *Temporary;
3739 
3740     /// \brief The declaration which lifetime-extended this reference, if any.
3741     /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
3742     const ValueDecl *ExtendingDecl;
3743 
3744     unsigned ManglingNumber;
3745   };
3746   llvm::PointerUnion<Stmt *, ExtraState *> State;
3747 
3748   friend class ASTStmtReader;
3749   friend class ASTStmtWriter;
3750 
3751   void initializeExtraState(const ValueDecl *ExtendedBy,
3752                             unsigned ManglingNumber);
3753 
3754 public:
MaterializeTemporaryExpr(QualType T,Expr * Temporary,bool BoundToLvalueReference)3755   MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3756                            bool BoundToLvalueReference)
3757     : Expr(MaterializeTemporaryExprClass, T,
3758            BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3759            Temporary->isTypeDependent(), Temporary->isValueDependent(),
3760            Temporary->isInstantiationDependent(),
3761            Temporary->containsUnexpandedParameterPack()),
3762         State(Temporary) {}
3763 
MaterializeTemporaryExpr(EmptyShell Empty)3764   MaterializeTemporaryExpr(EmptyShell Empty)
3765     : Expr(MaterializeTemporaryExprClass, Empty) { }
3766 
getTemporary()3767   Stmt *getTemporary() const {
3768     return State.is<Stmt *>() ? State.get<Stmt *>()
3769                               : State.get<ExtraState *>()->Temporary;
3770   }
3771 
3772   /// \brief Retrieve the temporary-generating subexpression whose value will
3773   /// be materialized into a glvalue.
GetTemporaryExpr()3774   Expr *GetTemporaryExpr() const { return static_cast<Expr *>(getTemporary()); }
3775 
3776   /// \brief Retrieve the storage duration for the materialized temporary.
getStorageDuration()3777   StorageDuration getStorageDuration() const {
3778     const ValueDecl *ExtendingDecl = getExtendingDecl();
3779     if (!ExtendingDecl)
3780       return SD_FullExpression;
3781     // FIXME: This is not necessarily correct for a temporary materialized
3782     // within a default initializer.
3783     if (isa<FieldDecl>(ExtendingDecl))
3784       return SD_Automatic;
3785     return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
3786   }
3787 
3788   /// \brief Get the declaration which triggered the lifetime-extension of this
3789   /// temporary, if any.
getExtendingDecl()3790   const ValueDecl *getExtendingDecl() const {
3791     return State.is<Stmt *>() ? nullptr
3792                               : State.get<ExtraState *>()->ExtendingDecl;
3793   }
3794 
3795   void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber);
3796 
getManglingNumber()3797   unsigned getManglingNumber() const {
3798     return State.is<Stmt *>() ? 0 : State.get<ExtraState *>()->ManglingNumber;
3799   }
3800 
3801   /// \brief Determine whether this materialized temporary is bound to an
3802   /// lvalue reference; otherwise, it's bound to an rvalue reference.
isBoundToLvalueReference()3803   bool isBoundToLvalueReference() const {
3804     return getValueKind() == VK_LValue;
3805   }
3806 
getLocStart()3807   SourceLocation getLocStart() const LLVM_READONLY {
3808     return getTemporary()->getLocStart();
3809   }
getLocEnd()3810   SourceLocation getLocEnd() const LLVM_READONLY {
3811     return getTemporary()->getLocEnd();
3812   }
3813 
classof(const Stmt * T)3814   static bool classof(const Stmt *T) {
3815     return T->getStmtClass() == MaterializeTemporaryExprClass;
3816   }
3817 
3818   // Iterators
children()3819   child_range children() {
3820     if (State.is<Stmt *>())
3821       return child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1);
3822 
3823     auto ES = State.get<ExtraState *>();
3824     return child_range(&ES->Temporary, &ES->Temporary + 1);
3825   }
3826 };
3827 
3828 /// \brief Represents a folding of a pack over an operator.
3829 ///
3830 /// This expression is always dependent and represents a pack expansion of the
3831 /// forms:
3832 ///
3833 ///    ( expr op ... )
3834 ///    ( ... op expr )
3835 ///    ( expr op ... op expr )
3836 class CXXFoldExpr : public Expr {
3837   SourceLocation LParenLoc;
3838   SourceLocation EllipsisLoc;
3839   SourceLocation RParenLoc;
3840   Stmt *SubExprs[2];
3841   BinaryOperatorKind Opcode;
3842 
3843   friend class ASTStmtReader;
3844   friend class ASTStmtWriter;
3845 public:
CXXFoldExpr(QualType T,SourceLocation LParenLoc,Expr * LHS,BinaryOperatorKind Opcode,SourceLocation EllipsisLoc,Expr * RHS,SourceLocation RParenLoc)3846   CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS,
3847               BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS,
3848               SourceLocation RParenLoc)
3849       : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary,
3850              /*Dependent*/ true, true, true,
3851              /*ContainsUnexpandedParameterPack*/ false),
3852         LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
3853         Opcode(Opcode) {
3854     SubExprs[0] = LHS;
3855     SubExprs[1] = RHS;
3856   }
CXXFoldExpr(EmptyShell Empty)3857   CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
3858 
getLHS()3859   Expr *getLHS() const { return static_cast<Expr*>(SubExprs[0]); }
getRHS()3860   Expr *getRHS() const { return static_cast<Expr*>(SubExprs[1]); }
3861 
3862   /// Does this produce a right-associated sequence of operators?
isRightFold()3863   bool isRightFold() const {
3864     return getLHS() && getLHS()->containsUnexpandedParameterPack();
3865   }
3866   /// Does this produce a left-associated sequence of operators?
isLeftFold()3867   bool isLeftFold() const { return !isRightFold(); }
3868   /// Get the pattern, that is, the operand that contains an unexpanded pack.
getPattern()3869   Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
3870   /// Get the operand that doesn't contain a pack, for a binary fold.
getInit()3871   Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
3872 
getEllipsisLoc()3873   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
getOperator()3874   BinaryOperatorKind getOperator() const { return Opcode; }
3875 
getLocStart()3876   SourceLocation getLocStart() const LLVM_READONLY {
3877     return LParenLoc;
3878   }
getLocEnd()3879   SourceLocation getLocEnd() const LLVM_READONLY {
3880     return RParenLoc;
3881   }
3882 
classof(const Stmt * T)3883   static bool classof(const Stmt *T) {
3884     return T->getStmtClass() == CXXFoldExprClass;
3885   }
3886 
3887   // Iterators
children()3888   child_range children() { return child_range(SubExprs, SubExprs + 2); }
3889 };
3890 
3891 }  // end namespace clang
3892 
3893 #endif
3894