ExprCXX.h revision 6ec278d1a354517e20f13a877481453ee7940c78
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                                           unsigned NumTemplateArgs);
1766
1767  /// True if this declaration should be extended by
1768  /// argument-dependent lookup.
1769  bool requiresADL() const { return RequiresADL; }
1770  void setRequiresADL(bool V) { RequiresADL = V; }
1771
1772  /// True if this lookup is overloaded.
1773  bool isOverloaded() const { return Overloaded; }
1774  void setOverloaded(bool V) { Overloaded = V; }
1775
1776  /// Gets the 'naming class' (in the sense of C++0x
1777  /// [class.access.base]p5) of the lookup.  This is the scope
1778  /// that was looked in to find these results.
1779  CXXRecordDecl *getNamingClass() const { return NamingClass; }
1780  void setNamingClass(CXXRecordDecl *D) { NamingClass = D; }
1781
1782  // Note that, inconsistently with the explicit-template-argument AST
1783  // nodes, users are *forbidden* from calling these methods on objects
1784  // without explicit template arguments.
1785
1786  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1787    assert(hasExplicitTemplateArgs());
1788    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1789  }
1790
1791  /// Gets a reference to the explicit template argument list.
1792  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1793    assert(hasExplicitTemplateArgs());
1794    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1795  }
1796
1797  /// \brief Retrieves the optional explicit template arguments.
1798  /// This points to the same data as getExplicitTemplateArgs(), but
1799  /// returns null if there are no explicit template arguments.
1800  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1801    if (!hasExplicitTemplateArgs()) return 0;
1802    return &getExplicitTemplateArgs();
1803  }
1804
1805  /// \brief Copies the template arguments (if present) into the given
1806  /// structure.
1807  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1808    getExplicitTemplateArgs().copyInto(List);
1809  }
1810
1811  SourceLocation getLAngleLoc() const {
1812    return getExplicitTemplateArgs().LAngleLoc;
1813  }
1814
1815  SourceLocation getRAngleLoc() const {
1816    return getExplicitTemplateArgs().RAngleLoc;
1817  }
1818
1819  TemplateArgumentLoc const *getTemplateArgs() const {
1820    return getExplicitTemplateArgs().getTemplateArgs();
1821  }
1822
1823  unsigned getNumTemplateArgs() const {
1824    return getExplicitTemplateArgs().NumTemplateArgs;
1825  }
1826
1827  virtual SourceRange getSourceRange() const {
1828    SourceRange Range(getNameInfo().getSourceRange());
1829    if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
1830    if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
1831    return Range;
1832  }
1833
1834  virtual StmtIterator child_begin();
1835  virtual StmtIterator child_end();
1836
1837  static bool classof(const Stmt *T) {
1838    return T->getStmtClass() == UnresolvedLookupExprClass;
1839  }
1840  static bool classof(const UnresolvedLookupExpr *) { return true; }
1841};
1842
1843/// \brief A qualified reference to a name whose declaration cannot
1844/// yet be resolved.
1845///
1846/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1847/// it expresses a reference to a declaration such as
1848/// X<T>::value. The difference, however, is that an
1849/// DependentScopeDeclRefExpr node is used only within C++ templates when
1850/// the qualification (e.g., X<T>::) refers to a dependent type. In
1851/// this case, X<T>::value cannot resolve to a declaration because the
1852/// declaration will differ from on instantiation of X<T> to the
1853/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1854/// qualifier (X<T>::) and the name of the entity being referenced
1855/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1856/// declaration can be found.
1857class DependentScopeDeclRefExpr : public Expr {
1858  /// The name of the entity we will be referencing.
1859  DeclarationNameInfo NameInfo;
1860
1861  /// QualifierRange - The source range that covers the
1862  /// nested-name-specifier.
1863  SourceRange QualifierRange;
1864
1865  /// \brief The nested-name-specifier that qualifies this unresolved
1866  /// declaration name.
1867  NestedNameSpecifier *Qualifier;
1868
1869  /// \brief Whether the name includes explicit template arguments.
1870  bool HasExplicitTemplateArgs;
1871
1872  DependentScopeDeclRefExpr(QualType T,
1873                            NestedNameSpecifier *Qualifier,
1874                            SourceRange QualifierRange,
1875                            const DeclarationNameInfo &NameInfo,
1876                            const TemplateArgumentListInfo *Args);
1877
1878public:
1879  static DependentScopeDeclRefExpr *Create(ASTContext &C,
1880                                           NestedNameSpecifier *Qualifier,
1881                                           SourceRange QualifierRange,
1882                                           const DeclarationNameInfo &NameInfo,
1883                              const TemplateArgumentListInfo *TemplateArgs = 0);
1884
1885  static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
1886                                                unsigned NumTemplateArgs);
1887
1888  /// \brief Retrieve the name that this expression refers to.
1889  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1890  void setNameInfo(const DeclarationNameInfo &N) { NameInfo =  N; }
1891
1892  /// \brief Retrieve the name that this expression refers to.
1893  DeclarationName getDeclName() const { return NameInfo.getName(); }
1894  void setDeclName(DeclarationName N) { NameInfo.setName(N); }
1895
1896  /// \brief Retrieve the location of the name within the expression.
1897  SourceLocation getLocation() const { return NameInfo.getLoc(); }
1898  void setLocation(SourceLocation L) { NameInfo.setLoc(L); }
1899
1900  /// \brief Retrieve the source range of the nested-name-specifier.
1901  SourceRange getQualifierRange() const { return QualifierRange; }
1902  void setQualifierRange(SourceRange R) { QualifierRange = R; }
1903
1904  /// \brief Retrieve the nested-name-specifier that qualifies this
1905  /// declaration.
1906  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1907  void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1908
1909  /// Determines whether this lookup had explicit template arguments.
1910  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1911
1912  // Note that, inconsistently with the explicit-template-argument AST
1913  // nodes, users are *forbidden* from calling these methods on objects
1914  // without explicit template arguments.
1915
1916  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1917    assert(hasExplicitTemplateArgs());
1918    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1919  }
1920
1921  /// Gets a reference to the explicit template argument list.
1922  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1923    assert(hasExplicitTemplateArgs());
1924    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1925  }
1926
1927  /// \brief Retrieves the optional explicit template arguments.
1928  /// This points to the same data as getExplicitTemplateArgs(), but
1929  /// returns null if there are no explicit template arguments.
1930  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1931    if (!hasExplicitTemplateArgs()) return 0;
1932    return &getExplicitTemplateArgs();
1933  }
1934
1935  /// \brief Copies the template arguments (if present) into the given
1936  /// structure.
1937  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1938    getExplicitTemplateArgs().copyInto(List);
1939  }
1940
1941  SourceLocation getLAngleLoc() const {
1942    return getExplicitTemplateArgs().LAngleLoc;
1943  }
1944
1945  SourceLocation getRAngleLoc() const {
1946    return getExplicitTemplateArgs().RAngleLoc;
1947  }
1948
1949  TemplateArgumentLoc const *getTemplateArgs() const {
1950    return getExplicitTemplateArgs().getTemplateArgs();
1951  }
1952
1953  unsigned getNumTemplateArgs() const {
1954    return getExplicitTemplateArgs().NumTemplateArgs;
1955  }
1956
1957  virtual SourceRange getSourceRange() const {
1958    SourceRange Range(QualifierRange.getBegin(), getLocation());
1959    if (hasExplicitTemplateArgs())
1960      Range.setEnd(getRAngleLoc());
1961    return Range;
1962  }
1963
1964  static bool classof(const Stmt *T) {
1965    return T->getStmtClass() == DependentScopeDeclRefExprClass;
1966  }
1967  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1968
1969  virtual StmtIterator child_begin();
1970  virtual StmtIterator child_end();
1971
1972  friend class ASTStmtReader;
1973  friend class ASTStmtWriter;
1974};
1975
1976/// Represents an expression --- generally a full-expression --- which
1977/// introduces cleanups to be run at the end of the sub-expression's
1978/// evaluation.  The most common source of expression-introduced
1979/// cleanups is temporary objects in C++, but several other C++
1980/// expressions can create cleanups.
1981class ExprWithCleanups : public Expr {
1982  Stmt *SubExpr;
1983
1984  CXXTemporary **Temps;
1985  unsigned NumTemps;
1986
1987  ExprWithCleanups(ASTContext &C, Expr *SubExpr,
1988                   CXXTemporary **Temps, unsigned NumTemps);
1989
1990public:
1991  ExprWithCleanups(EmptyShell Empty)
1992    : Expr(ExprWithCleanupsClass, Empty),
1993      SubExpr(0), Temps(0), NumTemps(0) {}
1994
1995  static ExprWithCleanups *Create(ASTContext &C, Expr *SubExpr,
1996                                        CXXTemporary **Temps,
1997                                        unsigned NumTemps);
1998
1999  unsigned getNumTemporaries() const { return NumTemps; }
2000  void setNumTemporaries(ASTContext &C, unsigned N);
2001
2002  CXXTemporary *getTemporary(unsigned i) {
2003    assert(i < NumTemps && "Index out of range");
2004    return Temps[i];
2005  }
2006  const CXXTemporary *getTemporary(unsigned i) const {
2007    return const_cast<ExprWithCleanups*>(this)->getTemporary(i);
2008  }
2009  void setTemporary(unsigned i, CXXTemporary *T) {
2010    assert(i < NumTemps && "Index out of range");
2011    Temps[i] = T;
2012  }
2013
2014  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2015  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2016  void setSubExpr(Expr *E) { SubExpr = E; }
2017
2018  virtual SourceRange getSourceRange() const {
2019    return SubExpr->getSourceRange();
2020  }
2021
2022  // Implement isa/cast/dyncast/etc.
2023  static bool classof(const Stmt *T) {
2024    return T->getStmtClass() == ExprWithCleanupsClass;
2025  }
2026  static bool classof(const ExprWithCleanups *) { return true; }
2027
2028  // Iterators
2029  virtual child_iterator child_begin();
2030  virtual child_iterator child_end();
2031};
2032
2033/// \brief Describes an explicit type conversion that uses functional
2034/// notion but could not be resolved because one or more arguments are
2035/// type-dependent.
2036///
2037/// The explicit type conversions expressed by
2038/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2039/// where \c T is some type and \c a1, a2, ..., aN are values, and
2040/// either \C T is a dependent type or one or more of the \c a's is
2041/// type-dependent. For example, this would occur in a template such
2042/// as:
2043///
2044/// \code
2045///   template<typename T, typename A1>
2046///   inline T make_a(const A1& a1) {
2047///     return T(a1);
2048///   }
2049/// \endcode
2050///
2051/// When the returned expression is instantiated, it may resolve to a
2052/// constructor call, conversion function call, or some kind of type
2053/// conversion.
2054class CXXUnresolvedConstructExpr : public Expr {
2055  /// \brief The type being constructed.
2056  TypeSourceInfo *Type;
2057
2058  /// \brief The location of the left parentheses ('(').
2059  SourceLocation LParenLoc;
2060
2061  /// \brief The location of the right parentheses (')').
2062  SourceLocation RParenLoc;
2063
2064  /// \brief The number of arguments used to construct the type.
2065  unsigned NumArgs;
2066
2067  CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2068                             SourceLocation LParenLoc,
2069                             Expr **Args,
2070                             unsigned NumArgs,
2071                             SourceLocation RParenLoc);
2072
2073  CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2074    : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2075
2076  friend class ASTStmtReader;
2077
2078public:
2079  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2080                                            TypeSourceInfo *Type,
2081                                            SourceLocation LParenLoc,
2082                                            Expr **Args,
2083                                            unsigned NumArgs,
2084                                            SourceLocation RParenLoc);
2085
2086  static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
2087                                                 unsigned NumArgs);
2088
2089  /// \brief Retrieve the type that is being constructed, as specified
2090  /// in the source code.
2091  QualType getTypeAsWritten() const { return Type->getType(); }
2092
2093  /// \brief Retrieve the type source information for the type being
2094  /// constructed.
2095  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2096
2097  /// \brief Retrieve the location of the left parentheses ('(') that
2098  /// precedes the argument list.
2099  SourceLocation getLParenLoc() const { return LParenLoc; }
2100  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2101
2102  /// \brief Retrieve the location of the right parentheses (')') that
2103  /// follows the argument list.
2104  SourceLocation getRParenLoc() const { return RParenLoc; }
2105  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2106
2107  /// \brief Retrieve the number of arguments.
2108  unsigned arg_size() const { return NumArgs; }
2109
2110  typedef Expr** arg_iterator;
2111  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2112  arg_iterator arg_end() { return arg_begin() + NumArgs; }
2113
2114  typedef const Expr* const * const_arg_iterator;
2115  const_arg_iterator arg_begin() const {
2116    return reinterpret_cast<const Expr* const *>(this + 1);
2117  }
2118  const_arg_iterator arg_end() const {
2119    return arg_begin() + NumArgs;
2120  }
2121
2122  Expr *getArg(unsigned I) {
2123    assert(I < NumArgs && "Argument index out-of-range");
2124    return *(arg_begin() + I);
2125  }
2126
2127  const Expr *getArg(unsigned I) const {
2128    assert(I < NumArgs && "Argument index out-of-range");
2129    return *(arg_begin() + I);
2130  }
2131
2132  void setArg(unsigned I, Expr *E) {
2133    assert(I < NumArgs && "Argument index out-of-range");
2134    *(arg_begin() + I) = E;
2135  }
2136
2137  virtual SourceRange getSourceRange() const;
2138
2139  static bool classof(const Stmt *T) {
2140    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2141  }
2142  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2143
2144  // Iterators
2145  virtual child_iterator child_begin();
2146  virtual child_iterator child_end();
2147};
2148
2149/// \brief Represents a C++ member access expression where the actual
2150/// member referenced could not be resolved because the base
2151/// expression or the member name was dependent.
2152///
2153/// Like UnresolvedMemberExprs, these can be either implicit or
2154/// explicit accesses.  It is only possible to get one of these with
2155/// an implicit access if a qualifier is provided.
2156class CXXDependentScopeMemberExpr : public Expr {
2157  /// \brief The expression for the base pointer or class reference,
2158  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
2159  Stmt *Base;
2160
2161  /// \brief The type of the base expression.  Never null, even for
2162  /// implicit accesses.
2163  QualType BaseType;
2164
2165  /// \brief Whether this member expression used the '->' operator or
2166  /// the '.' operator.
2167  bool IsArrow : 1;
2168
2169  /// \brief Whether this member expression has explicitly-specified template
2170  /// arguments.
2171  bool HasExplicitTemplateArgs : 1;
2172
2173  /// \brief The location of the '->' or '.' operator.
2174  SourceLocation OperatorLoc;
2175
2176  /// \brief The nested-name-specifier that precedes the member name, if any.
2177  NestedNameSpecifier *Qualifier;
2178
2179  /// \brief The source range covering the nested name specifier.
2180  SourceRange QualifierRange;
2181
2182  /// \brief In a qualified member access expression such as t->Base::f, this
2183  /// member stores the resolves of name lookup in the context of the member
2184  /// access expression, to be used at instantiation time.
2185  ///
2186  /// FIXME: This member, along with the Qualifier and QualifierRange, could
2187  /// be stuck into a structure that is optionally allocated at the end of
2188  /// the CXXDependentScopeMemberExpr, to save space in the common case.
2189  NamedDecl *FirstQualifierFoundInScope;
2190
2191  /// \brief The member to which this member expression refers, which
2192  /// can be name, overloaded operator, or destructor.
2193  /// FIXME: could also be a template-id
2194  DeclarationNameInfo MemberNameInfo;
2195
2196  CXXDependentScopeMemberExpr(ASTContext &C,
2197                          Expr *Base, QualType BaseType, bool IsArrow,
2198                          SourceLocation OperatorLoc,
2199                          NestedNameSpecifier *Qualifier,
2200                          SourceRange QualifierRange,
2201                          NamedDecl *FirstQualifierFoundInScope,
2202                          DeclarationNameInfo MemberNameInfo,
2203                          const TemplateArgumentListInfo *TemplateArgs);
2204
2205public:
2206  CXXDependentScopeMemberExpr(ASTContext &C,
2207                              Expr *Base, QualType BaseType,
2208                              bool IsArrow,
2209                              SourceLocation OperatorLoc,
2210                              NestedNameSpecifier *Qualifier,
2211                              SourceRange QualifierRange,
2212                              NamedDecl *FirstQualifierFoundInScope,
2213                              DeclarationNameInfo MemberNameInfo);
2214
2215  static CXXDependentScopeMemberExpr *
2216  Create(ASTContext &C,
2217         Expr *Base, QualType BaseType, bool IsArrow,
2218         SourceLocation OperatorLoc,
2219         NestedNameSpecifier *Qualifier,
2220         SourceRange QualifierRange,
2221         NamedDecl *FirstQualifierFoundInScope,
2222         DeclarationNameInfo MemberNameInfo,
2223         const TemplateArgumentListInfo *TemplateArgs);
2224
2225  static CXXDependentScopeMemberExpr *
2226  CreateEmpty(ASTContext &C, unsigned NumTemplateArgs);
2227
2228  /// \brief True if this is an implicit access, i.e. one in which the
2229  /// member being accessed was not written in the source.  The source
2230  /// location of the operator is invalid in this case.
2231  bool isImplicitAccess() const { return Base == 0; }
2232
2233  /// \brief Retrieve the base object of this member expressions,
2234  /// e.g., the \c x in \c x.m.
2235  Expr *getBase() const {
2236    assert(!isImplicitAccess());
2237    return cast<Expr>(Base);
2238  }
2239  void setBase(Expr *E) { Base = E; }
2240
2241  QualType getBaseType() const { return BaseType; }
2242  void setBaseType(QualType T) { BaseType = T; }
2243
2244  /// \brief Determine whether this member expression used the '->'
2245  /// operator; otherwise, it used the '.' operator.
2246  bool isArrow() const { return IsArrow; }
2247  void setArrow(bool A) { IsArrow = A; }
2248
2249  /// \brief Retrieve the location of the '->' or '.' operator.
2250  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2251  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2252
2253  /// \brief Retrieve the nested-name-specifier that qualifies the member
2254  /// name.
2255  NestedNameSpecifier *getQualifier() const { return Qualifier; }
2256  void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
2257
2258  /// \brief Retrieve the source range covering the nested-name-specifier
2259  /// that qualifies the member name.
2260  SourceRange getQualifierRange() const { return QualifierRange; }
2261  void setQualifierRange(SourceRange R) { QualifierRange = R; }
2262
2263  /// \brief Retrieve the first part of the nested-name-specifier that was
2264  /// found in the scope of the member access expression when the member access
2265  /// was initially parsed.
2266  ///
2267  /// This function only returns a useful result when member access expression
2268  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2269  /// returned by this function describes what was found by unqualified name
2270  /// lookup for the identifier "Base" within the scope of the member access
2271  /// expression itself. At template instantiation time, this information is
2272  /// combined with the results of name lookup into the type of the object
2273  /// expression itself (the class type of x).
2274  NamedDecl *getFirstQualifierFoundInScope() const {
2275    return FirstQualifierFoundInScope;
2276  }
2277  void setFirstQualifierFoundInScope(NamedDecl *D) {
2278    FirstQualifierFoundInScope = D;
2279  }
2280
2281  /// \brief Retrieve the name of the member that this expression
2282  /// refers to.
2283  const DeclarationNameInfo &getMemberNameInfo() const {
2284    return MemberNameInfo;
2285  }
2286  void setMemberNameInfo(const DeclarationNameInfo &N) { MemberNameInfo = N; }
2287
2288  /// \brief Retrieve the name of the member that this expression
2289  /// refers to.
2290  DeclarationName getMember() const { return MemberNameInfo.getName(); }
2291  void setMember(DeclarationName N) { MemberNameInfo.setName(N); }
2292
2293  // \brief Retrieve the location of the name of the member that this
2294  // expression refers to.
2295  SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
2296  void setMemberLoc(SourceLocation L) { MemberNameInfo.setLoc(L); }
2297
2298  /// \brief Determines whether this member expression actually had a C++
2299  /// template argument list explicitly specified, e.g., x.f<int>.
2300  bool hasExplicitTemplateArgs() const {
2301    return HasExplicitTemplateArgs;
2302  }
2303
2304  /// \brief Retrieve the explicit template argument list that followed the
2305  /// member template name, if any.
2306  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2307    assert(HasExplicitTemplateArgs);
2308    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2309  }
2310
2311  /// \brief Retrieve the explicit template argument list that followed the
2312  /// member template name, if any.
2313  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2314    return const_cast<CXXDependentScopeMemberExpr *>(this)
2315             ->getExplicitTemplateArgs();
2316  }
2317
2318  /// \brief Retrieves the optional explicit template arguments.
2319  /// This points to the same data as getExplicitTemplateArgs(), but
2320  /// returns null if there are no explicit template arguments.
2321  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2322    if (!hasExplicitTemplateArgs()) return 0;
2323    return &getExplicitTemplateArgs();
2324  }
2325
2326  /// \brief Copies the template arguments (if present) into the given
2327  /// structure.
2328  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2329    getExplicitTemplateArgs().copyInto(List);
2330  }
2331
2332  /// \brief Initializes the template arguments using the given structure.
2333  void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2334    getExplicitTemplateArgs().initializeFrom(List);
2335  }
2336
2337  /// \brief Retrieve the location of the left angle bracket following the
2338  /// member name ('<'), if any.
2339  SourceLocation getLAngleLoc() const {
2340    return getExplicitTemplateArgs().LAngleLoc;
2341  }
2342
2343  /// \brief Retrieve the template arguments provided as part of this
2344  /// template-id.
2345  const TemplateArgumentLoc *getTemplateArgs() const {
2346    return getExplicitTemplateArgs().getTemplateArgs();
2347  }
2348
2349  /// \brief Retrieve the number of template arguments provided as part of this
2350  /// template-id.
2351  unsigned getNumTemplateArgs() const {
2352    return getExplicitTemplateArgs().NumTemplateArgs;
2353  }
2354
2355  /// \brief Retrieve the location of the right angle bracket following the
2356  /// template arguments ('>').
2357  SourceLocation getRAngleLoc() const {
2358    return getExplicitTemplateArgs().RAngleLoc;
2359  }
2360
2361  virtual SourceRange getSourceRange() const {
2362    SourceRange Range;
2363    if (!isImplicitAccess())
2364      Range.setBegin(Base->getSourceRange().getBegin());
2365    else if (getQualifier())
2366      Range.setBegin(getQualifierRange().getBegin());
2367    else
2368      Range.setBegin(MemberNameInfo.getBeginLoc());
2369
2370    if (hasExplicitTemplateArgs())
2371      Range.setEnd(getRAngleLoc());
2372    else
2373      Range.setEnd(MemberNameInfo.getEndLoc());
2374    return Range;
2375  }
2376
2377  static bool classof(const Stmt *T) {
2378    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
2379  }
2380  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
2381
2382  // Iterators
2383  virtual child_iterator child_begin();
2384  virtual child_iterator child_end();
2385
2386  friend class ASTStmtReader;
2387  friend class ASTStmtWriter;
2388};
2389
2390/// \brief Represents a C++ member access expression for which lookup
2391/// produced a set of overloaded functions.
2392///
2393/// The member access may be explicit or implicit:
2394///    struct A {
2395///      int a, b;
2396///      int explicitAccess() { return this->a + this->A::b; }
2397///      int implicitAccess() { return a + A::b; }
2398///    };
2399///
2400/// In the final AST, an explicit access always becomes a MemberExpr.
2401/// An implicit access may become either a MemberExpr or a
2402/// DeclRefExpr, depending on whether the member is static.
2403class UnresolvedMemberExpr : public OverloadExpr {
2404  /// \brief Whether this member expression used the '->' operator or
2405  /// the '.' operator.
2406  bool IsArrow : 1;
2407
2408  /// \brief Whether the lookup results contain an unresolved using
2409  /// declaration.
2410  bool HasUnresolvedUsing : 1;
2411
2412  /// \brief The expression for the base pointer or class reference,
2413  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
2414  /// member expression
2415  Stmt *Base;
2416
2417  /// \brief The type of the base expression;  never null.
2418  QualType BaseType;
2419
2420  /// \brief The location of the '->' or '.' operator.
2421  SourceLocation OperatorLoc;
2422
2423  UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
2424                       Expr *Base, QualType BaseType, bool IsArrow,
2425                       SourceLocation OperatorLoc,
2426                       NestedNameSpecifier *Qualifier,
2427                       SourceRange QualifierRange,
2428                       const DeclarationNameInfo &MemberNameInfo,
2429                       const TemplateArgumentListInfo *TemplateArgs,
2430                       UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2431
2432  UnresolvedMemberExpr(EmptyShell Empty)
2433    : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2434      HasUnresolvedUsing(false), Base(0) { }
2435
2436public:
2437  static UnresolvedMemberExpr *
2438  Create(ASTContext &C, bool HasUnresolvedUsing,
2439         Expr *Base, QualType BaseType, bool IsArrow,
2440         SourceLocation OperatorLoc,
2441         NestedNameSpecifier *Qualifier,
2442         SourceRange QualifierRange,
2443         const DeclarationNameInfo &MemberNameInfo,
2444         const TemplateArgumentListInfo *TemplateArgs,
2445         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2446
2447  static UnresolvedMemberExpr *
2448  CreateEmpty(ASTContext &C, unsigned NumTemplateArgs);
2449
2450  /// \brief True if this is an implicit access, i.e. one in which the
2451  /// member being accessed was not written in the source.  The source
2452  /// location of the operator is invalid in this case.
2453  bool isImplicitAccess() const { return Base == 0; }
2454
2455  /// \brief Retrieve the base object of this member expressions,
2456  /// e.g., the \c x in \c x.m.
2457  Expr *getBase() {
2458    assert(!isImplicitAccess());
2459    return cast<Expr>(Base);
2460  }
2461  const Expr *getBase() const {
2462    assert(!isImplicitAccess());
2463    return cast<Expr>(Base);
2464  }
2465  void setBase(Expr *E) { Base = E; }
2466
2467  QualType getBaseType() const { return BaseType; }
2468  void setBaseType(QualType T) { BaseType = T; }
2469
2470  /// \brief Determine whether the lookup results contain an unresolved using
2471  /// declaration.
2472  bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2473  void setHasUnresolvedUsing(bool V) { HasUnresolvedUsing = V; }
2474
2475  /// \brief Determine whether this member expression used the '->'
2476  /// operator; otherwise, it used the '.' operator.
2477  bool isArrow() const { return IsArrow; }
2478  void setArrow(bool A) { IsArrow = A; }
2479
2480  /// \brief Retrieve the location of the '->' or '.' operator.
2481  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2482  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2483
2484  /// \brief Retrieves the naming class of this lookup.
2485  CXXRecordDecl *getNamingClass() const;
2486
2487  /// \brief Retrieve the full name info for the member that this expression
2488  /// refers to.
2489  const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
2490  void setMemberNameInfo(const DeclarationNameInfo &N) { setNameInfo(N); }
2491
2492  /// \brief Retrieve the name of the member that this expression
2493  /// refers to.
2494  DeclarationName getMemberName() const { return getName(); }
2495  void setMemberName(DeclarationName N) { setName(N); }
2496
2497  // \brief Retrieve the location of the name of the member that this
2498  // expression refers to.
2499  SourceLocation getMemberLoc() const { return getNameLoc(); }
2500  void setMemberLoc(SourceLocation L) { setNameLoc(L); }
2501
2502  /// \brief Retrieve the explicit template argument list that followed the
2503  /// member template name.
2504  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2505    assert(hasExplicitTemplateArgs());
2506    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2507  }
2508
2509  /// \brief Retrieve the explicit template argument list that followed the
2510  /// member template name, if any.
2511  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2512    assert(hasExplicitTemplateArgs());
2513    return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2514  }
2515
2516  /// \brief Retrieves the optional explicit template arguments.
2517  /// This points to the same data as getExplicitTemplateArgs(), but
2518  /// returns null if there are no explicit template arguments.
2519  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2520    if (!hasExplicitTemplateArgs()) return 0;
2521    return &getExplicitTemplateArgs();
2522  }
2523
2524  /// \brief Copies the template arguments into the given structure.
2525  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2526    getExplicitTemplateArgs().copyInto(List);
2527  }
2528
2529  /// \brief Retrieve the location of the left angle bracket following
2530  /// the member name ('<').
2531  SourceLocation getLAngleLoc() const {
2532    return getExplicitTemplateArgs().LAngleLoc;
2533  }
2534
2535  /// \brief Retrieve the template arguments provided as part of this
2536  /// template-id.
2537  const TemplateArgumentLoc *getTemplateArgs() const {
2538    return getExplicitTemplateArgs().getTemplateArgs();
2539  }
2540
2541  /// \brief Retrieve the number of template arguments provided as
2542  /// part of this template-id.
2543  unsigned getNumTemplateArgs() const {
2544    return getExplicitTemplateArgs().NumTemplateArgs;
2545  }
2546
2547  /// \brief Retrieve the location of the right angle bracket
2548  /// following the template arguments ('>').
2549  SourceLocation getRAngleLoc() const {
2550    return getExplicitTemplateArgs().RAngleLoc;
2551  }
2552
2553  virtual SourceRange getSourceRange() const {
2554    SourceRange Range = getMemberNameInfo().getSourceRange();
2555    if (!isImplicitAccess())
2556      Range.setBegin(Base->getSourceRange().getBegin());
2557    else if (getQualifier())
2558      Range.setBegin(getQualifierRange().getBegin());
2559
2560    if (hasExplicitTemplateArgs())
2561      Range.setEnd(getRAngleLoc());
2562    return Range;
2563  }
2564
2565  static bool classof(const Stmt *T) {
2566    return T->getStmtClass() == UnresolvedMemberExprClass;
2567  }
2568  static bool classof(const UnresolvedMemberExpr *) { return true; }
2569
2570  // Iterators
2571  virtual child_iterator child_begin();
2572  virtual child_iterator child_end();
2573};
2574
2575/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
2576///
2577/// The noexcept expression tests whether a given expression might throw. Its
2578/// result is a boolean constant.
2579class CXXNoexceptExpr : public Expr {
2580  bool Value : 1;
2581  Stmt *Operand;
2582  SourceRange Range;
2583
2584  friend class ASTStmtReader;
2585
2586public:
2587  CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
2588                  SourceLocation Keyword, SourceLocation RParen)
2589    : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
2590           /*TypeDependent*/false,
2591           /*ValueDependent*/Val == CT_Dependent,
2592           Operand->containsUnexpandedParameterPack()),
2593      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
2594  { }
2595
2596  CXXNoexceptExpr(EmptyShell Empty)
2597    : Expr(CXXNoexceptExprClass, Empty)
2598  { }
2599
2600  Expr *getOperand() const { return static_cast<Expr*>(Operand); }
2601
2602  virtual SourceRange getSourceRange() const { return Range; }
2603
2604  bool getValue() const { return Value; }
2605
2606  static bool classof(const Stmt *T) {
2607    return T->getStmtClass() == CXXNoexceptExprClass;
2608  }
2609  static bool classof(const CXXNoexceptExpr *) { return true; }
2610
2611  // Iterators
2612  virtual child_iterator child_begin();
2613  virtual child_iterator child_end();
2614};
2615
2616/// \brief Represents a C++0x pack expansion that produces a sequence of
2617/// expressions.
2618///
2619/// A pack expansion expression contains a pattern (which itself is an
2620/// expression) followed by an ellipsis. For example:
2621///
2622/// \code
2623/// template<typename F, typename ...Types>
2624/// void forward(F f, Types &&...args) {
2625///   f(static_cast<Types&&>(args)...);
2626/// }
2627/// \endcode
2628///
2629/// Here, the argument to the function object \c f is a pack expansion whose
2630/// pattern is \c static_cast<Types&&>(args). When the \c forward function
2631/// template is instantiated, the pack expansion will instantiate to zero or
2632/// or more function arguments to the function object \c f.
2633class PackExpansionExpr : public Expr {
2634  SourceLocation EllipsisLoc;
2635
2636  /// \brief The number of expansions that will be produced by this pack
2637  /// expansion expression, if known.
2638  ///
2639  /// When zero, the number of expansions is not known. Otherwise, this value
2640  /// is the number of expansions + 1.
2641  unsigned NumExpansions;
2642
2643  Stmt *Pattern;
2644
2645  friend class ASTStmtReader;
2646  friend class ASTStmtWriter;
2647
2648public:
2649  PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
2650                    llvm::Optional<unsigned> NumExpansions)
2651    : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
2652           Pattern->getObjectKind(), /*TypeDependent=*/true,
2653           /*ValueDependent=*/true, /*ContainsUnexpandedParameterPack=*/false),
2654      EllipsisLoc(EllipsisLoc),
2655      NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
2656      Pattern(Pattern) { }
2657
2658  PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
2659
2660  /// \brief Retrieve the pattern of the pack expansion.
2661  Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
2662
2663  /// \brief Retrieve the pattern of the pack expansion.
2664  const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
2665
2666  /// \brief Retrieve the location of the ellipsis that describes this pack
2667  /// expansion.
2668  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2669
2670  /// \brief Determine the number of expansions that will be produced when
2671  /// this pack expansion is instantiated, if already known.
2672  llvm::Optional<unsigned> getNumExpansions() const {
2673    if (NumExpansions)
2674      return NumExpansions - 1;
2675
2676    return llvm::Optional<unsigned>();
2677  }
2678
2679  virtual SourceRange getSourceRange() const;
2680
2681  static bool classof(const Stmt *T) {
2682    return T->getStmtClass() == PackExpansionExprClass;
2683  }
2684  static bool classof(const PackExpansionExpr *) { return true; }
2685
2686  // Iterators
2687  virtual child_iterator child_begin();
2688  virtual child_iterator child_end();
2689};
2690
2691inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2692  if (isa<UnresolvedLookupExpr>(this))
2693    return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2694  else
2695    return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2696}
2697
2698/// \brief Represents an expression that computes the length of a parameter
2699/// pack.
2700///
2701/// \code
2702/// template<typename ...Types>
2703/// struct count {
2704///   static const unsigned value = sizeof...(Types);
2705/// };
2706/// \endcode
2707class SizeOfPackExpr : public Expr {
2708  /// \brief The location of the 'sizeof' keyword.
2709  SourceLocation OperatorLoc;
2710
2711  /// \brief The location of the name of the parameter pack.
2712  SourceLocation PackLoc;
2713
2714  /// \brief The location of the closing parenthesis.
2715  SourceLocation RParenLoc;
2716
2717  /// \brief The length of the parameter pack, if known.
2718  ///
2719  /// When this expression is value-dependent, the length of the parameter pack
2720  /// is unknown. When this expression is not value-dependent, the length is
2721  /// known.
2722  unsigned Length;
2723
2724  /// \brief The parameter pack itself.
2725  NamedDecl *Pack;
2726
2727  friend class ASTStmtReader;
2728  friend class ASTStmtWriter;
2729
2730public:
2731  /// \brief Creates a value-dependent expression that computes the length of
2732  /// the given parameter pack.
2733  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2734                 SourceLocation PackLoc, SourceLocation RParenLoc)
2735    : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2736           /*TypeDependent=*/false, /*ValueDependent=*/true,
2737           /*ContainsUnexpandedParameterPack=*/false),
2738      OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2739      Length(0), Pack(Pack) { }
2740
2741  /// \brief Creates an expression that computes the length of
2742  /// the given parameter pack, which is already known.
2743  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2744                 SourceLocation PackLoc, SourceLocation RParenLoc,
2745                 unsigned Length)
2746  : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2747         /*TypeDependent=*/false, /*ValueDependent=*/false,
2748         /*ContainsUnexpandedParameterPack=*/false),
2749    OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2750    Length(Length), Pack(Pack) { }
2751
2752  /// \brief Create an empty expression.
2753  SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
2754
2755  /// \brief Determine the location of the 'sizeof' keyword.
2756  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2757
2758  /// \brief Determine the location of the parameter pack.
2759  SourceLocation getPackLoc() const { return PackLoc; }
2760
2761  /// \brief Determine the location of the right parenthesis.
2762  SourceLocation getRParenLoc() const { return RParenLoc; }
2763
2764  /// \brief Retrieve the parameter pack.
2765  NamedDecl *getPack() const { return Pack; }
2766
2767  /// \brief Retrieve the length of the parameter pack.
2768  ///
2769  /// This routine may only be invoked when the expression is not
2770  /// value-dependent.
2771  unsigned getPackLength() const {
2772    assert(!isValueDependent() &&
2773           "Cannot get the length of a value-dependent pack size expression");
2774    return Length;
2775  }
2776
2777  virtual SourceRange getSourceRange() const;
2778
2779  static bool classof(const Stmt *T) {
2780    return T->getStmtClass() == SizeOfPackExprClass;
2781  }
2782  static bool classof(const SizeOfPackExpr *) { return true; }
2783
2784  // Iterators
2785  virtual child_iterator child_begin();
2786  virtual child_iterator child_end();
2787};
2788
2789/// \brief Represents a reference to a non-type template parameter pack that
2790/// has been substituted with a non-template argument pack.
2791///
2792/// When a pack expansion in the source code contains multiple parameter packs
2793/// and those parameter packs correspond to different levels of template
2794/// parameter lists, this node node is used to represent a non-type template
2795/// parameter pack from an outer level, which has already had its argument pack
2796/// substituted but that still lives within a pack expansion that itself
2797/// could not be instantiated. When actually performing a substitution into
2798/// that pack expansion (e.g., when all template parameters have corresponding
2799/// arguments), this type will be replaced with the appropriate underlying
2800/// expression at the current pack substitution index.
2801class SubstNonTypeTemplateParmPackExpr : public Expr {
2802  /// \brief The non-type template parameter pack itself.
2803  NonTypeTemplateParmDecl *Param;
2804
2805  /// \brief A pointer to the set of template arguments that this
2806  /// parameter pack is instantiated with.
2807  const TemplateArgument *Arguments;
2808
2809  /// \brief The number of template arguments in \c Arguments.
2810  unsigned NumArguments;
2811
2812  /// \brief The location of the non-type template parameter pack reference.
2813  SourceLocation NameLoc;
2814
2815  friend class ASTStmtReader;
2816  friend class ASTStmtWriter;
2817
2818public:
2819  SubstNonTypeTemplateParmPackExpr(QualType T,
2820                                   NonTypeTemplateParmDecl *Param,
2821                                   SourceLocation NameLoc,
2822                                   const TemplateArgument &ArgPack);
2823
2824  SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
2825    : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
2826
2827  /// \brief Retrieve the non-type template parameter pack being substituted.
2828  NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
2829
2830  /// \brief Retrieve the location of the parameter pack name.
2831  SourceLocation getParameterPackLocation() const { return NameLoc; }
2832
2833  /// \brief Retrieve the template argument pack containing the substituted
2834  /// template arguments.
2835  TemplateArgument getArgumentPack() const;
2836
2837  virtual SourceRange getSourceRange() const;
2838
2839  static bool classof(const Stmt *T) {
2840    return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
2841  }
2842  static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
2843    return true;
2844  }
2845
2846  // Iterators
2847  virtual child_iterator child_begin();
2848  virtual child_iterator child_end();
2849};
2850
2851}  // end namespace clang
2852
2853#endif
2854