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