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