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