ExprCXX.h revision 76e3da57b0e8cf72d221f44d54566ef206341668
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};
740
741/// \brief Represents binding an expression to a temporary.
742///
743/// This ensures the destructor is called for the temporary. It should only be
744/// needed for non-POD, non-trivially destructable class types. For example:
745///
746/// \code
747///   struct S {
748///     S() { }  // User defined constructor makes S non-POD.
749///     ~S() { } // User defined destructor makes it non-trivial.
750///   };
751///   void test() {
752///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
753///   }
754/// \endcode
755class CXXBindTemporaryExpr : public Expr {
756  CXXTemporary *Temp;
757
758  Stmt *SubExpr;
759
760  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
761   : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
762          VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
763          SubExpr->isValueDependent(),
764          SubExpr->isInstantiationDependent(),
765          SubExpr->containsUnexpandedParameterPack()),
766     Temp(temp), SubExpr(SubExpr) { }
767
768public:
769  CXXBindTemporaryExpr(EmptyShell Empty)
770    : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
771
772  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
773                                      Expr* SubExpr);
774
775  CXXTemporary *getTemporary() { return Temp; }
776  const CXXTemporary *getTemporary() const { return Temp; }
777  void setTemporary(CXXTemporary *T) { Temp = T; }
778
779  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
780  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
781  void setSubExpr(Expr *E) { SubExpr = E; }
782
783  SourceRange getSourceRange() const {
784    return SubExpr->getSourceRange();
785  }
786
787  // Implement isa/cast/dyncast/etc.
788  static bool classof(const Stmt *T) {
789    return T->getStmtClass() == CXXBindTemporaryExprClass;
790  }
791  static bool classof(const CXXBindTemporaryExpr *) { return true; }
792
793  // Iterators
794  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
795};
796
797/// CXXConstructExpr - Represents a call to a C++ constructor.
798class CXXConstructExpr : public Expr {
799public:
800  enum ConstructionKind {
801    CK_Complete,
802    CK_NonVirtualBase,
803    CK_VirtualBase,
804    CK_Delegating
805  };
806
807private:
808  CXXConstructorDecl *Constructor;
809
810  SourceLocation Loc;
811  SourceRange ParenRange;
812  unsigned NumArgs : 16;
813  bool Elidable : 1;
814  bool HadMultipleCandidates : 1;
815  bool ZeroInitialization : 1;
816  unsigned ConstructKind : 2;
817  Stmt **Args;
818
819protected:
820  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
821                   SourceLocation Loc,
822                   CXXConstructorDecl *d, bool elidable,
823                   Expr **args, unsigned numargs,
824                   bool HadMultipleCandidates,
825                   bool ZeroInitialization = false,
826                   ConstructionKind ConstructKind = CK_Complete,
827                   SourceRange ParenRange = SourceRange());
828
829  /// \brief Construct an empty C++ construction expression.
830  CXXConstructExpr(StmtClass SC, EmptyShell Empty)
831    : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(0),
832      HadMultipleCandidates(false), ZeroInitialization(0),
833      ConstructKind(0), Args(0) { }
834
835public:
836  /// \brief Construct an empty C++ construction expression.
837  explicit CXXConstructExpr(EmptyShell Empty)
838    : Expr(CXXConstructExprClass, Empty), Constructor(0),
839      NumArgs(0), Elidable(0), HadMultipleCandidates(false),
840      ZeroInitialization(0), ConstructKind(0), Args(0) { }
841
842  static CXXConstructExpr *Create(ASTContext &C, QualType T,
843                                  SourceLocation Loc,
844                                  CXXConstructorDecl *D, bool Elidable,
845                                  Expr **Args, unsigned NumArgs,
846                                  bool HadMultipleCandidates,
847                                  bool ZeroInitialization = false,
848                                  ConstructionKind ConstructKind = CK_Complete,
849                                  SourceRange ParenRange = SourceRange());
850
851
852  CXXConstructorDecl* getConstructor() const { return Constructor; }
853  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
854
855  SourceLocation getLocation() const { return Loc; }
856  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
857
858  /// \brief Whether this construction is elidable.
859  bool isElidable() const { return Elidable; }
860  void setElidable(bool E) { Elidable = E; }
861
862  /// \brief Whether the referred constructor was resolved from
863  /// an overloaded set having size greater than 1.
864  bool hadMultipleCandidates() const { return HadMultipleCandidates; }
865  void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
866
867  /// \brief Whether this construction first requires
868  /// zero-initialization before the initializer is called.
869  bool requiresZeroInitialization() const { return ZeroInitialization; }
870  void setRequiresZeroInitialization(bool ZeroInit) {
871    ZeroInitialization = ZeroInit;
872  }
873
874  /// \brief Determines whether this constructor is actually constructing
875  /// a base class (rather than a complete object).
876  ConstructionKind getConstructionKind() const {
877    return (ConstructionKind)ConstructKind;
878  }
879  void setConstructionKind(ConstructionKind CK) {
880    ConstructKind = CK;
881  }
882
883  typedef ExprIterator arg_iterator;
884  typedef ConstExprIterator const_arg_iterator;
885
886  arg_iterator arg_begin() { return Args; }
887  arg_iterator arg_end() { return Args + NumArgs; }
888  const_arg_iterator arg_begin() const { return Args; }
889  const_arg_iterator arg_end() const { return Args + NumArgs; }
890
891  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
892  unsigned getNumArgs() const { return NumArgs; }
893
894  /// getArg - Return the specified argument.
895  Expr *getArg(unsigned Arg) {
896    assert(Arg < NumArgs && "Arg access out of range!");
897    return cast<Expr>(Args[Arg]);
898  }
899  const Expr *getArg(unsigned Arg) const {
900    assert(Arg < NumArgs && "Arg access out of range!");
901    return cast<Expr>(Args[Arg]);
902  }
903
904  /// setArg - Set the specified argument.
905  void setArg(unsigned Arg, Expr *ArgExpr) {
906    assert(Arg < NumArgs && "Arg access out of range!");
907    Args[Arg] = ArgExpr;
908  }
909
910  SourceRange getSourceRange() const;
911  SourceRange getParenRange() const { return ParenRange; }
912
913  static bool classof(const Stmt *T) {
914    return T->getStmtClass() == CXXConstructExprClass ||
915      T->getStmtClass() == CXXTemporaryObjectExprClass;
916  }
917  static bool classof(const CXXConstructExpr *) { return true; }
918
919  // Iterators
920  child_range children() {
921    return child_range(&Args[0], &Args[0]+NumArgs);
922  }
923
924  friend class ASTStmtReader;
925};
926
927/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
928/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
929/// x = int(0.5);
930class CXXFunctionalCastExpr : public ExplicitCastExpr {
931  SourceLocation TyBeginLoc;
932  SourceLocation RParenLoc;
933
934  CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
935                        TypeSourceInfo *writtenTy,
936                        SourceLocation tyBeginLoc, CastKind kind,
937                        Expr *castExpr, unsigned pathSize,
938                        SourceLocation rParenLoc)
939    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
940                       castExpr, pathSize, writtenTy),
941      TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
942
943  explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
944    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
945
946public:
947  static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
948                                       ExprValueKind VK,
949                                       TypeSourceInfo *Written,
950                                       SourceLocation TyBeginLoc,
951                                       CastKind Kind, Expr *Op,
952                                       const CXXCastPath *Path,
953                                       SourceLocation RPLoc);
954  static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
955                                            unsigned PathSize);
956
957  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
958  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
959  SourceLocation getRParenLoc() const { return RParenLoc; }
960  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
961
962  SourceRange getSourceRange() const {
963    return SourceRange(TyBeginLoc, RParenLoc);
964  }
965  static bool classof(const Stmt *T) {
966    return T->getStmtClass() == CXXFunctionalCastExprClass;
967  }
968  static bool classof(const CXXFunctionalCastExpr *) { return true; }
969};
970
971/// @brief Represents a C++ functional cast expression that builds a
972/// temporary object.
973///
974/// This expression type represents a C++ "functional" cast
975/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
976/// constructor to build a temporary object. With N == 1 arguments the
977/// functional cast expression will be represented by CXXFunctionalCastExpr.
978/// Example:
979/// @code
980/// struct X { X(int, float); }
981///
982/// X create_X() {
983///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
984/// };
985/// @endcode
986class CXXTemporaryObjectExpr : public CXXConstructExpr {
987  TypeSourceInfo *Type;
988
989public:
990  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
991                         TypeSourceInfo *Type,
992                         Expr **Args,unsigned NumArgs,
993                         SourceRange parenRange,
994                         bool HadMultipleCandidates,
995                         bool ZeroInitialization = false);
996  explicit CXXTemporaryObjectExpr(EmptyShell Empty)
997    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
998
999  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1000
1001  SourceRange getSourceRange() const;
1002
1003  static bool classof(const Stmt *T) {
1004    return T->getStmtClass() == CXXTemporaryObjectExprClass;
1005  }
1006  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
1007
1008  friend class ASTStmtReader;
1009};
1010
1011/// \brief A C++ lambda expression, which produces a function object
1012/// (of unspecified type) that can be invoked later.
1013///
1014/// Example:
1015/// \code
1016/// void low_pass_filter(std::vector<double> &values, double cutoff) {
1017///   values.erase(std::remove_if(values.begin(), values.end(),
1018//                                [=](double value) { return value > cutoff; });
1019/// }
1020/// \endcode
1021///
1022/// Lambda expressions can capture local variables, either by copying
1023/// the values of those local variables at the time the function
1024/// object is constructed (not when it is called!) or by holding a
1025/// reference to the local variable. These captures can occur either
1026/// implicitly or can be written explicitly between the square
1027/// brackets ([...]) that start the lambda expression.
1028class LambdaExpr : public Expr {
1029  enum {
1030    /// \brief Flag used by the Capture class to indicate that the given
1031    /// capture was implicit.
1032    Capture_Implicit = 0x01,
1033
1034    /// \brief Flag used by the Capture class to indciate that the
1035    /// given capture was by-copy.
1036    Capture_ByCopy = 0x02
1037  };
1038
1039  /// \brief The source range that covers the lambda introducer ([...]).
1040  SourceRange IntroducerRange;
1041
1042  /// \brief The number of captures in this lambda.
1043  unsigned NumCaptures : 16;
1044
1045  /// \brief The number of explicit captures in this lambda.
1046  unsigned NumExplicitCaptures : 13;
1047
1048  /// \brief The default capture kind, which is a value of type
1049  /// LambdaCaptureDefault.
1050  unsigned CaptureDefault : 2;
1051
1052  /// \brief Whether this lambda had an explicit parameter list vs. an
1053  /// implicit (and empty) parameter list.
1054  unsigned ExplicitParams : 1;
1055
1056  /// \brief The location of the closing brace ('}') that completes
1057  /// the lambda.
1058  ///
1059  /// The location of the brace is also available by looking up the
1060  /// function call operator in the lambda class. However, it is
1061  /// stored here to improve the performance of getSourceRange(), and
1062  /// to avoid having to deserialize the function call operator from a
1063  /// module file just to determine the source range.
1064  SourceLocation ClosingBrace;
1065
1066  // Note: The Create method allocates storage after the LambdaExpr
1067  // object, which contains the captures, followed by the capture
1068  // initializers, and finally the body of the lambda. The capture
1069  // initializers and lambda body are placed next to each other so
1070  // that the children() function can visit all of them easily.
1071
1072public:
1073  /// \brief Describes the capture of either a variable or 'this'.
1074  class Capture {
1075    llvm::PointerIntPair<VarDecl *, 2> VarAndBits;
1076    SourceLocation Loc;
1077    SourceLocation EllipsisLoc;
1078
1079    friend class ASTStmtReader;
1080    friend class ASTStmtWriter;
1081
1082  public:
1083    /// \brief Create a new capture.
1084    ///
1085    /// \param Loc The source location associated with this capture.
1086    ///
1087    /// \param Kind The kind of capture (this, byref, bycopy).
1088    ///
1089    /// \param Implicit Whether the capture was implicit or explicit.
1090    ///
1091    /// \param Var The local variable being captured, or null if capturing this.
1092    ///
1093    /// \param EllipsisLoc The location of the ellipsis (...) for a
1094    /// capture that is a pack expansion, or an invalid source
1095    /// location to indicate that this is not a pack expansion.
1096    Capture(SourceLocation Loc, bool Implicit,
1097            LambdaCaptureKind Kind, VarDecl *Var = 0,
1098            SourceLocation EllipsisLoc = SourceLocation());
1099
1100    /// \brief Determine the kind of capture.
1101    LambdaCaptureKind getCaptureKind() const;
1102
1103    /// \brief Determine whether this capture handles the C++ 'this'
1104    /// pointer.
1105    bool capturesThis() const { return VarAndBits.getPointer() == 0; }
1106
1107    /// \brief Determine whether this capture handles a variable.
1108    bool capturesVariable() const { return VarAndBits.getPointer() != 0; }
1109
1110    /// \brief Retrieve the declaration of the local variable being
1111    /// captured.
1112    ///
1113    /// This operation is only valid if this capture does not capture
1114    /// 'this'.
1115    VarDecl *getCapturedVar() const {
1116      assert(!capturesThis() && "No variable available for 'this' capture");
1117      return VarAndBits.getPointer();
1118    }
1119
1120    /// \brief Determine whether this was an implicit capture (not
1121    /// written between the square brackets introducing the lambda).
1122    bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; }
1123
1124    /// \brief Determine whether this was an explicit capture, written
1125    /// between the square brackets introducing the lambda.
1126    bool isExplicit() const { return !isImplicit(); }
1127
1128    /// \brief Retrieve the source location of the capture.
1129    ///
1130    /// For an explicit capture, this returns the location of the
1131    /// explicit capture in the source. For an implicit capture, this
1132    /// returns the location at which the variable or 'this' was first
1133    /// used.
1134    SourceLocation getLocation() const { return Loc; }
1135
1136    /// \brief Determine whether this capture is a pack expansion,
1137    /// which captures a function parameter pack.
1138    bool isPackExpansion() const { return EllipsisLoc.isValid(); }
1139
1140    /// \brief Retrieve the location of the ellipsis for a capture
1141    /// that is a pack expansion.
1142    SourceLocation getEllipsisLoc() const {
1143      assert(isPackExpansion() && "No ellipsis location for a non-expansion");
1144      return EllipsisLoc;
1145    }
1146  };
1147
1148private:
1149  /// \brief Construct a lambda expression.
1150  LambdaExpr(QualType T, SourceRange IntroducerRange,
1151             LambdaCaptureDefault CaptureDefault,
1152             ArrayRef<Capture> Captures,
1153             bool ExplicitParams,
1154             ArrayRef<Expr *> CaptureInits,
1155             SourceLocation ClosingBrace);
1156
1157  Stmt **getStoredStmts() const {
1158    LambdaExpr *This = const_cast<LambdaExpr *>(this);
1159    return reinterpret_cast<Stmt **>(reinterpret_cast<Capture *>(This + 1)
1160                                     + NumCaptures);
1161  }
1162
1163public:
1164  /// \brief Construct a new lambda expression.
1165  static LambdaExpr *Create(ASTContext &C,
1166                            CXXRecordDecl *Class,
1167                            SourceRange IntroducerRange,
1168                            LambdaCaptureDefault CaptureDefault,
1169                            ArrayRef<Capture> Captures,
1170                            bool ExplicitParams,
1171                            ArrayRef<Expr *> CaptureInits,
1172                            SourceLocation ClosingBrace);
1173
1174  /// \brief Determine the default capture kind for this lambda.
1175  LambdaCaptureDefault getCaptureDefault() const {
1176    return static_cast<LambdaCaptureDefault>(CaptureDefault);
1177  }
1178
1179  /// \brief An iterator that walks over the captures of the lambda,
1180  /// both implicit and explicit.
1181  typedef const Capture *capture_iterator;
1182
1183  /// \brief Retrieve an iterator pointing to the first lambda capture.
1184  capture_iterator capture_begin() const {
1185    return reinterpret_cast<const Capture *>(this + 1);
1186  }
1187
1188  /// \brief Retrieve an iterator pointing past the end of the
1189  /// sequence of lambda captures.
1190  capture_iterator capture_end() const {
1191    return capture_begin() + NumCaptures;
1192  }
1193
1194  /// \brief Retrieve an iterator pointing to the first explicit
1195  /// lambda capture.
1196  capture_iterator explicit_capture_begin() const {
1197    return capture_begin();
1198  }
1199
1200  /// \brief Retrieve an iterator pointing past the end of the sequence of
1201  /// explicit lambda captures.
1202  capture_iterator explicit_capture_end() const {
1203    return capture_begin() + NumExplicitCaptures;
1204  }
1205
1206  /// \brief Retrieve an iterator pointing to the first implicit
1207  /// lambda capture.
1208  capture_iterator implicit_capture_begin() const {
1209    return explicit_capture_end();
1210  }
1211
1212  /// \brief Retrieve an iterator pointing past the end of the sequence of
1213  /// implicit lambda captures.
1214  capture_iterator implicit_capture_end() const {
1215    return capture_end();
1216  }
1217
1218  /// \brief Iterator that walks over the capture initialization
1219  /// arguments.
1220  typedef Expr **capture_init_iterator;
1221
1222  /// \brief Retrieve the first initialization argument for this
1223  /// lambda expression (which initializes the first capture field).
1224  capture_init_iterator capture_init_begin() const {
1225    return reinterpret_cast<Expr **>(getStoredStmts() + 1);
1226  }
1227
1228  /// \brief Retrieve the iterator pointing one past the last
1229  /// initialization argument for this lambda expression.
1230  capture_init_iterator capture_init_end() const {
1231    return capture_init_begin() + NumCaptures;
1232  }
1233
1234  /// \brief Retrieve the source range covering the lambda introducer,
1235  /// which contains the explicit capture list surrounded by square
1236  /// brackets ([...]).
1237  SourceRange getIntroducerRange() const { return IntroducerRange; }
1238
1239  /// \brief Retrieve the class that corresponds to the lambda, which
1240  /// stores the captures in its fields and provides the various
1241  /// operations permitted on a lambda (copying, calling).
1242  CXXRecordDecl *getLambdaClass() const;
1243
1244  /// \brief Retrieve the function call operator associated with this
1245  /// lambda expression.
1246  CXXMethodDecl *getCallOperator() const;
1247
1248  /// \brief Retrieve the body of the lambda.
1249  CompoundStmt *getBody() const {
1250    return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
1251  }
1252
1253  /// \brief Determine whether the lambda is mutable, meaning that any
1254  /// captures values can be modified.
1255  bool isMutable() const;
1256
1257  /// \brief Determine whether this lambda has an explicit parameter
1258  /// list vs. an implicit (empty) parameter list.
1259  bool hasExplicitParameters() const { return ExplicitParams; }
1260
1261  static bool classof(const Stmt *T) {
1262    return T->getStmtClass() == LambdaExprClass;
1263  }
1264  static bool classof(const LambdaExpr *) { return true; }
1265
1266  SourceRange getSourceRange() const {
1267    return SourceRange(IntroducerRange.getBegin(), ClosingBrace);
1268  }
1269
1270  child_range children() {
1271    return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1272  }
1273
1274  friend class ASTStmtReader;
1275  friend class ASTStmtWriter;
1276};
1277
1278/// CXXScalarValueInitExpr - [C++ 5.2.3p2]
1279/// Expression "T()" which creates a value-initialized rvalue of type
1280/// T, which is a non-class type.
1281///
1282class CXXScalarValueInitExpr : public Expr {
1283  SourceLocation RParenLoc;
1284  TypeSourceInfo *TypeInfo;
1285
1286  friend class ASTStmtReader;
1287
1288public:
1289  /// \brief Create an explicitly-written scalar-value initialization
1290  /// expression.
1291  CXXScalarValueInitExpr(QualType Type,
1292                         TypeSourceInfo *TypeInfo,
1293                         SourceLocation rParenLoc ) :
1294    Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1295         false, false, Type->isInstantiationDependentType(), false),
1296    RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1297
1298  explicit CXXScalarValueInitExpr(EmptyShell Shell)
1299    : Expr(CXXScalarValueInitExprClass, Shell) { }
1300
1301  TypeSourceInfo *getTypeSourceInfo() const {
1302    return TypeInfo;
1303  }
1304
1305  SourceLocation getRParenLoc() const { return RParenLoc; }
1306
1307  SourceRange getSourceRange() const;
1308
1309  static bool classof(const Stmt *T) {
1310    return T->getStmtClass() == CXXScalarValueInitExprClass;
1311  }
1312  static bool classof(const CXXScalarValueInitExpr *) { return true; }
1313
1314  // Iterators
1315  child_range children() { return child_range(); }
1316};
1317
1318/// CXXNewExpr - A new expression for memory allocation and constructor calls,
1319/// e.g: "new CXXNewExpr(foo)".
1320class CXXNewExpr : public Expr {
1321  // Was the usage ::new, i.e. is the global new to be used?
1322  bool GlobalNew : 1;
1323  // Is there an initializer? If not, built-ins are uninitialized, else they're
1324  // value-initialized.
1325  bool Initializer : 1;
1326  // Do we allocate an array? If so, the first SubExpr is the size expression.
1327  bool Array : 1;
1328  // If this is an array allocation, does the usual deallocation
1329  // function for the allocated type want to know the allocated size?
1330  bool UsualArrayDeleteWantsSize : 1;
1331  // Whether the referred constructor (if any) was resolved from an
1332  // overload set having size greater than 1.
1333  bool HadMultipleCandidates : 1;
1334  // The number of placement new arguments.
1335  unsigned NumPlacementArgs : 13;
1336  // The number of constructor arguments. This may be 1 even for non-class
1337  // types; use the pseudo copy constructor.
1338  unsigned NumConstructorArgs : 14;
1339  // Contains an optional array size expression, any number of optional
1340  // placement arguments, and any number of optional constructor arguments,
1341  // in that order.
1342  Stmt **SubExprs;
1343  // Points to the allocation function used.
1344  FunctionDecl *OperatorNew;
1345  // Points to the deallocation function used in case of error. May be null.
1346  FunctionDecl *OperatorDelete;
1347  // Points to the constructor used. Cannot be null if AllocType is a record;
1348  // it would still point at the default constructor (even an implicit one).
1349  // Must be null for all other types.
1350  CXXConstructorDecl *Constructor;
1351
1352  /// \brief The allocated type-source information, as written in the source.
1353  TypeSourceInfo *AllocatedTypeInfo;
1354
1355  /// \brief If the allocated type was expressed as a parenthesized type-id,
1356  /// the source range covering the parenthesized type-id.
1357  SourceRange TypeIdParens;
1358
1359  SourceLocation StartLoc;
1360  SourceLocation EndLoc;
1361  SourceLocation ConstructorLParen;
1362  SourceLocation ConstructorRParen;
1363
1364  friend class ASTStmtReader;
1365public:
1366  CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1367             Expr **placementArgs, unsigned numPlaceArgs,
1368             SourceRange TypeIdParens,
1369             Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
1370             Expr **constructorArgs, unsigned numConsArgs,
1371             bool HadMultipleCandidates,
1372             FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1373             QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1374             SourceLocation startLoc, SourceLocation endLoc,
1375             SourceLocation constructorLParen,
1376             SourceLocation constructorRParen);
1377  explicit CXXNewExpr(EmptyShell Shell)
1378    : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
1379
1380  void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
1381                         unsigned numConsArgs);
1382
1383  QualType getAllocatedType() const {
1384    assert(getType()->isPointerType());
1385    return getType()->getAs<PointerType>()->getPointeeType();
1386  }
1387
1388  TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1389    return AllocatedTypeInfo;
1390  }
1391
1392  /// \brief True if the allocation result needs to be null-checked.
1393  /// C++0x [expr.new]p13:
1394  ///   If the allocation function returns null, initialization shall
1395  ///   not be done, the deallocation function shall not be called,
1396  ///   and the value of the new-expression shall be null.
1397  /// An allocation function is not allowed to return null unless it
1398  /// has a non-throwing exception-specification.  The '03 rule is
1399  /// identical except that the definition of a non-throwing
1400  /// exception specification is just "is it throw()?".
1401  bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1402
1403  FunctionDecl *getOperatorNew() const { return OperatorNew; }
1404  void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1405  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1406  void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1407  CXXConstructorDecl *getConstructor() const { return Constructor; }
1408  void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
1409
1410  bool isArray() const { return Array; }
1411  Expr *getArraySize() {
1412    return Array ? cast<Expr>(SubExprs[0]) : 0;
1413  }
1414  const Expr *getArraySize() const {
1415    return Array ? cast<Expr>(SubExprs[0]) : 0;
1416  }
1417
1418  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1419  Expr **getPlacementArgs() {
1420    return reinterpret_cast<Expr **>(SubExprs + Array);
1421  }
1422
1423  Expr *getPlacementArg(unsigned i) {
1424    assert(i < NumPlacementArgs && "Index out of range");
1425    return cast<Expr>(SubExprs[Array + i]);
1426  }
1427  const Expr *getPlacementArg(unsigned i) const {
1428    assert(i < NumPlacementArgs && "Index out of range");
1429    return cast<Expr>(SubExprs[Array + i]);
1430  }
1431
1432  bool isParenTypeId() const { return TypeIdParens.isValid(); }
1433  SourceRange getTypeIdParens() const { return TypeIdParens; }
1434
1435  bool isGlobalNew() const { return GlobalNew; }
1436  bool hasInitializer() const { return Initializer; }
1437
1438  /// Answers whether the usual array deallocation function for the
1439  /// allocated type expects the size of the allocation as a
1440  /// parameter.
1441  bool doesUsualArrayDeleteWantSize() const {
1442    return UsualArrayDeleteWantsSize;
1443  }
1444
1445  unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
1446
1447  Expr **getConstructorArgs() {
1448    return reinterpret_cast<Expr **>(SubExprs + Array + NumPlacementArgs);
1449  }
1450
1451  Expr *getConstructorArg(unsigned i) {
1452    assert(i < NumConstructorArgs && "Index out of range");
1453    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1454  }
1455  const Expr *getConstructorArg(unsigned i) const {
1456    assert(i < NumConstructorArgs && "Index out of range");
1457    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1458  }
1459
1460  /// \brief Whether the new expression refers a constructor that was
1461  /// resolved from an overloaded set having size greater than 1.
1462  bool hadMultipleCandidates() const { return HadMultipleCandidates; }
1463  void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
1464
1465  typedef ExprIterator arg_iterator;
1466  typedef ConstExprIterator const_arg_iterator;
1467
1468  arg_iterator placement_arg_begin() {
1469    return SubExprs + Array;
1470  }
1471  arg_iterator placement_arg_end() {
1472    return SubExprs + Array + getNumPlacementArgs();
1473  }
1474  const_arg_iterator placement_arg_begin() const {
1475    return SubExprs + Array;
1476  }
1477  const_arg_iterator placement_arg_end() const {
1478    return SubExprs + Array + getNumPlacementArgs();
1479  }
1480
1481  arg_iterator constructor_arg_begin() {
1482    return SubExprs + Array + getNumPlacementArgs();
1483  }
1484  arg_iterator constructor_arg_end() {
1485    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1486  }
1487  const_arg_iterator constructor_arg_begin() const {
1488    return SubExprs + Array + getNumPlacementArgs();
1489  }
1490  const_arg_iterator constructor_arg_end() const {
1491    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1492  }
1493
1494  typedef Stmt **raw_arg_iterator;
1495  raw_arg_iterator raw_arg_begin() { return SubExprs; }
1496  raw_arg_iterator raw_arg_end() {
1497    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1498  }
1499  const_arg_iterator raw_arg_begin() const { return SubExprs; }
1500  const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
1501
1502  SourceLocation getStartLoc() const { return StartLoc; }
1503  SourceLocation getEndLoc() const { return EndLoc; }
1504
1505  SourceLocation getConstructorLParen() const { return ConstructorLParen; }
1506  SourceLocation getConstructorRParen() const { return ConstructorRParen; }
1507
1508  SourceRange getSourceRange() const {
1509    return SourceRange(StartLoc, EndLoc);
1510  }
1511
1512  static bool classof(const Stmt *T) {
1513    return T->getStmtClass() == CXXNewExprClass;
1514  }
1515  static bool classof(const CXXNewExpr *) { return true; }
1516
1517  // Iterators
1518  child_range children() {
1519    return child_range(&SubExprs[0],
1520                       &SubExprs[0] + Array + getNumPlacementArgs()
1521                         + getNumConstructorArgs());
1522  }
1523};
1524
1525/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1526/// calls, e.g. "delete[] pArray".
1527class CXXDeleteExpr : public Expr {
1528  // Is this a forced global delete, i.e. "::delete"?
1529  bool GlobalDelete : 1;
1530  // Is this the array form of delete, i.e. "delete[]"?
1531  bool ArrayForm : 1;
1532  // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1533  // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1534  // will be true).
1535  bool ArrayFormAsWritten : 1;
1536  // Does the usual deallocation function for the element type require
1537  // a size_t argument?
1538  bool UsualArrayDeleteWantsSize : 1;
1539  // Points to the operator delete overload that is used. Could be a member.
1540  FunctionDecl *OperatorDelete;
1541  // The pointer expression to be deleted.
1542  Stmt *Argument;
1543  // Location of the expression.
1544  SourceLocation Loc;
1545public:
1546  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1547                bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1548                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1549    : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1550           arg->isInstantiationDependent(),
1551           arg->containsUnexpandedParameterPack()),
1552      GlobalDelete(globalDelete),
1553      ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1554      UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
1555      OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { }
1556  explicit CXXDeleteExpr(EmptyShell Shell)
1557    : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1558
1559  bool isGlobalDelete() const { return GlobalDelete; }
1560  bool isArrayForm() const { return ArrayForm; }
1561  bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1562
1563  /// Answers whether the usual array deallocation function for the
1564  /// allocated type expects the size of the allocation as a
1565  /// parameter.  This can be true even if the actual deallocation
1566  /// function that we're using doesn't want a size.
1567  bool doesUsualArrayDeleteWantSize() const {
1568    return UsualArrayDeleteWantsSize;
1569  }
1570
1571  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1572
1573  Expr *getArgument() { return cast<Expr>(Argument); }
1574  const Expr *getArgument() const { return cast<Expr>(Argument); }
1575
1576  /// \brief Retrieve the type being destroyed.  If the type being
1577  /// destroyed is a dependent type which may or may not be a pointer,
1578  /// return an invalid type.
1579  QualType getDestroyedType() const;
1580
1581  SourceRange getSourceRange() const {
1582    return SourceRange(Loc, Argument->getLocEnd());
1583  }
1584
1585  static bool classof(const Stmt *T) {
1586    return T->getStmtClass() == CXXDeleteExprClass;
1587  }
1588  static bool classof(const CXXDeleteExpr *) { return true; }
1589
1590  // Iterators
1591  child_range children() { return child_range(&Argument, &Argument+1); }
1592
1593  friend class ASTStmtReader;
1594};
1595
1596/// \brief Structure used to store the type being destroyed by a
1597/// pseudo-destructor expression.
1598class PseudoDestructorTypeStorage {
1599  /// \brief Either the type source information or the name of the type, if
1600  /// it couldn't be resolved due to type-dependence.
1601  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1602
1603  /// \brief The starting source location of the pseudo-destructor type.
1604  SourceLocation Location;
1605
1606public:
1607  PseudoDestructorTypeStorage() { }
1608
1609  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1610    : Type(II), Location(Loc) { }
1611
1612  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1613
1614  TypeSourceInfo *getTypeSourceInfo() const {
1615    return Type.dyn_cast<TypeSourceInfo *>();
1616  }
1617
1618  IdentifierInfo *getIdentifier() const {
1619    return Type.dyn_cast<IdentifierInfo *>();
1620  }
1621
1622  SourceLocation getLocation() const { return Location; }
1623};
1624
1625/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1626///
1627/// A pseudo-destructor is an expression that looks like a member access to a
1628/// destructor of a scalar type, except that scalar types don't have
1629/// destructors. For example:
1630///
1631/// \code
1632/// typedef int T;
1633/// void f(int *p) {
1634///   p->T::~T();
1635/// }
1636/// \endcode
1637///
1638/// Pseudo-destructors typically occur when instantiating templates such as:
1639///
1640/// \code
1641/// template<typename T>
1642/// void destroy(T* ptr) {
1643///   ptr->T::~T();
1644/// }
1645/// \endcode
1646///
1647/// for scalar types. A pseudo-destructor expression has no run-time semantics
1648/// beyond evaluating the base expression.
1649class CXXPseudoDestructorExpr : public Expr {
1650  /// \brief The base expression (that is being destroyed).
1651  Stmt *Base;
1652
1653  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1654  /// period ('.').
1655  bool IsArrow : 1;
1656
1657  /// \brief The location of the '.' or '->' operator.
1658  SourceLocation OperatorLoc;
1659
1660  /// \brief The nested-name-specifier that follows the operator, if present.
1661  NestedNameSpecifierLoc QualifierLoc;
1662
1663  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1664  /// expression.
1665  TypeSourceInfo *ScopeType;
1666
1667  /// \brief The location of the '::' in a qualified pseudo-destructor
1668  /// expression.
1669  SourceLocation ColonColonLoc;
1670
1671  /// \brief The location of the '~'.
1672  SourceLocation TildeLoc;
1673
1674  /// \brief The type being destroyed, or its name if we were unable to
1675  /// resolve the name.
1676  PseudoDestructorTypeStorage DestroyedType;
1677
1678  friend class ASTStmtReader;
1679
1680public:
1681  CXXPseudoDestructorExpr(ASTContext &Context,
1682                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1683                          NestedNameSpecifierLoc QualifierLoc,
1684                          TypeSourceInfo *ScopeType,
1685                          SourceLocation ColonColonLoc,
1686                          SourceLocation TildeLoc,
1687                          PseudoDestructorTypeStorage DestroyedType);
1688
1689  explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1690    : Expr(CXXPseudoDestructorExprClass, Shell),
1691      Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1692
1693  Expr *getBase() const { return cast<Expr>(Base); }
1694
1695  /// \brief Determines whether this member expression actually had
1696  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1697  /// x->Base::foo.
1698  bool hasQualifier() const { return QualifierLoc; }
1699
1700  /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1701  /// with source-location information.
1702  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1703
1704  /// \brief If the member name was qualified, retrieves the
1705  /// nested-name-specifier that precedes the member name. Otherwise, returns
1706  /// NULL.
1707  NestedNameSpecifier *getQualifier() const {
1708    return QualifierLoc.getNestedNameSpecifier();
1709  }
1710
1711  /// \brief Determine whether this pseudo-destructor expression was written
1712  /// using an '->' (otherwise, it used a '.').
1713  bool isArrow() const { return IsArrow; }
1714
1715  /// \brief Retrieve the location of the '.' or '->' operator.
1716  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1717
1718  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1719  /// expression.
1720  ///
1721  /// Pseudo-destructor expressions can have extra qualification within them
1722  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1723  /// Here, if the object type of the expression is (or may be) a scalar type,
1724  /// \p T may also be a scalar type and, therefore, cannot be part of a
1725  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1726  /// destructor expression.
1727  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1728
1729  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1730  /// expression.
1731  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1732
1733  /// \brief Retrieve the location of the '~'.
1734  SourceLocation getTildeLoc() const { return TildeLoc; }
1735
1736  /// \brief Retrieve the source location information for the type
1737  /// being destroyed.
1738  ///
1739  /// This type-source information is available for non-dependent
1740  /// pseudo-destructor expressions and some dependent pseudo-destructor
1741  /// expressions. Returns NULL if we only have the identifier for a
1742  /// dependent pseudo-destructor expression.
1743  TypeSourceInfo *getDestroyedTypeInfo() const {
1744    return DestroyedType.getTypeSourceInfo();
1745  }
1746
1747  /// \brief In a dependent pseudo-destructor expression for which we do not
1748  /// have full type information on the destroyed type, provides the name
1749  /// of the destroyed type.
1750  IdentifierInfo *getDestroyedTypeIdentifier() const {
1751    return DestroyedType.getIdentifier();
1752  }
1753
1754  /// \brief Retrieve the type being destroyed.
1755  QualType getDestroyedType() const;
1756
1757  /// \brief Retrieve the starting location of the type being destroyed.
1758  SourceLocation getDestroyedTypeLoc() const {
1759    return DestroyedType.getLocation();
1760  }
1761
1762  /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1763  /// expression.
1764  void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1765    DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1766  }
1767
1768  /// \brief Set the destroyed type.
1769  void setDestroyedType(TypeSourceInfo *Info) {
1770    DestroyedType = PseudoDestructorTypeStorage(Info);
1771  }
1772
1773  SourceRange getSourceRange() const;
1774
1775  static bool classof(const Stmt *T) {
1776    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1777  }
1778  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1779
1780  // Iterators
1781  child_range children() { return child_range(&Base, &Base + 1); }
1782};
1783
1784/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1785/// implementation of TR1/C++0x type trait templates.
1786/// Example:
1787/// __is_pod(int) == true
1788/// __is_enum(std::string) == false
1789class UnaryTypeTraitExpr : public Expr {
1790  /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
1791  unsigned UTT : 31;
1792  /// The value of the type trait. Unspecified if dependent.
1793  bool Value : 1;
1794
1795  /// Loc - The location of the type trait keyword.
1796  SourceLocation Loc;
1797
1798  /// RParen - The location of the closing paren.
1799  SourceLocation RParen;
1800
1801  /// The type being queried.
1802  TypeSourceInfo *QueriedType;
1803
1804public:
1805  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
1806                     TypeSourceInfo *queried, bool value,
1807                     SourceLocation rparen, QualType ty)
1808    : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1809           false,  queried->getType()->isDependentType(),
1810           queried->getType()->isInstantiationDependentType(),
1811           queried->getType()->containsUnexpandedParameterPack()),
1812      UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
1813
1814  explicit UnaryTypeTraitExpr(EmptyShell Empty)
1815    : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
1816      QueriedType() { }
1817
1818  SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1819
1820  UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
1821
1822  QualType getQueriedType() const { return QueriedType->getType(); }
1823
1824  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1825
1826  bool getValue() const { return Value; }
1827
1828  static bool classof(const Stmt *T) {
1829    return T->getStmtClass() == UnaryTypeTraitExprClass;
1830  }
1831  static bool classof(const UnaryTypeTraitExpr *) { return true; }
1832
1833  // Iterators
1834  child_range children() { return child_range(); }
1835
1836  friend class ASTStmtReader;
1837};
1838
1839/// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
1840/// implementation of TR1/C++0x type trait templates.
1841/// Example:
1842/// __is_base_of(Base, Derived) == true
1843class BinaryTypeTraitExpr : public Expr {
1844  /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
1845  unsigned BTT : 8;
1846
1847  /// The value of the type trait. Unspecified if dependent.
1848  bool Value : 1;
1849
1850  /// Loc - The location of the type trait keyword.
1851  SourceLocation Loc;
1852
1853  /// RParen - The location of the closing paren.
1854  SourceLocation RParen;
1855
1856  /// The lhs type being queried.
1857  TypeSourceInfo *LhsType;
1858
1859  /// The rhs type being queried.
1860  TypeSourceInfo *RhsType;
1861
1862public:
1863  BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1864                     TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
1865                     bool value, SourceLocation rparen, QualType ty)
1866    : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
1867           lhsType->getType()->isDependentType() ||
1868           rhsType->getType()->isDependentType(),
1869           (lhsType->getType()->isInstantiationDependentType() ||
1870            rhsType->getType()->isInstantiationDependentType()),
1871           (lhsType->getType()->containsUnexpandedParameterPack() ||
1872            rhsType->getType()->containsUnexpandedParameterPack())),
1873      BTT(btt), Value(value), Loc(loc), RParen(rparen),
1874      LhsType(lhsType), RhsType(rhsType) { }
1875
1876
1877  explicit BinaryTypeTraitExpr(EmptyShell Empty)
1878    : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1879      LhsType(), RhsType() { }
1880
1881  SourceRange getSourceRange() const {
1882    return SourceRange(Loc, RParen);
1883  }
1884
1885  BinaryTypeTrait getTrait() const {
1886    return static_cast<BinaryTypeTrait>(BTT);
1887  }
1888
1889  QualType getLhsType() const { return LhsType->getType(); }
1890  QualType getRhsType() const { return RhsType->getType(); }
1891
1892  TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
1893  TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
1894
1895  bool getValue() const { assert(!isTypeDependent()); return Value; }
1896
1897  static bool classof(const Stmt *T) {
1898    return T->getStmtClass() == BinaryTypeTraitExprClass;
1899  }
1900  static bool classof(const BinaryTypeTraitExpr *) { return true; }
1901
1902  // Iterators
1903  child_range children() { return child_range(); }
1904
1905  friend class ASTStmtReader;
1906};
1907
1908/// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the
1909/// implementation of __array_rank and __array_extent.
1910/// Example:
1911/// __array_rank(int[10][20]) == 2
1912/// __array_extent(int, 1)    == 20
1913class ArrayTypeTraitExpr : public Expr {
1914  virtual void anchor();
1915
1916  /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
1917  unsigned ATT : 2;
1918
1919  /// The value of the type trait. Unspecified if dependent.
1920  uint64_t Value;
1921
1922  /// The array dimension being queried, or -1 if not used
1923  Expr *Dimension;
1924
1925  /// Loc - The location of the type trait keyword.
1926  SourceLocation Loc;
1927
1928  /// RParen - The location of the closing paren.
1929  SourceLocation RParen;
1930
1931  /// The type being queried.
1932  TypeSourceInfo *QueriedType;
1933
1934public:
1935  ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
1936                     TypeSourceInfo *queried, uint64_t value,
1937                     Expr *dimension, SourceLocation rparen, QualType ty)
1938    : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1939           false, queried->getType()->isDependentType(),
1940           (queried->getType()->isInstantiationDependentType() ||
1941            (dimension && dimension->isInstantiationDependent())),
1942           queried->getType()->containsUnexpandedParameterPack()),
1943      ATT(att), Value(value), Dimension(dimension),
1944      Loc(loc), RParen(rparen), QueriedType(queried) { }
1945
1946
1947  explicit ArrayTypeTraitExpr(EmptyShell Empty)
1948    : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
1949      QueriedType() { }
1950
1951  virtual ~ArrayTypeTraitExpr() { }
1952
1953  virtual SourceRange getSourceRange() const {
1954    return SourceRange(Loc, RParen);
1955  }
1956
1957  ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
1958
1959  QualType getQueriedType() const { return QueriedType->getType(); }
1960
1961  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1962
1963  uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
1964
1965  Expr *getDimensionExpression() const { return Dimension; }
1966
1967  static bool classof(const Stmt *T) {
1968    return T->getStmtClass() == ArrayTypeTraitExprClass;
1969  }
1970  static bool classof(const ArrayTypeTraitExpr *) { return true; }
1971
1972  // Iterators
1973  child_range children() { return child_range(); }
1974
1975  friend class ASTStmtReader;
1976};
1977
1978/// ExpressionTraitExpr - An expression trait intrinsic
1979/// Example:
1980/// __is_lvalue_expr(std::cout) == true
1981/// __is_lvalue_expr(1) == false
1982class ExpressionTraitExpr : public Expr {
1983  /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned.
1984  unsigned ET : 31;
1985  /// The value of the type trait. Unspecified if dependent.
1986  bool Value : 1;
1987
1988  /// Loc - The location of the type trait keyword.
1989  SourceLocation Loc;
1990
1991  /// RParen - The location of the closing paren.
1992  SourceLocation RParen;
1993
1994  Expr* QueriedExpression;
1995public:
1996  ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
1997                     Expr *queried, bool value,
1998                     SourceLocation rparen, QualType resultType)
1999    : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2000           false, // Not type-dependent
2001           // Value-dependent if the argument is type-dependent.
2002           queried->isTypeDependent(),
2003           queried->isInstantiationDependent(),
2004           queried->containsUnexpandedParameterPack()),
2005      ET(et), Value(value), Loc(loc), RParen(rparen),
2006      QueriedExpression(queried) { }
2007
2008  explicit ExpressionTraitExpr(EmptyShell Empty)
2009    : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2010      QueriedExpression() { }
2011
2012  SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
2013
2014  ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2015
2016  Expr *getQueriedExpression() const { return QueriedExpression; }
2017
2018  bool getValue() const { return Value; }
2019
2020  static bool classof(const Stmt *T) {
2021    return T->getStmtClass() == ExpressionTraitExprClass;
2022  }
2023  static bool classof(const ExpressionTraitExpr *) { return true; }
2024
2025  // Iterators
2026  child_range children() { return child_range(); }
2027
2028  friend class ASTStmtReader;
2029};
2030
2031
2032/// \brief A reference to an overloaded function set, either an
2033/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
2034class OverloadExpr : public Expr {
2035  /// The results.  These are undesugared, which is to say, they may
2036  /// include UsingShadowDecls.  Access is relative to the naming
2037  /// class.
2038  // FIXME: Allocate this data after the OverloadExpr subclass.
2039  DeclAccessPair *Results;
2040  unsigned NumResults;
2041
2042  /// The common name of these declarations.
2043  DeclarationNameInfo NameInfo;
2044
2045  /// \brief The nested-name-specifier that qualifies the name, if any.
2046  NestedNameSpecifierLoc QualifierLoc;
2047
2048protected:
2049  /// \brief Whether the name includes info for explicit template
2050  /// keyword and arguments.
2051  bool HasTemplateKWAndArgsInfo;
2052
2053  /// \brief Return the optional template keyword and arguments info.
2054  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2055
2056  /// \brief Return the optional template keyword and arguments info.
2057  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2058    return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2059  }
2060
2061  OverloadExpr(StmtClass K, ASTContext &C,
2062               NestedNameSpecifierLoc QualifierLoc,
2063               SourceLocation TemplateKWLoc,
2064               const DeclarationNameInfo &NameInfo,
2065               const TemplateArgumentListInfo *TemplateArgs,
2066               UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2067               bool KnownDependent,
2068               bool KnownInstantiationDependent,
2069               bool KnownContainsUnexpandedParameterPack);
2070
2071  OverloadExpr(StmtClass K, EmptyShell Empty)
2072    : Expr(K, Empty), Results(0), NumResults(0),
2073      QualifierLoc(), HasTemplateKWAndArgsInfo(false) { }
2074
2075  void initializeResults(ASTContext &C,
2076                         UnresolvedSetIterator Begin,
2077                         UnresolvedSetIterator End);
2078
2079public:
2080  struct FindResult {
2081    OverloadExpr *Expression;
2082    bool IsAddressOfOperand;
2083    bool HasFormOfMemberPointer;
2084  };
2085
2086  /// Finds the overloaded expression in the given expression of
2087  /// OverloadTy.
2088  ///
2089  /// \return the expression (which must be there) and true if it has
2090  /// the particular form of a member pointer expression
2091  static FindResult find(Expr *E) {
2092    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2093
2094    FindResult Result;
2095
2096    E = E->IgnoreParens();
2097    if (isa<UnaryOperator>(E)) {
2098      assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2099      E = cast<UnaryOperator>(E)->getSubExpr();
2100      OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2101
2102      Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2103      Result.IsAddressOfOperand = true;
2104      Result.Expression = Ovl;
2105    } else {
2106      Result.HasFormOfMemberPointer = false;
2107      Result.IsAddressOfOperand = false;
2108      Result.Expression = cast<OverloadExpr>(E);
2109    }
2110
2111    return Result;
2112  }
2113
2114  /// Gets the naming class of this lookup, if any.
2115  CXXRecordDecl *getNamingClass() const;
2116
2117  typedef UnresolvedSetImpl::iterator decls_iterator;
2118  decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2119  decls_iterator decls_end() const {
2120    return UnresolvedSetIterator(Results + NumResults);
2121  }
2122
2123  /// Gets the number of declarations in the unresolved set.
2124  unsigned getNumDecls() const { return NumResults; }
2125
2126  /// Gets the full name info.
2127  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2128
2129  /// Gets the name looked up.
2130  DeclarationName getName() const { return NameInfo.getName(); }
2131
2132  /// Gets the location of the name.
2133  SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2134
2135  /// Fetches the nested-name qualifier, if one was given.
2136  NestedNameSpecifier *getQualifier() const {
2137    return QualifierLoc.getNestedNameSpecifier();
2138  }
2139
2140  /// Fetches the nested-name qualifier with source-location information, if
2141  /// one was given.
2142  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2143
2144  /// \brief Retrieve the location of the template keyword preceding
2145  /// this name, if any.
2146  SourceLocation getTemplateKeywordLoc() const {
2147    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2148    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2149  }
2150
2151  /// \brief Retrieve the location of the left angle bracket starting the
2152  /// explicit template argument list following the name, if any.
2153  SourceLocation getLAngleLoc() const {
2154    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2155    return getTemplateKWAndArgsInfo()->LAngleLoc;
2156  }
2157
2158  /// \brief Retrieve the location of the right angle bracket ending the
2159  /// explicit template argument list following the name, if any.
2160  SourceLocation getRAngleLoc() const {
2161    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2162    return getTemplateKWAndArgsInfo()->RAngleLoc;
2163  }
2164
2165  /// Determines whether the name was preceded by the template keyword.
2166  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2167
2168  /// Determines whether this expression had explicit template arguments.
2169  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2170
2171  // Note that, inconsistently with the explicit-template-argument AST
2172  // nodes, users are *forbidden* from calling these methods on objects
2173  // without explicit template arguments.
2174
2175  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2176    assert(hasExplicitTemplateArgs());
2177    return *getTemplateKWAndArgsInfo();
2178  }
2179
2180  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2181    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
2182  }
2183
2184  TemplateArgumentLoc const *getTemplateArgs() const {
2185    return getExplicitTemplateArgs().getTemplateArgs();
2186  }
2187
2188  unsigned getNumTemplateArgs() const {
2189    return getExplicitTemplateArgs().NumTemplateArgs;
2190  }
2191
2192  /// Copies the template arguments into the given structure.
2193  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2194    getExplicitTemplateArgs().copyInto(List);
2195  }
2196
2197  /// \brief Retrieves the optional explicit template arguments.
2198  /// This points to the same data as getExplicitTemplateArgs(), but
2199  /// returns null if there are no explicit template arguments.
2200  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2201    if (!hasExplicitTemplateArgs()) return 0;
2202    return &getExplicitTemplateArgs();
2203  }
2204
2205  static bool classof(const Stmt *T) {
2206    return T->getStmtClass() == UnresolvedLookupExprClass ||
2207           T->getStmtClass() == UnresolvedMemberExprClass;
2208  }
2209  static bool classof(const OverloadExpr *) { return true; }
2210
2211  friend class ASTStmtReader;
2212  friend class ASTStmtWriter;
2213};
2214
2215/// \brief A reference to a name which we were able to look up during
2216/// parsing but could not resolve to a specific declaration.  This
2217/// arises in several ways:
2218///   * we might be waiting for argument-dependent lookup
2219///   * the name might resolve to an overloaded function
2220/// and eventually:
2221///   * the lookup might have included a function template
2222/// These never include UnresolvedUsingValueDecls, which are always
2223/// class members and therefore appear only in
2224/// UnresolvedMemberLookupExprs.
2225class UnresolvedLookupExpr : public OverloadExpr {
2226  /// True if these lookup results should be extended by
2227  /// argument-dependent lookup if this is the operand of a function
2228  /// call.
2229  bool RequiresADL;
2230
2231  /// True if namespace ::std should be considered an associated namespace
2232  /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1.
2233  bool StdIsAssociatedNamespace;
2234
2235  /// True if these lookup results are overloaded.  This is pretty
2236  /// trivially rederivable if we urgently need to kill this field.
2237  bool Overloaded;
2238
2239  /// The naming class (C++ [class.access.base]p5) of the lookup, if
2240  /// any.  This can generally be recalculated from the context chain,
2241  /// but that can be fairly expensive for unqualified lookups.  If we
2242  /// want to improve memory use here, this could go in a union
2243  /// against the qualified-lookup bits.
2244  CXXRecordDecl *NamingClass;
2245
2246  UnresolvedLookupExpr(ASTContext &C,
2247                       CXXRecordDecl *NamingClass,
2248                       NestedNameSpecifierLoc QualifierLoc,
2249                       SourceLocation TemplateKWLoc,
2250                       const DeclarationNameInfo &NameInfo,
2251                       bool RequiresADL, bool Overloaded,
2252                       const TemplateArgumentListInfo *TemplateArgs,
2253                       UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2254                       bool StdIsAssociatedNamespace)
2255    : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2256                   NameInfo, TemplateArgs, Begin, End, false, false, false),
2257      RequiresADL(RequiresADL),
2258      StdIsAssociatedNamespace(StdIsAssociatedNamespace),
2259      Overloaded(Overloaded), NamingClass(NamingClass)
2260  {}
2261
2262  UnresolvedLookupExpr(EmptyShell Empty)
2263    : OverloadExpr(UnresolvedLookupExprClass, Empty),
2264      RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false),
2265      NamingClass(0)
2266  {}
2267
2268  friend class ASTStmtReader;
2269
2270public:
2271  static UnresolvedLookupExpr *Create(ASTContext &C,
2272                                      CXXRecordDecl *NamingClass,
2273                                      NestedNameSpecifierLoc QualifierLoc,
2274                                      const DeclarationNameInfo &NameInfo,
2275                                      bool ADL, bool Overloaded,
2276                                      UnresolvedSetIterator Begin,
2277                                      UnresolvedSetIterator End,
2278                                      bool StdIsAssociatedNamespace = false) {
2279    assert((ADL || !StdIsAssociatedNamespace) &&
2280           "std considered associated namespace when not performing ADL");
2281    return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2282                                       SourceLocation(), NameInfo,
2283                                       ADL, Overloaded, 0, Begin, End,
2284                                       StdIsAssociatedNamespace);
2285  }
2286
2287  static UnresolvedLookupExpr *Create(ASTContext &C,
2288                                      CXXRecordDecl *NamingClass,
2289                                      NestedNameSpecifierLoc QualifierLoc,
2290                                      SourceLocation TemplateKWLoc,
2291                                      const DeclarationNameInfo &NameInfo,
2292                                      bool ADL,
2293                                      const TemplateArgumentListInfo *Args,
2294                                      UnresolvedSetIterator Begin,
2295                                      UnresolvedSetIterator End);
2296
2297  static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
2298                                           bool HasTemplateKWAndArgsInfo,
2299                                           unsigned NumTemplateArgs);
2300
2301  /// True if this declaration should be extended by
2302  /// argument-dependent lookup.
2303  bool requiresADL() const { return RequiresADL; }
2304
2305  /// True if namespace ::std should be artificially added to the set of
2306  /// associated namespaecs for argument-dependent lookup purposes.
2307  bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; }
2308
2309  /// True if this lookup is overloaded.
2310  bool isOverloaded() const { return Overloaded; }
2311
2312  /// Gets the 'naming class' (in the sense of C++0x
2313  /// [class.access.base]p5) of the lookup.  This is the scope
2314  /// that was looked in to find these results.
2315  CXXRecordDecl *getNamingClass() const { return NamingClass; }
2316
2317  SourceRange getSourceRange() const {
2318    SourceRange Range(getNameInfo().getSourceRange());
2319    if (getQualifierLoc())
2320      Range.setBegin(getQualifierLoc().getBeginLoc());
2321    if (hasExplicitTemplateArgs())
2322      Range.setEnd(getRAngleLoc());
2323    return Range;
2324  }
2325
2326  child_range children() { return child_range(); }
2327
2328  static bool classof(const Stmt *T) {
2329    return T->getStmtClass() == UnresolvedLookupExprClass;
2330  }
2331  static bool classof(const UnresolvedLookupExpr *) { return true; }
2332};
2333
2334/// \brief A qualified reference to a name whose declaration cannot
2335/// yet be resolved.
2336///
2337/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2338/// it expresses a reference to a declaration such as
2339/// X<T>::value. The difference, however, is that an
2340/// DependentScopeDeclRefExpr node is used only within C++ templates when
2341/// the qualification (e.g., X<T>::) refers to a dependent type. In
2342/// this case, X<T>::value cannot resolve to a declaration because the
2343/// declaration will differ from on instantiation of X<T> to the
2344/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2345/// qualifier (X<T>::) and the name of the entity being referenced
2346/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2347/// declaration can be found.
2348class DependentScopeDeclRefExpr : public Expr {
2349  /// \brief The nested-name-specifier that qualifies this unresolved
2350  /// declaration name.
2351  NestedNameSpecifierLoc QualifierLoc;
2352
2353  /// The name of the entity we will be referencing.
2354  DeclarationNameInfo NameInfo;
2355
2356  /// \brief Whether the name includes info for explicit template
2357  /// keyword and arguments.
2358  bool HasTemplateKWAndArgsInfo;
2359
2360  /// \brief Return the optional template keyword and arguments info.
2361  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2362    if (!HasTemplateKWAndArgsInfo) return 0;
2363    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2364  }
2365  /// \brief Return the optional template keyword and arguments info.
2366  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2367    return const_cast<DependentScopeDeclRefExpr*>(this)
2368      ->getTemplateKWAndArgsInfo();
2369  }
2370
2371  DependentScopeDeclRefExpr(QualType T,
2372                            NestedNameSpecifierLoc QualifierLoc,
2373                            SourceLocation TemplateKWLoc,
2374                            const DeclarationNameInfo &NameInfo,
2375                            const TemplateArgumentListInfo *Args);
2376
2377public:
2378  static DependentScopeDeclRefExpr *Create(ASTContext &C,
2379                                           NestedNameSpecifierLoc QualifierLoc,
2380                                           SourceLocation TemplateKWLoc,
2381                                           const DeclarationNameInfo &NameInfo,
2382                              const TemplateArgumentListInfo *TemplateArgs);
2383
2384  static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2385                                                bool HasTemplateKWAndArgsInfo,
2386                                                unsigned NumTemplateArgs);
2387
2388  /// \brief Retrieve the name that this expression refers to.
2389  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2390
2391  /// \brief Retrieve the name that this expression refers to.
2392  DeclarationName getDeclName() const { return NameInfo.getName(); }
2393
2394  /// \brief Retrieve the location of the name within the expression.
2395  SourceLocation getLocation() const { return NameInfo.getLoc(); }
2396
2397  /// \brief Retrieve the nested-name-specifier that qualifies the
2398  /// name, with source location information.
2399  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2400
2401
2402  /// \brief Retrieve the nested-name-specifier that qualifies this
2403  /// declaration.
2404  NestedNameSpecifier *getQualifier() const {
2405    return QualifierLoc.getNestedNameSpecifier();
2406  }
2407
2408  /// \brief Retrieve the location of the template keyword preceding
2409  /// this name, if any.
2410  SourceLocation getTemplateKeywordLoc() const {
2411    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2412    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2413  }
2414
2415  /// \brief Retrieve the location of the left angle bracket starting the
2416  /// explicit template argument list following the name, if any.
2417  SourceLocation getLAngleLoc() const {
2418    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2419    return getTemplateKWAndArgsInfo()->LAngleLoc;
2420  }
2421
2422  /// \brief Retrieve the location of the right angle bracket ending the
2423  /// explicit template argument list following the name, if any.
2424  SourceLocation getRAngleLoc() const {
2425    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2426    return getTemplateKWAndArgsInfo()->RAngleLoc;
2427  }
2428
2429  /// Determines whether the name was preceded by the template keyword.
2430  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2431
2432  /// Determines whether this lookup had explicit template arguments.
2433  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2434
2435  // Note that, inconsistently with the explicit-template-argument AST
2436  // nodes, users are *forbidden* from calling these methods on objects
2437  // without explicit template arguments.
2438
2439  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2440    assert(hasExplicitTemplateArgs());
2441    return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
2442  }
2443
2444  /// Gets a reference to the explicit template argument list.
2445  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2446    assert(hasExplicitTemplateArgs());
2447    return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2448  }
2449
2450  /// \brief Retrieves the optional explicit template arguments.
2451  /// This points to the same data as getExplicitTemplateArgs(), but
2452  /// returns null if there are no explicit template arguments.
2453  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2454    if (!hasExplicitTemplateArgs()) return 0;
2455    return &getExplicitTemplateArgs();
2456  }
2457
2458  /// \brief Copies the template arguments (if present) into the given
2459  /// structure.
2460  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2461    getExplicitTemplateArgs().copyInto(List);
2462  }
2463
2464  TemplateArgumentLoc const *getTemplateArgs() const {
2465    return getExplicitTemplateArgs().getTemplateArgs();
2466  }
2467
2468  unsigned getNumTemplateArgs() const {
2469    return getExplicitTemplateArgs().NumTemplateArgs;
2470  }
2471
2472  SourceRange getSourceRange() const {
2473    SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
2474    if (hasExplicitTemplateArgs())
2475      Range.setEnd(getRAngleLoc());
2476    return Range;
2477  }
2478
2479  static bool classof(const Stmt *T) {
2480    return T->getStmtClass() == DependentScopeDeclRefExprClass;
2481  }
2482  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
2483
2484  child_range children() { return child_range(); }
2485
2486  friend class ASTStmtReader;
2487  friend class ASTStmtWriter;
2488};
2489
2490/// Represents an expression --- generally a full-expression --- which
2491/// introduces cleanups to be run at the end of the sub-expression's
2492/// evaluation.  The most common source of expression-introduced
2493/// cleanups is temporary objects in C++, but several other kinds of
2494/// expressions can create cleanups, including basically every
2495/// call in ARC that returns an Objective-C pointer.
2496///
2497/// This expression also tracks whether the sub-expression contains a
2498/// potentially-evaluated block literal.  The lifetime of a block
2499/// literal is the extent of the enclosing scope.
2500class ExprWithCleanups : public Expr {
2501public:
2502  /// The type of objects that are kept in the cleanup.
2503  /// It's useful to remember the set of blocks;  we could also
2504  /// remember the set of temporaries, but there's currently
2505  /// no need.
2506  typedef BlockDecl *CleanupObject;
2507
2508private:
2509  Stmt *SubExpr;
2510
2511  ExprWithCleanups(EmptyShell, unsigned NumObjects);
2512  ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
2513
2514  CleanupObject *getObjectsBuffer() {
2515    return reinterpret_cast<CleanupObject*>(this + 1);
2516  }
2517  const CleanupObject *getObjectsBuffer() const {
2518    return reinterpret_cast<const CleanupObject*>(this + 1);
2519  }
2520  friend class ASTStmtReader;
2521
2522public:
2523  static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty,
2524                                  unsigned numObjects);
2525
2526  static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr,
2527                                  ArrayRef<CleanupObject> objects);
2528
2529  ArrayRef<CleanupObject> getObjects() const {
2530    return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects());
2531  }
2532
2533  unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
2534
2535  CleanupObject getObject(unsigned i) const {
2536    assert(i < getNumObjects() && "Index out of range");
2537    return getObjects()[i];
2538  }
2539
2540  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2541  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2542
2543  /// setSubExpr - As with any mutator of the AST, be very careful
2544  /// when modifying an existing AST to preserve its invariants.
2545  void setSubExpr(Expr *E) { SubExpr = E; }
2546
2547  SourceRange getSourceRange() const {
2548    return SubExpr->getSourceRange();
2549  }
2550
2551  // Implement isa/cast/dyncast/etc.
2552  static bool classof(const Stmt *T) {
2553    return T->getStmtClass() == ExprWithCleanupsClass;
2554  }
2555  static bool classof(const ExprWithCleanups *) { return true; }
2556
2557  // Iterators
2558  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2559};
2560
2561/// \brief Describes an explicit type conversion that uses functional
2562/// notion but could not be resolved because one or more arguments are
2563/// type-dependent.
2564///
2565/// The explicit type conversions expressed by
2566/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2567/// where \c T is some type and \c a1, a2, ..., aN are values, and
2568/// either \C T is a dependent type or one or more of the \c a's is
2569/// type-dependent. For example, this would occur in a template such
2570/// as:
2571///
2572/// \code
2573///   template<typename T, typename A1>
2574///   inline T make_a(const A1& a1) {
2575///     return T(a1);
2576///   }
2577/// \endcode
2578///
2579/// When the returned expression is instantiated, it may resolve to a
2580/// constructor call, conversion function call, or some kind of type
2581/// conversion.
2582class CXXUnresolvedConstructExpr : public Expr {
2583  /// \brief The type being constructed.
2584  TypeSourceInfo *Type;
2585
2586  /// \brief The location of the left parentheses ('(').
2587  SourceLocation LParenLoc;
2588
2589  /// \brief The location of the right parentheses (')').
2590  SourceLocation RParenLoc;
2591
2592  /// \brief The number of arguments used to construct the type.
2593  unsigned NumArgs;
2594
2595  CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2596                             SourceLocation LParenLoc,
2597                             Expr **Args,
2598                             unsigned NumArgs,
2599                             SourceLocation RParenLoc);
2600
2601  CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2602    : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2603
2604  friend class ASTStmtReader;
2605
2606public:
2607  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2608                                            TypeSourceInfo *Type,
2609                                            SourceLocation LParenLoc,
2610                                            Expr **Args,
2611                                            unsigned NumArgs,
2612                                            SourceLocation RParenLoc);
2613
2614  static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
2615                                                 unsigned NumArgs);
2616
2617  /// \brief Retrieve the type that is being constructed, as specified
2618  /// in the source code.
2619  QualType getTypeAsWritten() const { return Type->getType(); }
2620
2621  /// \brief Retrieve the type source information for the type being
2622  /// constructed.
2623  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2624
2625  /// \brief Retrieve the location of the left parentheses ('(') that
2626  /// precedes the argument list.
2627  SourceLocation getLParenLoc() const { return LParenLoc; }
2628  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2629
2630  /// \brief Retrieve the location of the right parentheses (')') that
2631  /// follows the argument list.
2632  SourceLocation getRParenLoc() const { return RParenLoc; }
2633  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2634
2635  /// \brief Retrieve the number of arguments.
2636  unsigned arg_size() const { return NumArgs; }
2637
2638  typedef Expr** arg_iterator;
2639  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2640  arg_iterator arg_end() { return arg_begin() + NumArgs; }
2641
2642  typedef const Expr* const * const_arg_iterator;
2643  const_arg_iterator arg_begin() const {
2644    return reinterpret_cast<const Expr* const *>(this + 1);
2645  }
2646  const_arg_iterator arg_end() const {
2647    return arg_begin() + NumArgs;
2648  }
2649
2650  Expr *getArg(unsigned I) {
2651    assert(I < NumArgs && "Argument index out-of-range");
2652    return *(arg_begin() + I);
2653  }
2654
2655  const Expr *getArg(unsigned I) const {
2656    assert(I < NumArgs && "Argument index out-of-range");
2657    return *(arg_begin() + I);
2658  }
2659
2660  void setArg(unsigned I, Expr *E) {
2661    assert(I < NumArgs && "Argument index out-of-range");
2662    *(arg_begin() + I) = E;
2663  }
2664
2665  SourceRange getSourceRange() const;
2666
2667  static bool classof(const Stmt *T) {
2668    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2669  }
2670  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2671
2672  // Iterators
2673  child_range children() {
2674    Stmt **begin = reinterpret_cast<Stmt**>(this+1);
2675    return child_range(begin, begin + NumArgs);
2676  }
2677};
2678
2679/// \brief Represents a C++ member access expression where the actual
2680/// member referenced could not be resolved because the base
2681/// expression or the member name was dependent.
2682///
2683/// Like UnresolvedMemberExprs, these can be either implicit or
2684/// explicit accesses.  It is only possible to get one of these with
2685/// an implicit access if a qualifier is provided.
2686class CXXDependentScopeMemberExpr : public Expr {
2687  /// \brief The expression for the base pointer or class reference,
2688  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
2689  Stmt *Base;
2690
2691  /// \brief The type of the base expression.  Never null, even for
2692  /// implicit accesses.
2693  QualType BaseType;
2694
2695  /// \brief Whether this member expression used the '->' operator or
2696  /// the '.' operator.
2697  bool IsArrow : 1;
2698
2699  /// \brief Whether this member expression has info for explicit template
2700  /// keyword and arguments.
2701  bool HasTemplateKWAndArgsInfo : 1;
2702
2703  /// \brief The location of the '->' or '.' operator.
2704  SourceLocation OperatorLoc;
2705
2706  /// \brief The nested-name-specifier that precedes the member name, if any.
2707  NestedNameSpecifierLoc QualifierLoc;
2708
2709  /// \brief In a qualified member access expression such as t->Base::f, this
2710  /// member stores the resolves of name lookup in the context of the member
2711  /// access expression, to be used at instantiation time.
2712  ///
2713  /// FIXME: This member, along with the QualifierLoc, could
2714  /// be stuck into a structure that is optionally allocated at the end of
2715  /// the CXXDependentScopeMemberExpr, to save space in the common case.
2716  NamedDecl *FirstQualifierFoundInScope;
2717
2718  /// \brief The member to which this member expression refers, which
2719  /// can be name, overloaded operator, or destructor.
2720  /// FIXME: could also be a template-id
2721  DeclarationNameInfo MemberNameInfo;
2722
2723  /// \brief Return the optional template keyword and arguments info.
2724  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2725    if (!HasTemplateKWAndArgsInfo) return 0;
2726    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2727  }
2728  /// \brief Return the optional template keyword and arguments info.
2729  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2730    return const_cast<CXXDependentScopeMemberExpr*>(this)
2731      ->getTemplateKWAndArgsInfo();
2732  }
2733
2734  CXXDependentScopeMemberExpr(ASTContext &C,
2735                          Expr *Base, QualType BaseType, bool IsArrow,
2736                          SourceLocation OperatorLoc,
2737                          NestedNameSpecifierLoc QualifierLoc,
2738                          SourceLocation TemplateKWLoc,
2739                          NamedDecl *FirstQualifierFoundInScope,
2740                          DeclarationNameInfo MemberNameInfo,
2741                          const TemplateArgumentListInfo *TemplateArgs);
2742
2743public:
2744  CXXDependentScopeMemberExpr(ASTContext &C,
2745                              Expr *Base, QualType BaseType,
2746                              bool IsArrow,
2747                              SourceLocation OperatorLoc,
2748                              NestedNameSpecifierLoc QualifierLoc,
2749                              NamedDecl *FirstQualifierFoundInScope,
2750                              DeclarationNameInfo MemberNameInfo);
2751
2752  static CXXDependentScopeMemberExpr *
2753  Create(ASTContext &C,
2754         Expr *Base, QualType BaseType, bool IsArrow,
2755         SourceLocation OperatorLoc,
2756         NestedNameSpecifierLoc QualifierLoc,
2757         SourceLocation TemplateKWLoc,
2758         NamedDecl *FirstQualifierFoundInScope,
2759         DeclarationNameInfo MemberNameInfo,
2760         const TemplateArgumentListInfo *TemplateArgs);
2761
2762  static CXXDependentScopeMemberExpr *
2763  CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
2764              unsigned NumTemplateArgs);
2765
2766  /// \brief True if this is an implicit access, i.e. one in which the
2767  /// member being accessed was not written in the source.  The source
2768  /// location of the operator is invalid in this case.
2769  bool isImplicitAccess() const;
2770
2771  /// \brief Retrieve the base object of this member expressions,
2772  /// e.g., the \c x in \c x.m.
2773  Expr *getBase() const {
2774    assert(!isImplicitAccess());
2775    return cast<Expr>(Base);
2776  }
2777
2778  QualType getBaseType() const { return BaseType; }
2779
2780  /// \brief Determine whether this member expression used the '->'
2781  /// operator; otherwise, it used the '.' operator.
2782  bool isArrow() const { return IsArrow; }
2783
2784  /// \brief Retrieve the location of the '->' or '.' operator.
2785  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2786
2787  /// \brief Retrieve the nested-name-specifier that qualifies the member
2788  /// name.
2789  NestedNameSpecifier *getQualifier() const {
2790    return QualifierLoc.getNestedNameSpecifier();
2791  }
2792
2793  /// \brief Retrieve the nested-name-specifier that qualifies the member
2794  /// name, with source location information.
2795  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2796
2797
2798  /// \brief Retrieve the first part of the nested-name-specifier that was
2799  /// found in the scope of the member access expression when the member access
2800  /// was initially parsed.
2801  ///
2802  /// This function only returns a useful result when member access expression
2803  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2804  /// returned by this function describes what was found by unqualified name
2805  /// lookup for the identifier "Base" within the scope of the member access
2806  /// expression itself. At template instantiation time, this information is
2807  /// combined with the results of name lookup into the type of the object
2808  /// expression itself (the class type of x).
2809  NamedDecl *getFirstQualifierFoundInScope() const {
2810    return FirstQualifierFoundInScope;
2811  }
2812
2813  /// \brief Retrieve the name of the member that this expression
2814  /// refers to.
2815  const DeclarationNameInfo &getMemberNameInfo() const {
2816    return MemberNameInfo;
2817  }
2818
2819  /// \brief Retrieve the name of the member that this expression
2820  /// refers to.
2821  DeclarationName getMember() const { return MemberNameInfo.getName(); }
2822
2823  // \brief Retrieve the location of the name of the member that this
2824  // expression refers to.
2825  SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
2826
2827  /// \brief Retrieve the location of the template keyword preceding the
2828  /// member name, if any.
2829  SourceLocation getTemplateKeywordLoc() const {
2830    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2831    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2832  }
2833
2834  /// \brief Retrieve the location of the left angle bracket starting the
2835  /// explicit template argument list following the member name, if any.
2836  SourceLocation getLAngleLoc() const {
2837    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2838    return getTemplateKWAndArgsInfo()->LAngleLoc;
2839  }
2840
2841  /// \brief Retrieve the location of the right angle bracket ending the
2842  /// explicit template argument list following the member name, if any.
2843  SourceLocation getRAngleLoc() const {
2844    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2845    return getTemplateKWAndArgsInfo()->RAngleLoc;
2846  }
2847
2848  /// Determines whether the member name was preceded by the template keyword.
2849  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2850
2851  /// \brief Determines whether this member expression actually had a C++
2852  /// template argument list explicitly specified, e.g., x.f<int>.
2853  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2854
2855  /// \brief Retrieve the explicit template argument list that followed the
2856  /// member template name, if any.
2857  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2858    assert(hasExplicitTemplateArgs());
2859    return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
2860  }
2861
2862  /// \brief Retrieve the explicit template argument list that followed the
2863  /// member template name, if any.
2864  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2865    return const_cast<CXXDependentScopeMemberExpr *>(this)
2866             ->getExplicitTemplateArgs();
2867  }
2868
2869  /// \brief Retrieves the optional explicit template arguments.
2870  /// This points to the same data as getExplicitTemplateArgs(), but
2871  /// returns null if there are no explicit template arguments.
2872  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2873    if (!hasExplicitTemplateArgs()) return 0;
2874    return &getExplicitTemplateArgs();
2875  }
2876
2877  /// \brief Copies the template arguments (if present) into the given
2878  /// structure.
2879  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2880    getExplicitTemplateArgs().copyInto(List);
2881  }
2882
2883  /// \brief Initializes the template arguments using the given structure.
2884  void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2885    getExplicitTemplateArgs().initializeFrom(List);
2886  }
2887
2888  /// \brief Retrieve the template arguments provided as part of this
2889  /// template-id.
2890  const TemplateArgumentLoc *getTemplateArgs() const {
2891    return getExplicitTemplateArgs().getTemplateArgs();
2892  }
2893
2894  /// \brief Retrieve the number of template arguments provided as part of this
2895  /// template-id.
2896  unsigned getNumTemplateArgs() const {
2897    return getExplicitTemplateArgs().NumTemplateArgs;
2898  }
2899
2900  SourceRange getSourceRange() const {
2901    SourceRange Range;
2902    if (!isImplicitAccess())
2903      Range.setBegin(Base->getSourceRange().getBegin());
2904    else if (getQualifier())
2905      Range.setBegin(getQualifierLoc().getBeginLoc());
2906    else
2907      Range.setBegin(MemberNameInfo.getBeginLoc());
2908
2909    if (hasExplicitTemplateArgs())
2910      Range.setEnd(getRAngleLoc());
2911    else
2912      Range.setEnd(MemberNameInfo.getEndLoc());
2913    return Range;
2914  }
2915
2916  static bool classof(const Stmt *T) {
2917    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
2918  }
2919  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
2920
2921  // Iterators
2922  child_range children() {
2923    if (isImplicitAccess()) return child_range();
2924    return child_range(&Base, &Base + 1);
2925  }
2926
2927  friend class ASTStmtReader;
2928  friend class ASTStmtWriter;
2929};
2930
2931/// \brief Represents a C++ member access expression for which lookup
2932/// produced a set of overloaded functions.
2933///
2934/// The member access may be explicit or implicit:
2935///    struct A {
2936///      int a, b;
2937///      int explicitAccess() { return this->a + this->A::b; }
2938///      int implicitAccess() { return a + A::b; }
2939///    };
2940///
2941/// In the final AST, an explicit access always becomes a MemberExpr.
2942/// An implicit access may become either a MemberExpr or a
2943/// DeclRefExpr, depending on whether the member is static.
2944class UnresolvedMemberExpr : public OverloadExpr {
2945  /// \brief Whether this member expression used the '->' operator or
2946  /// the '.' operator.
2947  bool IsArrow : 1;
2948
2949  /// \brief Whether the lookup results contain an unresolved using
2950  /// declaration.
2951  bool HasUnresolvedUsing : 1;
2952
2953  /// \brief The expression for the base pointer or class reference,
2954  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
2955  /// member expression
2956  Stmt *Base;
2957
2958  /// \brief The type of the base expression;  never null.
2959  QualType BaseType;
2960
2961  /// \brief The location of the '->' or '.' operator.
2962  SourceLocation OperatorLoc;
2963
2964  UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
2965                       Expr *Base, QualType BaseType, bool IsArrow,
2966                       SourceLocation OperatorLoc,
2967                       NestedNameSpecifierLoc QualifierLoc,
2968                       SourceLocation TemplateKWLoc,
2969                       const DeclarationNameInfo &MemberNameInfo,
2970                       const TemplateArgumentListInfo *TemplateArgs,
2971                       UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2972
2973  UnresolvedMemberExpr(EmptyShell Empty)
2974    : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2975      HasUnresolvedUsing(false), Base(0) { }
2976
2977  friend class ASTStmtReader;
2978
2979public:
2980  static UnresolvedMemberExpr *
2981  Create(ASTContext &C, bool HasUnresolvedUsing,
2982         Expr *Base, QualType BaseType, bool IsArrow,
2983         SourceLocation OperatorLoc,
2984         NestedNameSpecifierLoc QualifierLoc,
2985         SourceLocation TemplateKWLoc,
2986         const DeclarationNameInfo &MemberNameInfo,
2987         const TemplateArgumentListInfo *TemplateArgs,
2988         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2989
2990  static UnresolvedMemberExpr *
2991  CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
2992              unsigned NumTemplateArgs);
2993
2994  /// \brief True if this is an implicit access, i.e. one in which the
2995  /// member being accessed was not written in the source.  The source
2996  /// location of the operator is invalid in this case.
2997  bool isImplicitAccess() const;
2998
2999  /// \brief Retrieve the base object of this member expressions,
3000  /// e.g., the \c x in \c x.m.
3001  Expr *getBase() {
3002    assert(!isImplicitAccess());
3003    return cast<Expr>(Base);
3004  }
3005  const Expr *getBase() const {
3006    assert(!isImplicitAccess());
3007    return cast<Expr>(Base);
3008  }
3009
3010  QualType getBaseType() const { return BaseType; }
3011
3012  /// \brief Determine whether the lookup results contain an unresolved using
3013  /// declaration.
3014  bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3015
3016  /// \brief Determine whether this member expression used the '->'
3017  /// operator; otherwise, it used the '.' operator.
3018  bool isArrow() const { return IsArrow; }
3019
3020  /// \brief Retrieve the location of the '->' or '.' operator.
3021  SourceLocation getOperatorLoc() const { return OperatorLoc; }
3022
3023  /// \brief Retrieves the naming class of this lookup.
3024  CXXRecordDecl *getNamingClass() const;
3025
3026  /// \brief Retrieve the full name info for the member that this expression
3027  /// refers to.
3028  const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3029
3030  /// \brief Retrieve the name of the member that this expression
3031  /// refers to.
3032  DeclarationName getMemberName() const { return getName(); }
3033
3034  // \brief Retrieve the location of the name of the member that this
3035  // expression refers to.
3036  SourceLocation getMemberLoc() const { return getNameLoc(); }
3037
3038  SourceRange getSourceRange() const {
3039    SourceRange Range = getMemberNameInfo().getSourceRange();
3040    if (!isImplicitAccess())
3041      Range.setBegin(Base->getSourceRange().getBegin());
3042    else if (getQualifierLoc())
3043      Range.setBegin(getQualifierLoc().getBeginLoc());
3044
3045    if (hasExplicitTemplateArgs())
3046      Range.setEnd(getRAngleLoc());
3047    return Range;
3048  }
3049
3050  static bool classof(const Stmt *T) {
3051    return T->getStmtClass() == UnresolvedMemberExprClass;
3052  }
3053  static bool classof(const UnresolvedMemberExpr *) { return true; }
3054
3055  // Iterators
3056  child_range children() {
3057    if (isImplicitAccess()) return child_range();
3058    return child_range(&Base, &Base + 1);
3059  }
3060};
3061
3062/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
3063///
3064/// The noexcept expression tests whether a given expression might throw. Its
3065/// result is a boolean constant.
3066class CXXNoexceptExpr : public Expr {
3067  bool Value : 1;
3068  Stmt *Operand;
3069  SourceRange Range;
3070
3071  friend class ASTStmtReader;
3072
3073public:
3074  CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3075                  SourceLocation Keyword, SourceLocation RParen)
3076    : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3077           /*TypeDependent*/false,
3078           /*ValueDependent*/Val == CT_Dependent,
3079           Val == CT_Dependent || Operand->isInstantiationDependent(),
3080           Operand->containsUnexpandedParameterPack()),
3081      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
3082  { }
3083
3084  CXXNoexceptExpr(EmptyShell Empty)
3085    : Expr(CXXNoexceptExprClass, Empty)
3086  { }
3087
3088  Expr *getOperand() const { return static_cast<Expr*>(Operand); }
3089
3090  SourceRange getSourceRange() const { return Range; }
3091
3092  bool getValue() const { return Value; }
3093
3094  static bool classof(const Stmt *T) {
3095    return T->getStmtClass() == CXXNoexceptExprClass;
3096  }
3097  static bool classof(const CXXNoexceptExpr *) { return true; }
3098
3099  // Iterators
3100  child_range children() { return child_range(&Operand, &Operand + 1); }
3101};
3102
3103/// \brief Represents a C++0x pack expansion that produces a sequence of
3104/// expressions.
3105///
3106/// A pack expansion expression contains a pattern (which itself is an
3107/// expression) followed by an ellipsis. For example:
3108///
3109/// \code
3110/// template<typename F, typename ...Types>
3111/// void forward(F f, Types &&...args) {
3112///   f(static_cast<Types&&>(args)...);
3113/// }
3114/// \endcode
3115///
3116/// Here, the argument to the function object \c f is a pack expansion whose
3117/// pattern is \c static_cast<Types&&>(args). When the \c forward function
3118/// template is instantiated, the pack expansion will instantiate to zero or
3119/// or more function arguments to the function object \c f.
3120class PackExpansionExpr : public Expr {
3121  SourceLocation EllipsisLoc;
3122
3123  /// \brief The number of expansions that will be produced by this pack
3124  /// expansion expression, if known.
3125  ///
3126  /// When zero, the number of expansions is not known. Otherwise, this value
3127  /// is the number of expansions + 1.
3128  unsigned NumExpansions;
3129
3130  Stmt *Pattern;
3131
3132  friend class ASTStmtReader;
3133  friend class ASTStmtWriter;
3134
3135public:
3136  PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3137                    llvm::Optional<unsigned> NumExpansions)
3138    : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3139           Pattern->getObjectKind(), /*TypeDependent=*/true,
3140           /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3141           /*ContainsUnexpandedParameterPack=*/false),
3142      EllipsisLoc(EllipsisLoc),
3143      NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3144      Pattern(Pattern) { }
3145
3146  PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3147
3148  /// \brief Retrieve the pattern of the pack expansion.
3149  Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3150
3151  /// \brief Retrieve the pattern of the pack expansion.
3152  const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3153
3154  /// \brief Retrieve the location of the ellipsis that describes this pack
3155  /// expansion.
3156  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3157
3158  /// \brief Determine the number of expansions that will be produced when
3159  /// this pack expansion is instantiated, if already known.
3160  llvm::Optional<unsigned> getNumExpansions() const {
3161    if (NumExpansions)
3162      return NumExpansions - 1;
3163
3164    return llvm::Optional<unsigned>();
3165  }
3166
3167  SourceRange getSourceRange() const {
3168    return SourceRange(Pattern->getLocStart(), EllipsisLoc);
3169  }
3170
3171  static bool classof(const Stmt *T) {
3172    return T->getStmtClass() == PackExpansionExprClass;
3173  }
3174  static bool classof(const PackExpansionExpr *) { return true; }
3175
3176  // Iterators
3177  child_range children() {
3178    return child_range(&Pattern, &Pattern + 1);
3179  }
3180};
3181
3182inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3183  if (!HasTemplateKWAndArgsInfo) return 0;
3184  if (isa<UnresolvedLookupExpr>(this))
3185    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3186      (cast<UnresolvedLookupExpr>(this) + 1);
3187  else
3188    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3189      (cast<UnresolvedMemberExpr>(this) + 1);
3190}
3191
3192/// \brief Represents an expression that computes the length of a parameter
3193/// pack.
3194///
3195/// \code
3196/// template<typename ...Types>
3197/// struct count {
3198///   static const unsigned value = sizeof...(Types);
3199/// };
3200/// \endcode
3201class SizeOfPackExpr : public Expr {
3202  /// \brief The location of the 'sizeof' keyword.
3203  SourceLocation OperatorLoc;
3204
3205  /// \brief The location of the name of the parameter pack.
3206  SourceLocation PackLoc;
3207
3208  /// \brief The location of the closing parenthesis.
3209  SourceLocation RParenLoc;
3210
3211  /// \brief The length of the parameter pack, if known.
3212  ///
3213  /// When this expression is value-dependent, the length of the parameter pack
3214  /// is unknown. When this expression is not value-dependent, the length is
3215  /// known.
3216  unsigned Length;
3217
3218  /// \brief The parameter pack itself.
3219  NamedDecl *Pack;
3220
3221  friend class ASTStmtReader;
3222  friend class ASTStmtWriter;
3223
3224public:
3225  /// \brief Creates a value-dependent expression that computes the length of
3226  /// the given parameter pack.
3227  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3228                 SourceLocation PackLoc, SourceLocation RParenLoc)
3229    : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3230           /*TypeDependent=*/false, /*ValueDependent=*/true,
3231           /*InstantiationDependent=*/true,
3232           /*ContainsUnexpandedParameterPack=*/false),
3233      OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3234      Length(0), Pack(Pack) { }
3235
3236  /// \brief Creates an expression that computes the length of
3237  /// the given parameter pack, which is already known.
3238  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3239                 SourceLocation PackLoc, SourceLocation RParenLoc,
3240                 unsigned Length)
3241  : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3242         /*TypeDependent=*/false, /*ValueDependent=*/false,
3243         /*InstantiationDependent=*/false,
3244         /*ContainsUnexpandedParameterPack=*/false),
3245    OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3246    Length(Length), Pack(Pack) { }
3247
3248  /// \brief Create an empty expression.
3249  SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3250
3251  /// \brief Determine the location of the 'sizeof' keyword.
3252  SourceLocation getOperatorLoc() const { return OperatorLoc; }
3253
3254  /// \brief Determine the location of the parameter pack.
3255  SourceLocation getPackLoc() const { return PackLoc; }
3256
3257  /// \brief Determine the location of the right parenthesis.
3258  SourceLocation getRParenLoc() const { return RParenLoc; }
3259
3260  /// \brief Retrieve the parameter pack.
3261  NamedDecl *getPack() const { return Pack; }
3262
3263  /// \brief Retrieve the length of the parameter pack.
3264  ///
3265  /// This routine may only be invoked when the expression is not
3266  /// value-dependent.
3267  unsigned getPackLength() const {
3268    assert(!isValueDependent() &&
3269           "Cannot get the length of a value-dependent pack size expression");
3270    return Length;
3271  }
3272
3273  SourceRange getSourceRange() const {
3274    return SourceRange(OperatorLoc, RParenLoc);
3275  }
3276
3277  static bool classof(const Stmt *T) {
3278    return T->getStmtClass() == SizeOfPackExprClass;
3279  }
3280  static bool classof(const SizeOfPackExpr *) { return true; }
3281
3282  // Iterators
3283  child_range children() { return child_range(); }
3284};
3285
3286/// \brief Represents a reference to a non-type template parameter
3287/// that has been substituted with a template argument.
3288class SubstNonTypeTemplateParmExpr : public Expr {
3289  /// \brief The replaced parameter.
3290  NonTypeTemplateParmDecl *Param;
3291
3292  /// \brief The replacement expression.
3293  Stmt *Replacement;
3294
3295  /// \brief The location of the non-type template parameter reference.
3296  SourceLocation NameLoc;
3297
3298  friend class ASTReader;
3299  friend class ASTStmtReader;
3300  explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
3301    : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
3302
3303public:
3304  SubstNonTypeTemplateParmExpr(QualType type,
3305                               ExprValueKind valueKind,
3306                               SourceLocation loc,
3307                               NonTypeTemplateParmDecl *param,
3308                               Expr *replacement)
3309    : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3310           replacement->isTypeDependent(), replacement->isValueDependent(),
3311           replacement->isInstantiationDependent(),
3312           replacement->containsUnexpandedParameterPack()),
3313      Param(param), Replacement(replacement), NameLoc(loc) {}
3314
3315  SourceLocation getNameLoc() const { return NameLoc; }
3316  SourceRange getSourceRange() const { return NameLoc; }
3317
3318  Expr *getReplacement() const { return cast<Expr>(Replacement); }
3319
3320  NonTypeTemplateParmDecl *getParameter() const { return Param; }
3321
3322  static bool classof(const Stmt *s) {
3323    return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3324  }
3325  static bool classof(const SubstNonTypeTemplateParmExpr *) {
3326    return true;
3327  }
3328
3329  // Iterators
3330  child_range children() { return child_range(&Replacement, &Replacement+1); }
3331};
3332
3333/// \brief Represents a reference to a non-type template parameter pack that
3334/// has been substituted with a non-template argument pack.
3335///
3336/// When a pack expansion in the source code contains multiple parameter packs
3337/// and those parameter packs correspond to different levels of template
3338/// parameter lists, this node node is used to represent a non-type template
3339/// parameter pack from an outer level, which has already had its argument pack
3340/// substituted but that still lives within a pack expansion that itself
3341/// could not be instantiated. When actually performing a substitution into
3342/// that pack expansion (e.g., when all template parameters have corresponding
3343/// arguments), this type will be replaced with the appropriate underlying
3344/// expression at the current pack substitution index.
3345class SubstNonTypeTemplateParmPackExpr : public Expr {
3346  /// \brief The non-type template parameter pack itself.
3347  NonTypeTemplateParmDecl *Param;
3348
3349  /// \brief A pointer to the set of template arguments that this
3350  /// parameter pack is instantiated with.
3351  const TemplateArgument *Arguments;
3352
3353  /// \brief The number of template arguments in \c Arguments.
3354  unsigned NumArguments;
3355
3356  /// \brief The location of the non-type template parameter pack reference.
3357  SourceLocation NameLoc;
3358
3359  friend class ASTReader;
3360  friend class ASTStmtReader;
3361  explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3362    : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3363
3364public:
3365  SubstNonTypeTemplateParmPackExpr(QualType T,
3366                                   NonTypeTemplateParmDecl *Param,
3367                                   SourceLocation NameLoc,
3368                                   const TemplateArgument &ArgPack);
3369
3370  /// \brief Retrieve the non-type template parameter pack being substituted.
3371  NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3372
3373  /// \brief Retrieve the location of the parameter pack name.
3374  SourceLocation getParameterPackLocation() const { return NameLoc; }
3375
3376  /// \brief Retrieve the template argument pack containing the substituted
3377  /// template arguments.
3378  TemplateArgument getArgumentPack() const;
3379
3380  SourceRange getSourceRange() const { return NameLoc; }
3381
3382  static bool classof(const Stmt *T) {
3383    return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3384  }
3385  static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
3386    return true;
3387  }
3388
3389  // Iterators
3390  child_range children() { return child_range(); }
3391};
3392
3393/// \brief Represents a prvalue temporary that written into memory so that
3394/// a reference can bind to it.
3395///
3396/// Prvalue expressions are materialized when they need to have an address
3397/// in memory for a reference to bind to. This happens when binding a
3398/// reference to the result of a conversion, e.g.,
3399///
3400/// \code
3401/// const int &r = 1.0;
3402/// \endcode
3403///
3404/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3405/// then materialized via a \c MaterializeTemporaryExpr, and the reference
3406/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3407/// (either an lvalue or an xvalue, depending on the kind of reference binding
3408/// to it), maintaining the invariant that references always bind to glvalues.
3409class MaterializeTemporaryExpr : public Expr {
3410  /// \brief The temporary-generating expression whose value will be
3411  /// materialized.
3412 Stmt *Temporary;
3413
3414  friend class ASTStmtReader;
3415  friend class ASTStmtWriter;
3416
3417public:
3418  MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3419                           bool BoundToLvalueReference)
3420    : Expr(MaterializeTemporaryExprClass, T,
3421           BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3422           Temporary->isTypeDependent(), Temporary->isValueDependent(),
3423           Temporary->isInstantiationDependent(),
3424           Temporary->containsUnexpandedParameterPack()),
3425      Temporary(Temporary) { }
3426
3427  MaterializeTemporaryExpr(EmptyShell Empty)
3428    : Expr(MaterializeTemporaryExprClass, Empty) { }
3429
3430  /// \brief Retrieve the temporary-generating subexpression whose value will
3431  /// be materialized into a glvalue.
3432  Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); }
3433
3434  /// \brief Determine whether this materialized temporary is bound to an
3435  /// lvalue reference; otherwise, it's bound to an rvalue reference.
3436  bool isBoundToLvalueReference() const {
3437    return getValueKind() == VK_LValue;
3438  }
3439
3440  SourceRange getSourceRange() const { return Temporary->getSourceRange(); }
3441
3442  static bool classof(const Stmt *T) {
3443    return T->getStmtClass() == MaterializeTemporaryExprClass;
3444  }
3445  static bool classof(const MaterializeTemporaryExpr *) {
3446    return true;
3447  }
3448
3449  // Iterators
3450  child_range children() { return child_range(&Temporary, &Temporary + 1); }
3451};
3452
3453}  // end namespace clang
3454
3455#endif
3456