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