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