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