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