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