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