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