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