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