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