ExprCXX.h revision 1817bd483b538fd3f4530649f5cb900bad9e8a76
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
24  class CXXConstructorDecl;
25  class CXXDestructorDecl;
26  class CXXMethodDecl;
27  class CXXTemporary;
28  class 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                      SourceLocation operatorloc)
55    : CallExpr(C, CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc),
56      Operator(Op) {}
57  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
58    CallExpr(C, CXXOperatorCallExprClass, Empty) { }
59
60
61  /// getOperator - Returns the kind of overloaded operator that this
62  /// expression refers to.
63  OverloadedOperatorKind getOperator() const { return Operator; }
64  void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
65
66  /// getOperatorLoc - Returns the location of the operator symbol in
67  /// the expression. When @c getOperator()==OO_Call, this is the
68  /// location of the right parentheses; when @c
69  /// getOperator()==OO_Subscript, this is the location of the right
70  /// bracket.
71  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
72
73  virtual SourceRange getSourceRange() const;
74
75  static bool classof(const Stmt *T) {
76    return T->getStmtClass() == CXXOperatorCallExprClass;
77  }
78  static bool classof(const CXXOperatorCallExpr *) { return true; }
79};
80
81/// CXXMemberCallExpr - Represents a call to a member function that
82/// may be written either with member call syntax (e.g., "obj.func()"
83/// or "objptr->func()") or with normal function-call syntax
84/// ("func()") within a member function that ends up calling a member
85/// function. The callee in either case is a MemberExpr that contains
86/// both the object argument and the member function, while the
87/// arguments are the arguments within the parentheses (not including
88/// the object argument).
89class CXXMemberCallExpr : public CallExpr {
90public:
91  CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs,
92                    QualType t, SourceLocation rparenloc)
93    : CallExpr(C, CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) {}
94
95  CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
96    : CallExpr(C, CXXMemberCallExprClass, Empty) { }
97
98  /// getImplicitObjectArgument - Retrieves the implicit object
99  /// argument for the member call. For example, in "x.f(5)", this
100  /// operation would return "x".
101  Expr *getImplicitObjectArgument();
102
103  virtual SourceRange getSourceRange() const;
104
105  static bool classof(const Stmt *T) {
106    return T->getStmtClass() == CXXMemberCallExprClass;
107  }
108  static bool classof(const CXXMemberCallExpr *) { return true; }
109};
110
111/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
112/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
113/// const_cast.
114///
115/// This abstract class is inherited by all of the classes
116/// representing "named" casts, e.g., CXXStaticCastExpr,
117/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
118class CXXNamedCastExpr : public ExplicitCastExpr {
119private:
120  SourceLocation Loc; // the location of the casting op
121
122protected:
123  CXXNamedCastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op,
124                   CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
125                   SourceLocation l)
126    : ExplicitCastExpr(SC, ty, kind, op, BasePath, writtenTy), Loc(l) {}
127
128  explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell)
129    : ExplicitCastExpr(SC, Shell) { }
130
131public:
132  const char *getCastName() const;
133
134  /// \brief Retrieve the location of the cast operator keyword, e.g.,
135  /// "static_cast".
136  SourceLocation getOperatorLoc() const { return Loc; }
137  void setOperatorLoc(SourceLocation L) { Loc = L; }
138
139  virtual SourceRange getSourceRange() const {
140    return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
141  }
142  static bool classof(const Stmt *T) {
143    switch (T->getStmtClass()) {
144    case CXXStaticCastExprClass:
145    case CXXDynamicCastExprClass:
146    case CXXReinterpretCastExprClass:
147    case CXXConstCastExprClass:
148      return true;
149    default:
150      return false;
151    }
152  }
153  static bool classof(const CXXNamedCastExpr *) { return true; }
154};
155
156/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
157///
158/// This expression node represents a C++ static cast, e.g.,
159/// @c static_cast<int>(1.0).
160class CXXStaticCastExpr : public CXXNamedCastExpr {
161public:
162  CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op,
163                    CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
164                    SourceLocation l)
165    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, BasePath, writtenTy, l) {}
166
167  explicit CXXStaticCastExpr(EmptyShell Empty)
168    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty) { }
169
170  static bool classof(const Stmt *T) {
171    return T->getStmtClass() == CXXStaticCastExprClass;
172  }
173  static bool classof(const CXXStaticCastExpr *) { return true; }
174};
175
176/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
177/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
178/// determine how to perform the type cast.
179///
180/// This expression node represents a dynamic cast, e.g.,
181/// @c dynamic_cast<Derived*>(BasePtr).
182class CXXDynamicCastExpr : public CXXNamedCastExpr {
183public:
184  CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op,
185                     CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
186                     SourceLocation l)
187    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, BasePath,
188                       writtenTy, l) {}
189
190  explicit CXXDynamicCastExpr(EmptyShell Empty)
191    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty) { }
192
193  static bool classof(const Stmt *T) {
194    return T->getStmtClass() == CXXDynamicCastExprClass;
195  }
196  static bool classof(const CXXDynamicCastExpr *) { return true; }
197};
198
199/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
200/// [expr.reinterpret.cast]), which provides a differently-typed view
201/// of a value but performs no actual work at run time.
202///
203/// This expression node represents a reinterpret cast, e.g.,
204/// @c reinterpret_cast<int>(VoidPtr).
205class CXXReinterpretCastExpr : public CXXNamedCastExpr {
206public:
207  CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op,
208                         CXXBaseSpecifierArray BasePath,
209                         TypeSourceInfo *writtenTy, SourceLocation l)
210    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op, BasePath,
211                       writtenTy, l) {}
212
213  explicit CXXReinterpretCastExpr(EmptyShell Empty)
214    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty) { }
215
216  static bool classof(const Stmt *T) {
217    return T->getStmtClass() == CXXReinterpretCastExprClass;
218  }
219  static bool classof(const CXXReinterpretCastExpr *) { return true; }
220};
221
222/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
223/// which can remove type qualifiers but does not change the underlying value.
224///
225/// This expression node represents a const cast, e.g.,
226/// @c const_cast<char*>(PtrToConstChar).
227class CXXConstCastExpr : public CXXNamedCastExpr {
228public:
229  CXXConstCastExpr(QualType ty, Expr *op, TypeSourceInfo *writtenTy,
230                   SourceLocation l)
231    : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op,
232                       CXXBaseSpecifierArray(), writtenTy, l) {}
233
234  explicit CXXConstCastExpr(EmptyShell Empty)
235    : CXXNamedCastExpr(CXXConstCastExprClass, Empty) { }
236
237  static bool classof(const Stmt *T) {
238    return T->getStmtClass() == CXXConstCastExprClass;
239  }
240  static bool classof(const CXXConstCastExpr *) { return true; }
241};
242
243/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
244///
245class CXXBoolLiteralExpr : public Expr {
246  bool Value;
247  SourceLocation Loc;
248public:
249  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
250    Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {}
251
252  explicit CXXBoolLiteralExpr(EmptyShell Empty)
253    : Expr(CXXBoolLiteralExprClass, Empty) { }
254
255  bool getValue() const { return Value; }
256  void setValue(bool V) { Value = V; }
257
258  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
259
260  SourceLocation getLocation() const { return Loc; }
261  void setLocation(SourceLocation L) { Loc = L; }
262
263  static bool classof(const Stmt *T) {
264    return T->getStmtClass() == CXXBoolLiteralExprClass;
265  }
266  static bool classof(const CXXBoolLiteralExpr *) { return true; }
267
268  // Iterators
269  virtual child_iterator child_begin();
270  virtual child_iterator child_end();
271};
272
273/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
274class CXXNullPtrLiteralExpr : public Expr {
275  SourceLocation Loc;
276public:
277  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
278    Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {}
279
280  explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
281    : Expr(CXXNullPtrLiteralExprClass, Empty) { }
282
283  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
284
285  SourceLocation getLocation() const { return Loc; }
286  void setLocation(SourceLocation L) { Loc = L; }
287
288  static bool classof(const Stmt *T) {
289    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
290  }
291  static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
292
293  virtual child_iterator child_begin();
294  virtual child_iterator child_end();
295};
296
297/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
298/// the type_info that corresponds to the supplied type, or the (possibly
299/// dynamic) type of the supplied expression.
300///
301/// This represents code like @c typeid(int) or @c typeid(*objPtr)
302class CXXTypeidExpr : public Expr {
303private:
304  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
305  SourceRange Range;
306
307public:
308  CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
309    : Expr(CXXTypeidExprClass, Ty,
310           // typeid is never type-dependent (C++ [temp.dep.expr]p4)
311           false,
312           // typeid is value-dependent if the type or expression are dependent
313           Operand->getType()->isDependentType()),
314      Operand(Operand), Range(R) { }
315
316  CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
317    : Expr(CXXTypeidExprClass, Ty,
318        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
319        false,
320        // typeid is value-dependent if the type or expression are dependent
321        Operand->isTypeDependent() || Operand->isValueDependent()),
322      Operand(Operand), Range(R) { }
323
324  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
325
326  /// \brief Retrieves the type operand of this typeid() expression after
327  /// various required adjustments (removing reference types, cv-qualifiers).
328  QualType getTypeOperand() const;
329
330  /// \brief Retrieve source information for the type operand.
331  TypeSourceInfo *getTypeOperandSourceInfo() const {
332    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
333    return Operand.get<TypeSourceInfo *>();
334  }
335
336  Expr* getExprOperand() const {
337    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
338    return static_cast<Expr*>(Operand.get<Stmt *>());
339  }
340
341  virtual SourceRange getSourceRange() const {
342    return Range;
343  }
344  static bool classof(const Stmt *T) {
345    return T->getStmtClass() == CXXTypeidExprClass;
346  }
347  static bool classof(const CXXTypeidExpr *) { return true; }
348
349  // Iterators
350  virtual child_iterator child_begin();
351  virtual child_iterator child_end();
352};
353
354/// CXXThisExpr - Represents the "this" expression in C++, which is a
355/// pointer to the object on which the current member function is
356/// executing (C++ [expr.prim]p3). Example:
357///
358/// @code
359/// class Foo {
360/// public:
361///   void bar();
362///   void test() { this->bar(); }
363/// };
364/// @endcode
365class CXXThisExpr : public Expr {
366  SourceLocation Loc;
367  bool Implicit : 1;
368
369public:
370  CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
371    : Expr(CXXThisExprClass, Type,
372           // 'this' is type-dependent if the class type of the enclosing
373           // member function is dependent (C++ [temp.dep.expr]p2)
374           Type->isDependentType(), Type->isDependentType()),
375      Loc(L), Implicit(isImplicit) { }
376
377  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
378
379  bool isImplicit() const { return Implicit; }
380  void setImplicit(bool I) { Implicit = I; }
381
382  static bool classof(const Stmt *T) {
383    return T->getStmtClass() == CXXThisExprClass;
384  }
385  static bool classof(const CXXThisExpr *) { return true; }
386
387  // Iterators
388  virtual child_iterator child_begin();
389  virtual child_iterator child_end();
390};
391
392///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
393///  'throw' and 'throw' assignment-expression.  When
394///  assignment-expression isn't present, Op will be null.
395///
396class CXXThrowExpr : public Expr {
397  Stmt *Op;
398  SourceLocation ThrowLoc;
399public:
400  // Ty is the void type which is used as the result type of the
401  // exepression.  The l is the location of the throw keyword.  expr
402  // can by null, if the optional expression to throw isn't present.
403  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
404    Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {}
405  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
406  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
407  void setSubExpr(Expr *E) { Op = E; }
408
409  SourceLocation getThrowLoc() const { return ThrowLoc; }
410  void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
411
412  virtual SourceRange getSourceRange() const {
413    if (getSubExpr() == 0)
414      return SourceRange(ThrowLoc, ThrowLoc);
415    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
416  }
417
418  static bool classof(const Stmt *T) {
419    return T->getStmtClass() == CXXThrowExprClass;
420  }
421  static bool classof(const CXXThrowExpr *) { return true; }
422
423  // Iterators
424  virtual child_iterator child_begin();
425  virtual child_iterator child_end();
426};
427
428/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
429/// function call argument that was created from the corresponding
430/// parameter's default argument, when the call did not explicitly
431/// supply arguments for all of the parameters.
432class CXXDefaultArgExpr : public Expr {
433  /// \brief The parameter whose default is being used.
434  ///
435  /// When the bit is set, the subexpression is stored after the
436  /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
437  /// actual default expression is the subexpression.
438  llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
439
440  /// \brief The location where the default argument expression was used.
441  SourceLocation Loc;
442
443protected:
444  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
445    : Expr(SC,
446           param->hasUnparsedDefaultArg()
447             ? param->getType().getNonReferenceType()
448             : param->getDefaultArg()->getType(),
449           false, false),
450      Param(param, false), Loc(Loc) { }
451
452  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
453                    Expr *SubExpr)
454    : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc)
455  {
456    *reinterpret_cast<Expr **>(this + 1) = SubExpr;
457  }
458
459protected:
460  virtual void DoDestroy(ASTContext &C);
461
462public:
463  // Param is the parameter whose default argument is used by this
464  // expression.
465  static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
466                                   ParmVarDecl *Param) {
467    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
468  }
469
470  // Param is the parameter whose default argument is used by this
471  // expression, and SubExpr is the expression that will actually be used.
472  static CXXDefaultArgExpr *Create(ASTContext &C,
473                                   SourceLocation Loc,
474                                   ParmVarDecl *Param,
475                                   Expr *SubExpr);
476
477  // Retrieve the parameter that the argument was created from.
478  const ParmVarDecl *getParam() const { return Param.getPointer(); }
479  ParmVarDecl *getParam() { return Param.getPointer(); }
480
481  // Retrieve the actual argument to the function call.
482  const Expr *getExpr() const {
483    if (Param.getInt())
484      return *reinterpret_cast<Expr const * const*> (this + 1);
485    return getParam()->getDefaultArg();
486  }
487  Expr *getExpr() {
488    if (Param.getInt())
489      return *reinterpret_cast<Expr **> (this + 1);
490    return getParam()->getDefaultArg();
491  }
492
493  /// \brief Retrieve the location where this default argument was actually
494  /// used.
495  SourceLocation getUsedLocation() const { return Loc; }
496
497  virtual SourceRange getSourceRange() const {
498    // Default argument expressions have no representation in the
499    // source, so they have an empty source range.
500    return SourceRange();
501  }
502
503  static bool classof(const Stmt *T) {
504    return T->getStmtClass() == CXXDefaultArgExprClass;
505  }
506  static bool classof(const CXXDefaultArgExpr *) { return true; }
507
508  // Iterators
509  virtual child_iterator child_begin();
510  virtual child_iterator child_end();
511};
512
513/// CXXTemporary - Represents a C++ temporary.
514class CXXTemporary {
515  /// Destructor - The destructor that needs to be called.
516  const CXXDestructorDecl *Destructor;
517
518  CXXTemporary(const CXXDestructorDecl *destructor)
519    : Destructor(destructor) { }
520  ~CXXTemporary() { }
521
522public:
523  static CXXTemporary *Create(ASTContext &C,
524                              const CXXDestructorDecl *Destructor);
525
526  void Destroy(ASTContext &Ctx);
527
528  const CXXDestructorDecl *getDestructor() const { return Destructor; }
529};
530
531/// CXXBindTemporaryExpr - Represents binding an expression to a temporary,
532/// so its destructor can be called later.
533class CXXBindTemporaryExpr : public Expr {
534  CXXTemporary *Temp;
535
536  Stmt *SubExpr;
537
538  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr)
539   : Expr(CXXBindTemporaryExprClass, subexpr->getType(), false, false),
540     Temp(temp), SubExpr(subexpr) { }
541  ~CXXBindTemporaryExpr() { }
542
543protected:
544  virtual void DoDestroy(ASTContext &C);
545
546public:
547  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
548                                      Expr* SubExpr);
549
550  CXXTemporary *getTemporary() { return Temp; }
551  const CXXTemporary *getTemporary() const { return Temp; }
552
553  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
554  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
555  void setSubExpr(Expr *E) { SubExpr = E; }
556
557  virtual SourceRange getSourceRange() const {
558    return SubExpr->getSourceRange();
559  }
560
561  // Implement isa/cast/dyncast/etc.
562  static bool classof(const Stmt *T) {
563    return T->getStmtClass() == CXXBindTemporaryExprClass;
564  }
565  static bool classof(const CXXBindTemporaryExpr *) { return true; }
566
567  // Iterators
568  virtual child_iterator child_begin();
569  virtual child_iterator child_end();
570};
571
572/// CXXBindReferenceExpr - Represents binding an expression to a reference.
573/// In the example:
574///
575/// const int &i = 10;
576///
577/// a bind reference expression is inserted to indicate that 10 is bound to
578/// a reference. (Ans also that a temporary needs to be created to hold the
579/// value).
580class CXXBindReferenceExpr : public Expr {
581  // SubExpr - The expression being bound.
582  Stmt *SubExpr;
583
584  // ExtendsLifetime - Whether binding this reference extends the lifetime of
585  // the expression being bound. FIXME: Add C++ reference.
586  bool ExtendsLifetime;
587
588  /// RequiresTemporaryCopy - Whether binding the subexpression requires a
589  /// temporary copy.
590  bool RequiresTemporaryCopy;
591
592  CXXBindReferenceExpr(Expr *subexpr, bool ExtendsLifetime,
593                       bool RequiresTemporaryCopy)
594  : Expr(CXXBindReferenceExprClass, subexpr->getType(), false, false),
595    SubExpr(subexpr), ExtendsLifetime(ExtendsLifetime),
596    RequiresTemporaryCopy(RequiresTemporaryCopy) { }
597  ~CXXBindReferenceExpr() { }
598
599protected:
600  virtual void DoDestroy(ASTContext &C);
601
602public:
603  static CXXBindReferenceExpr *Create(ASTContext &C, Expr *SubExpr,
604                                      bool ExtendsLifetime,
605                                      bool RequiresTemporaryCopy);
606
607  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
608  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
609  void setSubExpr(Expr *E) { SubExpr = E; }
610
611  virtual SourceRange getSourceRange() const {
612    return SubExpr->getSourceRange();
613  }
614
615  /// requiresTemporaryCopy - Whether binding the subexpression requires a
616  /// temporary copy.
617  bool requiresTemporaryCopy() const { return RequiresTemporaryCopy; }
618
619  // extendsLifetime - Whether binding this reference extends the lifetime of
620  // the expression being bound. FIXME: Add C++ reference.
621  bool extendsLifetime() { return ExtendsLifetime; }
622
623  // Implement isa/cast/dyncast/etc.
624  static bool classof(const Stmt *T) {
625    return T->getStmtClass() == CXXBindReferenceExprClass;
626  }
627  static bool classof(const CXXBindReferenceExpr *) { return true; }
628
629  // Iterators
630  virtual child_iterator child_begin();
631  virtual child_iterator child_end();
632};
633
634/// CXXConstructExpr - Represents a call to a C++ constructor.
635class CXXConstructExpr : public Expr {
636public:
637  enum ConstructionKind {
638    CK_Complete,
639    CK_NonVirtualBase,
640    CK_VirtualBase
641  };
642
643private:
644  CXXConstructorDecl *Constructor;
645
646  SourceLocation Loc;
647  bool Elidable : 1;
648  bool ZeroInitialization : 1;
649  unsigned ConstructKind : 2;
650  Stmt **Args;
651  unsigned NumArgs;
652
653protected:
654  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
655                   SourceLocation Loc,
656                   CXXConstructorDecl *d, bool elidable,
657                   Expr **args, unsigned numargs,
658                   bool ZeroInitialization = false,
659                   ConstructionKind ConstructKind = CK_Complete);
660  ~CXXConstructExpr() { }
661
662  virtual void DoDestroy(ASTContext &C);
663
664public:
665  /// \brief Construct an empty C++ construction expression that will store
666  /// \p numargs arguments.
667  CXXConstructExpr(EmptyShell Empty, ASTContext &C, unsigned numargs);
668
669  static CXXConstructExpr *Create(ASTContext &C, QualType T,
670                                  SourceLocation Loc,
671                                  CXXConstructorDecl *D, bool Elidable,
672                                  Expr **Args, unsigned NumArgs,
673                                  bool ZeroInitialization = false,
674                                  ConstructionKind ConstructKind = CK_Complete);
675
676
677  CXXConstructorDecl* getConstructor() const { return Constructor; }
678  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
679
680  SourceLocation getLocation() const { return Loc; }
681  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
682
683  /// \brief Whether this construction is elidable.
684  bool isElidable() const { return Elidable; }
685  void setElidable(bool E) { Elidable = E; }
686
687  /// \brief Whether this construction first requires
688  /// zero-initialization before the initializer is called.
689  bool requiresZeroInitialization() const { return ZeroInitialization; }
690  void setRequiresZeroInitialization(bool ZeroInit) {
691    ZeroInitialization = ZeroInit;
692  }
693
694  /// \brief Determines whether this constructor is actually constructing
695  /// a base class (rather than a complete object).
696  ConstructionKind getConstructionKind() const {
697    return (ConstructionKind)ConstructKind;
698  }
699  void setConstructionKind(ConstructionKind CK) {
700    ConstructKind = CK;
701  }
702
703  typedef ExprIterator arg_iterator;
704  typedef ConstExprIterator const_arg_iterator;
705
706  arg_iterator arg_begin() { return Args; }
707  arg_iterator arg_end() { return Args + NumArgs; }
708  const_arg_iterator arg_begin() const { return Args; }
709  const_arg_iterator arg_end() const { return Args + NumArgs; }
710
711  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
712  unsigned getNumArgs() const { return NumArgs; }
713
714  /// getArg - Return the specified argument.
715  Expr *getArg(unsigned Arg) {
716    assert(Arg < NumArgs && "Arg access out of range!");
717    return cast<Expr>(Args[Arg]);
718  }
719  const Expr *getArg(unsigned Arg) const {
720    assert(Arg < NumArgs && "Arg access out of range!");
721    return cast<Expr>(Args[Arg]);
722  }
723
724  /// setArg - Set the specified argument.
725  void setArg(unsigned Arg, Expr *ArgExpr) {
726    assert(Arg < NumArgs && "Arg access out of range!");
727    Args[Arg] = ArgExpr;
728  }
729
730  virtual SourceRange getSourceRange() const;
731
732  static bool classof(const Stmt *T) {
733    return T->getStmtClass() == CXXConstructExprClass ||
734      T->getStmtClass() == CXXTemporaryObjectExprClass;
735  }
736  static bool classof(const CXXConstructExpr *) { return true; }
737
738  // Iterators
739  virtual child_iterator child_begin();
740  virtual child_iterator child_end();
741};
742
743/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
744/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
745/// x = int(0.5);
746class CXXFunctionalCastExpr : public ExplicitCastExpr {
747  SourceLocation TyBeginLoc;
748  SourceLocation RParenLoc;
749public:
750  CXXFunctionalCastExpr(QualType ty, TypeSourceInfo *writtenTy,
751                        SourceLocation tyBeginLoc, CastKind kind,
752                        Expr *castExpr, CXXBaseSpecifierArray BasePath,
753                        SourceLocation rParenLoc)
754    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr,
755                       BasePath, writtenTy),
756      TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
757
758  explicit CXXFunctionalCastExpr(EmptyShell Shell)
759    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell) { }
760
761  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
762  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
763  SourceLocation getRParenLoc() const { return RParenLoc; }
764  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
765
766  virtual SourceRange getSourceRange() const {
767    return SourceRange(TyBeginLoc, RParenLoc);
768  }
769  static bool classof(const Stmt *T) {
770    return T->getStmtClass() == CXXFunctionalCastExprClass;
771  }
772  static bool classof(const CXXFunctionalCastExpr *) { return true; }
773};
774
775/// @brief Represents a C++ functional cast expression that builds a
776/// temporary object.
777///
778/// This expression type represents a C++ "functional" cast
779/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
780/// constructor to build a temporary object. If N == 0 but no
781/// constructor will be called (because the functional cast is
782/// performing a value-initialized an object whose class type has no
783/// user-declared constructors), CXXZeroInitValueExpr will represent
784/// the functional cast. Finally, with N == 1 arguments the functional
785/// cast expression will be represented by CXXFunctionalCastExpr.
786/// Example:
787/// @code
788/// struct X { X(int, float); }
789///
790/// X create_X() {
791///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
792/// };
793/// @endcode
794class CXXTemporaryObjectExpr : public CXXConstructExpr {
795  SourceLocation TyBeginLoc;
796  SourceLocation RParenLoc;
797
798public:
799  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
800                         QualType writtenTy, SourceLocation tyBeginLoc,
801                         Expr **Args,unsigned NumArgs,
802                         SourceLocation rParenLoc,
803                         bool ZeroInitialization = false);
804
805  ~CXXTemporaryObjectExpr() { }
806
807  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
808  SourceLocation getRParenLoc() const { return RParenLoc; }
809
810  virtual SourceRange getSourceRange() const {
811    return SourceRange(TyBeginLoc, RParenLoc);
812  }
813  static bool classof(const Stmt *T) {
814    return T->getStmtClass() == CXXTemporaryObjectExprClass;
815  }
816  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
817};
818
819/// CXXZeroInitValueExpr - [C++ 5.2.3p2]
820/// Expression "T()" which creates a value-initialized rvalue of type
821/// T, which is either a non-class type or a class type without any
822/// user-defined constructors.
823///
824class CXXZeroInitValueExpr : public Expr {
825  SourceLocation TyBeginLoc;
826  SourceLocation RParenLoc;
827
828public:
829  CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc,
830                       SourceLocation rParenLoc ) :
831    Expr(CXXZeroInitValueExprClass, ty, false, false),
832    TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
833
834  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
835  SourceLocation getRParenLoc() const { return RParenLoc; }
836
837  /// @brief Whether this initialization expression was
838  /// implicitly-generated.
839  bool isImplicit() const {
840    return TyBeginLoc.isInvalid() && RParenLoc.isInvalid();
841  }
842
843  virtual SourceRange getSourceRange() const {
844    return SourceRange(TyBeginLoc, RParenLoc);
845  }
846
847  static bool classof(const Stmt *T) {
848    return T->getStmtClass() == CXXZeroInitValueExprClass;
849  }
850  static bool classof(const CXXZeroInitValueExpr *) { return true; }
851
852  // Iterators
853  virtual child_iterator child_begin();
854  virtual child_iterator child_end();
855};
856
857/// CXXNewExpr - A new expression for memory allocation and constructor calls,
858/// e.g: "new CXXNewExpr(foo)".
859class CXXNewExpr : public Expr {
860  // Was the usage ::new, i.e. is the global new to be used?
861  bool GlobalNew : 1;
862  // Was the form (type-id) used? Otherwise, it was new-type-id.
863  bool ParenTypeId : 1;
864  // Is there an initializer? If not, built-ins are uninitialized, else they're
865  // value-initialized.
866  bool Initializer : 1;
867  // Do we allocate an array? If so, the first SubExpr is the size expression.
868  bool Array : 1;
869  // The number of placement new arguments.
870  unsigned NumPlacementArgs : 14;
871  // The number of constructor arguments. This may be 1 even for non-class
872  // types; use the pseudo copy constructor.
873  unsigned NumConstructorArgs : 14;
874  // Contains an optional array size expression, any number of optional
875  // placement arguments, and any number of optional constructor arguments,
876  // in that order.
877  Stmt **SubExprs;
878  // Points to the allocation function used.
879  FunctionDecl *OperatorNew;
880  // Points to the deallocation function used in case of error. May be null.
881  FunctionDecl *OperatorDelete;
882  // Points to the constructor used. Cannot be null if AllocType is a record;
883  // it would still point at the default constructor (even an implicit one).
884  // Must be null for all other types.
885  CXXConstructorDecl *Constructor;
886
887  SourceLocation StartLoc;
888  SourceLocation EndLoc;
889
890public:
891  CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
892             Expr **placementArgs, unsigned numPlaceArgs, bool ParenTypeId,
893             Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
894             Expr **constructorArgs, unsigned numConsArgs,
895             FunctionDecl *operatorDelete, QualType ty,
896             SourceLocation startLoc, SourceLocation endLoc);
897
898  virtual void DoDestroy(ASTContext &C);
899
900  QualType getAllocatedType() const {
901    assert(getType()->isPointerType());
902    return getType()->getAs<PointerType>()->getPointeeType();
903  }
904
905  FunctionDecl *getOperatorNew() const { return OperatorNew; }
906  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
907  CXXConstructorDecl *getConstructor() const { return Constructor; }
908
909  bool isArray() const { return Array; }
910  Expr *getArraySize() {
911    return Array ? cast<Expr>(SubExprs[0]) : 0;
912  }
913  const Expr *getArraySize() const {
914    return Array ? cast<Expr>(SubExprs[0]) : 0;
915  }
916
917  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
918  Expr *getPlacementArg(unsigned i) {
919    assert(i < NumPlacementArgs && "Index out of range");
920    return cast<Expr>(SubExprs[Array + i]);
921  }
922  const Expr *getPlacementArg(unsigned i) const {
923    assert(i < NumPlacementArgs && "Index out of range");
924    return cast<Expr>(SubExprs[Array + i]);
925  }
926
927  bool isGlobalNew() const { return GlobalNew; }
928  bool isParenTypeId() const { return ParenTypeId; }
929  bool hasInitializer() const { return Initializer; }
930
931  unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
932  Expr *getConstructorArg(unsigned i) {
933    assert(i < NumConstructorArgs && "Index out of range");
934    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
935  }
936  const Expr *getConstructorArg(unsigned i) const {
937    assert(i < NumConstructorArgs && "Index out of range");
938    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
939  }
940
941  typedef ExprIterator arg_iterator;
942  typedef ConstExprIterator const_arg_iterator;
943
944  arg_iterator placement_arg_begin() {
945    return SubExprs + Array;
946  }
947  arg_iterator placement_arg_end() {
948    return SubExprs + Array + getNumPlacementArgs();
949  }
950  const_arg_iterator placement_arg_begin() const {
951    return SubExprs + Array;
952  }
953  const_arg_iterator placement_arg_end() const {
954    return SubExprs + Array + getNumPlacementArgs();
955  }
956
957  arg_iterator constructor_arg_begin() {
958    return SubExprs + Array + getNumPlacementArgs();
959  }
960  arg_iterator constructor_arg_end() {
961    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
962  }
963  const_arg_iterator constructor_arg_begin() const {
964    return SubExprs + Array + getNumPlacementArgs();
965  }
966  const_arg_iterator constructor_arg_end() const {
967    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
968  }
969
970  virtual SourceRange getSourceRange() const {
971    return SourceRange(StartLoc, EndLoc);
972  }
973
974  static bool classof(const Stmt *T) {
975    return T->getStmtClass() == CXXNewExprClass;
976  }
977  static bool classof(const CXXNewExpr *) { return true; }
978
979  // Iterators
980  virtual child_iterator child_begin();
981  virtual child_iterator child_end();
982};
983
984/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
985/// calls, e.g. "delete[] pArray".
986class CXXDeleteExpr : public Expr {
987  // Is this a forced global delete, i.e. "::delete"?
988  bool GlobalDelete : 1;
989  // Is this the array form of delete, i.e. "delete[]"?
990  bool ArrayForm : 1;
991  // Points to the operator delete overload that is used. Could be a member.
992  FunctionDecl *OperatorDelete;
993  // The pointer expression to be deleted.
994  Stmt *Argument;
995  // Location of the expression.
996  SourceLocation Loc;
997public:
998  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
999                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1000    : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete),
1001      ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg),
1002      Loc(loc) { }
1003
1004  bool isGlobalDelete() const { return GlobalDelete; }
1005  bool isArrayForm() const { return ArrayForm; }
1006
1007  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1008
1009  Expr *getArgument() { return cast<Expr>(Argument); }
1010  const Expr *getArgument() const { return cast<Expr>(Argument); }
1011
1012  virtual SourceRange getSourceRange() const {
1013    return SourceRange(Loc, Argument->getLocEnd());
1014  }
1015
1016  static bool classof(const Stmt *T) {
1017    return T->getStmtClass() == CXXDeleteExprClass;
1018  }
1019  static bool classof(const CXXDeleteExpr *) { return true; }
1020
1021  // Iterators
1022  virtual child_iterator child_begin();
1023  virtual child_iterator child_end();
1024};
1025
1026/// \brief Structure used to store the type being destroyed by a
1027/// pseudo-destructor expression.
1028class PseudoDestructorTypeStorage {
1029  /// \brief Either the type source information or the name of the type, if
1030  /// it couldn't be resolved due to type-dependence.
1031  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1032
1033  /// \brief The starting source location of the pseudo-destructor type.
1034  SourceLocation Location;
1035
1036public:
1037  PseudoDestructorTypeStorage() { }
1038
1039  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1040    : Type(II), Location(Loc) { }
1041
1042  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1043
1044  TypeSourceInfo *getTypeSourceInfo() const {
1045    return Type.dyn_cast<TypeSourceInfo *>();
1046  }
1047
1048  IdentifierInfo *getIdentifier() const {
1049    return Type.dyn_cast<IdentifierInfo *>();
1050  }
1051
1052  SourceLocation getLocation() const { return Location; }
1053};
1054
1055/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1056///
1057/// A pseudo-destructor is an expression that looks like a member access to a
1058/// destructor of a scalar type, except that scalar types don't have
1059/// destructors. For example:
1060///
1061/// \code
1062/// typedef int T;
1063/// void f(int *p) {
1064///   p->T::~T();
1065/// }
1066/// \endcode
1067///
1068/// Pseudo-destructors typically occur when instantiating templates such as:
1069///
1070/// \code
1071/// template<typename T>
1072/// void destroy(T* ptr) {
1073///   ptr->T::~T();
1074/// }
1075/// \endcode
1076///
1077/// for scalar types. A pseudo-destructor expression has no run-time semantics
1078/// beyond evaluating the base expression.
1079class CXXPseudoDestructorExpr : public Expr {
1080  /// \brief The base expression (that is being destroyed).
1081  Stmt *Base;
1082
1083  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1084  /// period ('.').
1085  bool IsArrow : 1;
1086
1087  /// \brief The location of the '.' or '->' operator.
1088  SourceLocation OperatorLoc;
1089
1090  /// \brief The nested-name-specifier that follows the operator, if present.
1091  NestedNameSpecifier *Qualifier;
1092
1093  /// \brief The source range that covers the nested-name-specifier, if
1094  /// present.
1095  SourceRange QualifierRange;
1096
1097  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1098  /// expression.
1099  TypeSourceInfo *ScopeType;
1100
1101  /// \brief The location of the '::' in a qualified pseudo-destructor
1102  /// expression.
1103  SourceLocation ColonColonLoc;
1104
1105  /// \brief The location of the '~'.
1106  SourceLocation TildeLoc;
1107
1108  /// \brief The type being destroyed, or its name if we were unable to
1109  /// resolve the name.
1110  PseudoDestructorTypeStorage DestroyedType;
1111
1112public:
1113  CXXPseudoDestructorExpr(ASTContext &Context,
1114                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1115                          NestedNameSpecifier *Qualifier,
1116                          SourceRange QualifierRange,
1117                          TypeSourceInfo *ScopeType,
1118                          SourceLocation ColonColonLoc,
1119                          SourceLocation TildeLoc,
1120                          PseudoDestructorTypeStorage DestroyedType)
1121    : Expr(CXXPseudoDestructorExprClass,
1122           Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
1123                                                          false, 0, false,
1124                                                          false, 0, 0,
1125                                                      FunctionType::ExtInfo())),
1126           /*isTypeDependent=*/(Base->isTypeDependent() ||
1127            (DestroyedType.getTypeSourceInfo() &&
1128              DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
1129           /*isValueDependent=*/Base->isValueDependent()),
1130      Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
1131      OperatorLoc(OperatorLoc), Qualifier(Qualifier),
1132      QualifierRange(QualifierRange),
1133      ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
1134      DestroyedType(DestroyedType) { }
1135
1136  void setBase(Expr *E) { Base = E; }
1137  Expr *getBase() const { return cast<Expr>(Base); }
1138
1139  /// \brief Determines whether this member expression actually had
1140  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1141  /// x->Base::foo.
1142  bool hasQualifier() const { return Qualifier != 0; }
1143
1144  /// \brief If the member name was qualified, retrieves the source range of
1145  /// the nested-name-specifier that precedes the member name. Otherwise,
1146  /// returns an empty source range.
1147  SourceRange getQualifierRange() const { return QualifierRange; }
1148
1149  /// \brief If the member name was qualified, retrieves the
1150  /// nested-name-specifier that precedes the member name. Otherwise, returns
1151  /// NULL.
1152  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1153
1154  /// \brief Determine whether this pseudo-destructor expression was written
1155  /// using an '->' (otherwise, it used a '.').
1156  bool isArrow() const { return IsArrow; }
1157  void setArrow(bool A) { IsArrow = A; }
1158
1159  /// \brief Retrieve the location of the '.' or '->' operator.
1160  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1161
1162  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1163  /// expression.
1164  ///
1165  /// Pseudo-destructor expressions can have extra qualification within them
1166  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1167  /// Here, if the object type of the expression is (or may be) a scalar type,
1168  /// \p T may also be a scalar type and, therefore, cannot be part of a
1169  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1170  /// destructor expression.
1171  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1172
1173  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1174  /// expression.
1175  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1176
1177  /// \brief Retrieve the location of the '~'.
1178  SourceLocation getTildeLoc() const { return TildeLoc; }
1179
1180  /// \brief Retrieve the source location information for the type
1181  /// being destroyed.
1182  ///
1183  /// This type-source information is available for non-dependent
1184  /// pseudo-destructor expressions and some dependent pseudo-destructor
1185  /// expressions. Returns NULL if we only have the identifier for a
1186  /// dependent pseudo-destructor expression.
1187  TypeSourceInfo *getDestroyedTypeInfo() const {
1188    return DestroyedType.getTypeSourceInfo();
1189  }
1190
1191  /// \brief In a dependent pseudo-destructor expression for which we do not
1192  /// have full type information on the destroyed type, provides the name
1193  /// of the destroyed type.
1194  IdentifierInfo *getDestroyedTypeIdentifier() const {
1195    return DestroyedType.getIdentifier();
1196  }
1197
1198  /// \brief Retrieve the type being destroyed.
1199  QualType getDestroyedType() const;
1200
1201  /// \brief Retrieve the starting location of the type being destroyed.
1202  SourceLocation getDestroyedTypeLoc() const {
1203    return DestroyedType.getLocation();
1204  }
1205
1206  virtual SourceRange getSourceRange() const;
1207
1208  static bool classof(const Stmt *T) {
1209    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1210  }
1211  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1212
1213  // Iterators
1214  virtual child_iterator child_begin();
1215  virtual child_iterator child_end();
1216};
1217
1218/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1219/// implementation of TR1/C++0x type trait templates.
1220/// Example:
1221/// __is_pod(int) == true
1222/// __is_enum(std::string) == false
1223class UnaryTypeTraitExpr : public Expr {
1224  /// UTT - The trait.
1225  UnaryTypeTrait UTT;
1226
1227  /// Loc - The location of the type trait keyword.
1228  SourceLocation Loc;
1229
1230  /// RParen - The location of the closing paren.
1231  SourceLocation RParen;
1232
1233  /// QueriedType - The type we're testing.
1234  QualType QueriedType;
1235
1236public:
1237  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried,
1238                     SourceLocation rparen, QualType ty)
1239    : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
1240      UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
1241
1242  virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1243
1244  UnaryTypeTrait getTrait() const { return UTT; }
1245
1246  QualType getQueriedType() const { return QueriedType; }
1247
1248  bool EvaluateTrait(ASTContext&) const;
1249
1250  static bool classof(const Stmt *T) {
1251    return T->getStmtClass() == UnaryTypeTraitExprClass;
1252  }
1253  static bool classof(const UnaryTypeTraitExpr *) { return true; }
1254
1255  // Iterators
1256  virtual child_iterator child_begin();
1257  virtual child_iterator child_end();
1258};
1259
1260/// \brief A reference to an overloaded function set, either an
1261/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1262class OverloadExpr : public Expr {
1263  /// The results.  These are undesugared, which is to say, they may
1264  /// include UsingShadowDecls.  Access is relative to the naming
1265  /// class.
1266  UnresolvedSet<4> Results;
1267
1268  /// The common name of these declarations.
1269  DeclarationName Name;
1270
1271  /// The scope specifier, if any.
1272  NestedNameSpecifier *Qualifier;
1273
1274  /// The source range of the scope specifier.
1275  SourceRange QualifierRange;
1276
1277  /// The location of the name.
1278  SourceLocation NameLoc;
1279
1280  /// True if the name was a template-id.
1281  bool HasExplicitTemplateArgs;
1282
1283protected:
1284  OverloadExpr(StmtClass K, QualType T, bool Dependent,
1285               NestedNameSpecifier *Qualifier, SourceRange QRange,
1286               DeclarationName Name, SourceLocation NameLoc,
1287               bool HasTemplateArgs)
1288    : Expr(K, T, Dependent, Dependent),
1289      Name(Name), Qualifier(Qualifier), QualifierRange(QRange),
1290      NameLoc(NameLoc), HasExplicitTemplateArgs(HasTemplateArgs)
1291  {}
1292
1293public:
1294  /// Computes whether an unresolved lookup on the given declarations
1295  /// and optional template arguments is type- and value-dependent.
1296  static bool ComputeDependence(UnresolvedSetIterator Begin,
1297                                UnresolvedSetIterator End,
1298                                const TemplateArgumentListInfo *Args);
1299
1300  /// Finds the overloaded expression in the given expression of
1301  /// OverloadTy.
1302  ///
1303  /// \return the expression (which must be there) and true if it is
1304  /// within an address-of operator.
1305  static llvm::PointerIntPair<OverloadExpr*,1> find(Expr *E) {
1306    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1307
1308    bool op = false;
1309    E = E->IgnoreParens();
1310    if (isa<UnaryOperator>(E))
1311      op = true, E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
1312    return llvm::PointerIntPair<OverloadExpr*,1>(cast<OverloadExpr>(E), op);
1313  }
1314
1315  void addDecls(UnresolvedSetIterator Begin, UnresolvedSetIterator End) {
1316    Results.append(Begin, End);
1317  }
1318
1319  /// Gets the naming class of this lookup, if any.
1320  CXXRecordDecl *getNamingClass() const;
1321
1322  typedef UnresolvedSetImpl::iterator decls_iterator;
1323  decls_iterator decls_begin() const { return Results.begin(); }
1324  decls_iterator decls_end() const { return Results.end(); }
1325
1326  /// Gets the decls as an unresolved set.
1327  const UnresolvedSetImpl &getDecls() { return Results; }
1328
1329  /// Gets the number of declarations in the unresolved set.
1330  unsigned getNumDecls() const { return Results.size(); }
1331
1332  /// Gets the name looked up.
1333  DeclarationName getName() const { return Name; }
1334  void setName(DeclarationName N) { Name = N; }
1335
1336  /// Gets the location of the name.
1337  SourceLocation getNameLoc() const { return NameLoc; }
1338  void setNameLoc(SourceLocation Loc) { NameLoc = Loc; }
1339
1340  /// Fetches the nested-name qualifier, if one was given.
1341  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1342
1343  /// Fetches the range of the nested-name qualifier.
1344  SourceRange getQualifierRange() const { return QualifierRange; }
1345
1346  /// \brief Determines whether this expression had an explicit
1347  /// template argument list, e.g. f<int>.
1348  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1349
1350  ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
1351
1352  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1353    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1354  }
1355
1356  ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1357    if (hasExplicitTemplateArgs())
1358      return &getExplicitTemplateArgs();
1359    return 0;
1360  }
1361
1362  static bool classof(const Stmt *T) {
1363    return T->getStmtClass() == UnresolvedLookupExprClass ||
1364           T->getStmtClass() == UnresolvedMemberExprClass;
1365  }
1366  static bool classof(const OverloadExpr *) { return true; }
1367};
1368
1369/// \brief A reference to a name which we were able to look up during
1370/// parsing but could not resolve to a specific declaration.  This
1371/// arises in several ways:
1372///   * we might be waiting for argument-dependent lookup
1373///   * the name might resolve to an overloaded function
1374/// and eventually:
1375///   * the lookup might have included a function template
1376/// These never include UnresolvedUsingValueDecls, which are always
1377/// class members and therefore appear only in
1378/// UnresolvedMemberLookupExprs.
1379class UnresolvedLookupExpr : public OverloadExpr {
1380  /// True if these lookup results should be extended by
1381  /// argument-dependent lookup if this is the operand of a function
1382  /// call.
1383  bool RequiresADL;
1384
1385  /// True if these lookup results are overloaded.  This is pretty
1386  /// trivially rederivable if we urgently need to kill this field.
1387  bool Overloaded;
1388
1389  /// The naming class (C++ [class.access.base]p5) of the lookup, if
1390  /// any.  This can generally be recalculated from the context chain,
1391  /// but that can be fairly expensive for unqualified lookups.  If we
1392  /// want to improve memory use here, this could go in a union
1393  /// against the qualified-lookup bits.
1394  CXXRecordDecl *NamingClass;
1395
1396  UnresolvedLookupExpr(QualType T, bool Dependent, CXXRecordDecl *NamingClass,
1397                       NestedNameSpecifier *Qualifier, SourceRange QRange,
1398                       DeclarationName Name, SourceLocation NameLoc,
1399                       bool RequiresADL, bool Overloaded, bool HasTemplateArgs)
1400    : OverloadExpr(UnresolvedLookupExprClass, T, Dependent, Qualifier, QRange,
1401                   Name, NameLoc, HasTemplateArgs),
1402      RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1403  {}
1404
1405public:
1406  static UnresolvedLookupExpr *Create(ASTContext &C,
1407                                      bool Dependent,
1408                                      CXXRecordDecl *NamingClass,
1409                                      NestedNameSpecifier *Qualifier,
1410                                      SourceRange QualifierRange,
1411                                      DeclarationName Name,
1412                                      SourceLocation NameLoc,
1413                                      bool ADL, bool Overloaded) {
1414    return new(C) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy,
1415                                       Dependent, NamingClass,
1416                                       Qualifier, QualifierRange,
1417                                       Name, NameLoc, ADL, Overloaded, false);
1418  }
1419
1420  static UnresolvedLookupExpr *Create(ASTContext &C,
1421                                      bool Dependent,
1422                                      CXXRecordDecl *NamingClass,
1423                                      NestedNameSpecifier *Qualifier,
1424                                      SourceRange QualifierRange,
1425                                      DeclarationName Name,
1426                                      SourceLocation NameLoc,
1427                                      bool ADL,
1428                                      const TemplateArgumentListInfo &Args);
1429
1430  /// True if this declaration should be extended by
1431  /// argument-dependent lookup.
1432  bool requiresADL() const { return RequiresADL; }
1433
1434  /// True if this lookup is overloaded.
1435  bool isOverloaded() const { return Overloaded; }
1436
1437  /// Gets the 'naming class' (in the sense of C++0x
1438  /// [class.access.base]p5) of the lookup.  This is the scope
1439  /// that was looked in to find these results.
1440  CXXRecordDecl *getNamingClass() const { return NamingClass; }
1441
1442  // Note that, inconsistently with the explicit-template-argument AST
1443  // nodes, users are *forbidden* from calling these methods on objects
1444  // without explicit template arguments.
1445
1446  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1447    assert(hasExplicitTemplateArgs());
1448    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1449  }
1450
1451  /// Gets a reference to the explicit template argument list.
1452  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1453    assert(hasExplicitTemplateArgs());
1454    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1455  }
1456
1457  /// \brief Copies the template arguments (if present) into the given
1458  /// structure.
1459  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1460    getExplicitTemplateArgs().copyInto(List);
1461  }
1462
1463  SourceLocation getLAngleLoc() const {
1464    return getExplicitTemplateArgs().LAngleLoc;
1465  }
1466
1467  SourceLocation getRAngleLoc() const {
1468    return getExplicitTemplateArgs().RAngleLoc;
1469  }
1470
1471  TemplateArgumentLoc const *getTemplateArgs() const {
1472    return getExplicitTemplateArgs().getTemplateArgs();
1473  }
1474
1475  unsigned getNumTemplateArgs() const {
1476    return getExplicitTemplateArgs().NumTemplateArgs;
1477  }
1478
1479  virtual SourceRange getSourceRange() const {
1480    SourceRange Range(getNameLoc());
1481    if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
1482    if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
1483    return Range;
1484  }
1485
1486  virtual StmtIterator child_begin();
1487  virtual StmtIterator child_end();
1488
1489  static bool classof(const Stmt *T) {
1490    return T->getStmtClass() == UnresolvedLookupExprClass;
1491  }
1492  static bool classof(const UnresolvedLookupExpr *) { return true; }
1493};
1494
1495/// \brief A qualified reference to a name whose declaration cannot
1496/// yet be resolved.
1497///
1498/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1499/// it expresses a reference to a declaration such as
1500/// X<T>::value. The difference, however, is that an
1501/// DependentScopeDeclRefExpr node is used only within C++ templates when
1502/// the qualification (e.g., X<T>::) refers to a dependent type. In
1503/// this case, X<T>::value cannot resolve to a declaration because the
1504/// declaration will differ from on instantiation of X<T> to the
1505/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1506/// qualifier (X<T>::) and the name of the entity being referenced
1507/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1508/// declaration can be found.
1509class DependentScopeDeclRefExpr : public Expr {
1510  /// The name of the entity we will be referencing.
1511  DeclarationName Name;
1512
1513  /// Location of the name of the declaration we're referencing.
1514  SourceLocation Loc;
1515
1516  /// QualifierRange - The source range that covers the
1517  /// nested-name-specifier.
1518  SourceRange QualifierRange;
1519
1520  /// \brief The nested-name-specifier that qualifies this unresolved
1521  /// declaration name.
1522  NestedNameSpecifier *Qualifier;
1523
1524  /// \brief Whether the name includes explicit template arguments.
1525  bool HasExplicitTemplateArgs;
1526
1527  DependentScopeDeclRefExpr(QualType T,
1528                            NestedNameSpecifier *Qualifier,
1529                            SourceRange QualifierRange,
1530                            DeclarationName Name,
1531                            SourceLocation NameLoc,
1532                            bool HasExplicitTemplateArgs)
1533    : Expr(DependentScopeDeclRefExprClass, T, true, true),
1534      Name(Name), Loc(NameLoc),
1535      QualifierRange(QualifierRange), Qualifier(Qualifier),
1536      HasExplicitTemplateArgs(HasExplicitTemplateArgs)
1537  {}
1538
1539public:
1540  static DependentScopeDeclRefExpr *Create(ASTContext &C,
1541                                           NestedNameSpecifier *Qualifier,
1542                                           SourceRange QualifierRange,
1543                                           DeclarationName Name,
1544                                           SourceLocation NameLoc,
1545                              const TemplateArgumentListInfo *TemplateArgs = 0);
1546
1547  /// \brief Retrieve the name that this expression refers to.
1548  DeclarationName getDeclName() const { return Name; }
1549
1550  /// \brief Retrieve the location of the name within the expression.
1551  SourceLocation getLocation() const { return Loc; }
1552
1553  /// \brief Retrieve the source range of the nested-name-specifier.
1554  SourceRange getQualifierRange() const { return QualifierRange; }
1555
1556  /// \brief Retrieve the nested-name-specifier that qualifies this
1557  /// declaration.
1558  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1559
1560  /// Determines whether this lookup had explicit template arguments.
1561  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1562
1563  // Note that, inconsistently with the explicit-template-argument AST
1564  // nodes, users are *forbidden* from calling these methods on objects
1565  // without explicit template arguments.
1566
1567  /// Gets a reference to the explicit template argument list.
1568  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1569    assert(hasExplicitTemplateArgs());
1570    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1571  }
1572
1573  /// \brief Copies the template arguments (if present) into the given
1574  /// structure.
1575  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1576    getExplicitTemplateArgs().copyInto(List);
1577  }
1578
1579  SourceLocation getLAngleLoc() const {
1580    return getExplicitTemplateArgs().LAngleLoc;
1581  }
1582
1583  SourceLocation getRAngleLoc() const {
1584    return getExplicitTemplateArgs().RAngleLoc;
1585  }
1586
1587  TemplateArgumentLoc const *getTemplateArgs() const {
1588    return getExplicitTemplateArgs().getTemplateArgs();
1589  }
1590
1591  unsigned getNumTemplateArgs() const {
1592    return getExplicitTemplateArgs().NumTemplateArgs;
1593  }
1594
1595  virtual SourceRange getSourceRange() const {
1596    SourceRange Range(QualifierRange.getBegin(), getLocation());
1597    if (hasExplicitTemplateArgs())
1598      Range.setEnd(getRAngleLoc());
1599    return Range;
1600  }
1601
1602  static bool classof(const Stmt *T) {
1603    return T->getStmtClass() == DependentScopeDeclRefExprClass;
1604  }
1605  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1606
1607  virtual StmtIterator child_begin();
1608  virtual StmtIterator child_end();
1609};
1610
1611class CXXExprWithTemporaries : public Expr {
1612  Stmt *SubExpr;
1613
1614  CXXTemporary **Temps;
1615  unsigned NumTemps;
1616
1617  CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps,
1618                         unsigned NumTemps);
1619  ~CXXExprWithTemporaries();
1620
1621protected:
1622  virtual void DoDestroy(ASTContext &C);
1623
1624public:
1625  static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
1626                                        CXXTemporary **Temps,
1627                                        unsigned NumTemps);
1628
1629  unsigned getNumTemporaries() const { return NumTemps; }
1630  CXXTemporary *getTemporary(unsigned i) {
1631    assert(i < NumTemps && "Index out of range");
1632    return Temps[i];
1633  }
1634  const CXXTemporary *getTemporary(unsigned i) const {
1635    return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i);
1636  }
1637
1638  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1639  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1640  void setSubExpr(Expr *E) { SubExpr = E; }
1641
1642  virtual SourceRange getSourceRange() const {
1643    return SubExpr->getSourceRange();
1644  }
1645
1646  // Implement isa/cast/dyncast/etc.
1647  static bool classof(const Stmt *T) {
1648    return T->getStmtClass() == CXXExprWithTemporariesClass;
1649  }
1650  static bool classof(const CXXExprWithTemporaries *) { return true; }
1651
1652  // Iterators
1653  virtual child_iterator child_begin();
1654  virtual child_iterator child_end();
1655};
1656
1657/// \brief Describes an explicit type conversion that uses functional
1658/// notion but could not be resolved because one or more arguments are
1659/// type-dependent.
1660///
1661/// The explicit type conversions expressed by
1662/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1663/// where \c T is some type and \c a1, a2, ..., aN are values, and
1664/// either \C T is a dependent type or one or more of the \c a's is
1665/// type-dependent. For example, this would occur in a template such
1666/// as:
1667///
1668/// \code
1669///   template<typename T, typename A1>
1670///   inline T make_a(const A1& a1) {
1671///     return T(a1);
1672///   }
1673/// \endcode
1674///
1675/// When the returned expression is instantiated, it may resolve to a
1676/// constructor call, conversion function call, or some kind of type
1677/// conversion.
1678class CXXUnresolvedConstructExpr : public Expr {
1679  /// \brief The starting location of the type
1680  SourceLocation TyBeginLoc;
1681
1682  /// \brief The type being constructed.
1683  QualType Type;
1684
1685  /// \brief The location of the left parentheses ('(').
1686  SourceLocation LParenLoc;
1687
1688  /// \brief The location of the right parentheses (')').
1689  SourceLocation RParenLoc;
1690
1691  /// \brief The number of arguments used to construct the type.
1692  unsigned NumArgs;
1693
1694  CXXUnresolvedConstructExpr(SourceLocation TyBegin,
1695                             QualType T,
1696                             SourceLocation LParenLoc,
1697                             Expr **Args,
1698                             unsigned NumArgs,
1699                             SourceLocation RParenLoc);
1700
1701public:
1702  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1703                                            SourceLocation TyBegin,
1704                                            QualType T,
1705                                            SourceLocation LParenLoc,
1706                                            Expr **Args,
1707                                            unsigned NumArgs,
1708                                            SourceLocation RParenLoc);
1709
1710  /// \brief Retrieve the source location where the type begins.
1711  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1712  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1713
1714  /// \brief Retrieve the type that is being constructed, as specified
1715  /// in the source code.
1716  QualType getTypeAsWritten() const { return Type; }
1717  void setTypeAsWritten(QualType T) { Type = T; }
1718
1719  /// \brief Retrieve the location of the left parentheses ('(') that
1720  /// precedes the argument list.
1721  SourceLocation getLParenLoc() const { return LParenLoc; }
1722  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1723
1724  /// \brief Retrieve the location of the right parentheses (')') that
1725  /// follows the argument list.
1726  SourceLocation getRParenLoc() const { return RParenLoc; }
1727  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1728
1729  /// \brief Retrieve the number of arguments.
1730  unsigned arg_size() const { return NumArgs; }
1731
1732  typedef Expr** arg_iterator;
1733  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1734  arg_iterator arg_end() { return arg_begin() + NumArgs; }
1735
1736  typedef const Expr* const * const_arg_iterator;
1737  const_arg_iterator arg_begin() const {
1738    return reinterpret_cast<const Expr* const *>(this + 1);
1739  }
1740  const_arg_iterator arg_end() const {
1741    return arg_begin() + NumArgs;
1742  }
1743
1744  Expr *getArg(unsigned I) {
1745    assert(I < NumArgs && "Argument index out-of-range");
1746    return *(arg_begin() + I);
1747  }
1748
1749  const Expr *getArg(unsigned I) const {
1750    assert(I < NumArgs && "Argument index out-of-range");
1751    return *(arg_begin() + I);
1752  }
1753
1754  virtual SourceRange getSourceRange() const {
1755    return SourceRange(TyBeginLoc, RParenLoc);
1756  }
1757  static bool classof(const Stmt *T) {
1758    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1759  }
1760  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
1761
1762  // Iterators
1763  virtual child_iterator child_begin();
1764  virtual child_iterator child_end();
1765};
1766
1767/// \brief Represents a C++ member access expression where the actual
1768/// member referenced could not be resolved because the base
1769/// expression or the member name was dependent.
1770///
1771/// Like UnresolvedMemberExprs, these can be either implicit or
1772/// explicit accesses.  It is only possible to get one of these with
1773/// an implicit access if a qualifier is provided.
1774class CXXDependentScopeMemberExpr : public Expr {
1775  /// \brief The expression for the base pointer or class reference,
1776  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
1777  Stmt *Base;
1778
1779  /// \brief The type of the base expression.  Never null, even for
1780  /// implicit accesses.
1781  QualType BaseType;
1782
1783  /// \brief Whether this member expression used the '->' operator or
1784  /// the '.' operator.
1785  bool IsArrow : 1;
1786
1787  /// \brief Whether this member expression has explicitly-specified template
1788  /// arguments.
1789  bool HasExplicitTemplateArgs : 1;
1790
1791  /// \brief The location of the '->' or '.' operator.
1792  SourceLocation OperatorLoc;
1793
1794  /// \brief The nested-name-specifier that precedes the member name, if any.
1795  NestedNameSpecifier *Qualifier;
1796
1797  /// \brief The source range covering the nested name specifier.
1798  SourceRange QualifierRange;
1799
1800  /// \brief In a qualified member access expression such as t->Base::f, this
1801  /// member stores the resolves of name lookup in the context of the member
1802  /// access expression, to be used at instantiation time.
1803  ///
1804  /// FIXME: This member, along with the Qualifier and QualifierRange, could
1805  /// be stuck into a structure that is optionally allocated at the end of
1806  /// the CXXDependentScopeMemberExpr, to save space in the common case.
1807  NamedDecl *FirstQualifierFoundInScope;
1808
1809  /// \brief The member to which this member expression refers, which
1810  /// can be name, overloaded operator, or destructor.
1811  /// FIXME: could also be a template-id
1812  DeclarationName Member;
1813
1814  /// \brief The location of the member name.
1815  SourceLocation MemberLoc;
1816
1817  /// \brief Retrieve the explicit template argument list that followed the
1818  /// member template name, if any.
1819  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
1820    assert(HasExplicitTemplateArgs);
1821    return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
1822  }
1823
1824  /// \brief Retrieve the explicit template argument list that followed the
1825  /// member template name, if any.
1826  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1827    return const_cast<CXXDependentScopeMemberExpr *>(this)
1828             ->getExplicitTemplateArgumentList();
1829  }
1830
1831  CXXDependentScopeMemberExpr(ASTContext &C,
1832                          Expr *Base, QualType BaseType, bool IsArrow,
1833                          SourceLocation OperatorLoc,
1834                          NestedNameSpecifier *Qualifier,
1835                          SourceRange QualifierRange,
1836                          NamedDecl *FirstQualifierFoundInScope,
1837                          DeclarationName Member,
1838                          SourceLocation MemberLoc,
1839                          const TemplateArgumentListInfo *TemplateArgs);
1840
1841public:
1842  CXXDependentScopeMemberExpr(ASTContext &C,
1843                          Expr *Base, QualType BaseType,
1844                          bool IsArrow,
1845                          SourceLocation OperatorLoc,
1846                          NestedNameSpecifier *Qualifier,
1847                          SourceRange QualifierRange,
1848                          NamedDecl *FirstQualifierFoundInScope,
1849                          DeclarationName Member,
1850                          SourceLocation MemberLoc)
1851  : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
1852    Base(Base), BaseType(BaseType), IsArrow(IsArrow),
1853    HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
1854    Qualifier(Qualifier), QualifierRange(QualifierRange),
1855    FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1856    Member(Member), MemberLoc(MemberLoc) { }
1857
1858  static CXXDependentScopeMemberExpr *
1859  Create(ASTContext &C,
1860         Expr *Base, QualType BaseType, bool IsArrow,
1861         SourceLocation OperatorLoc,
1862         NestedNameSpecifier *Qualifier,
1863         SourceRange QualifierRange,
1864         NamedDecl *FirstQualifierFoundInScope,
1865         DeclarationName Member,
1866         SourceLocation MemberLoc,
1867         const TemplateArgumentListInfo *TemplateArgs);
1868
1869  /// \brief True if this is an implicit access, i.e. one in which the
1870  /// member being accessed was not written in the source.  The source
1871  /// location of the operator is invalid in this case.
1872  bool isImplicitAccess() const { return Base == 0; }
1873
1874  /// \brief Retrieve the base object of this member expressions,
1875  /// e.g., the \c x in \c x.m.
1876  Expr *getBase() const {
1877    assert(!isImplicitAccess());
1878    return cast<Expr>(Base);
1879  }
1880  void setBase(Expr *E) { Base = E; }
1881
1882  QualType getBaseType() const { return BaseType; }
1883
1884  /// \brief Determine whether this member expression used the '->'
1885  /// operator; otherwise, it used the '.' operator.
1886  bool isArrow() const { return IsArrow; }
1887  void setArrow(bool A) { IsArrow = A; }
1888
1889  /// \brief Retrieve the location of the '->' or '.' operator.
1890  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1891  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1892
1893  /// \brief Retrieve the nested-name-specifier that qualifies the member
1894  /// name.
1895  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1896
1897  /// \brief Retrieve the source range covering the nested-name-specifier
1898  /// that qualifies the member name.
1899  SourceRange getQualifierRange() const { return QualifierRange; }
1900
1901  /// \brief Retrieve the first part of the nested-name-specifier that was
1902  /// found in the scope of the member access expression when the member access
1903  /// was initially parsed.
1904  ///
1905  /// This function only returns a useful result when member access expression
1906  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
1907  /// returned by this function describes what was found by unqualified name
1908  /// lookup for the identifier "Base" within the scope of the member access
1909  /// expression itself. At template instantiation time, this information is
1910  /// combined with the results of name lookup into the type of the object
1911  /// expression itself (the class type of x).
1912  NamedDecl *getFirstQualifierFoundInScope() const {
1913    return FirstQualifierFoundInScope;
1914  }
1915
1916  /// \brief Retrieve the name of the member that this expression
1917  /// refers to.
1918  DeclarationName getMember() const { return Member; }
1919  void setMember(DeclarationName N) { Member = N; }
1920
1921  // \brief Retrieve the location of the name of the member that this
1922  // expression refers to.
1923  SourceLocation getMemberLoc() const { return MemberLoc; }
1924  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
1925
1926  /// \brief Determines whether this member expression actually had a C++
1927  /// template argument list explicitly specified, e.g., x.f<int>.
1928  bool hasExplicitTemplateArgs() const {
1929    return HasExplicitTemplateArgs;
1930  }
1931
1932  /// \brief Copies the template arguments (if present) into the given
1933  /// structure.
1934  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1935    assert(HasExplicitTemplateArgs);
1936    getExplicitTemplateArgumentList()->copyInto(List);
1937  }
1938
1939  /// \brief Retrieve the location of the left angle bracket following the
1940  /// member name ('<'), if any.
1941  SourceLocation getLAngleLoc() const {
1942    assert(HasExplicitTemplateArgs);
1943    return getExplicitTemplateArgumentList()->LAngleLoc;
1944  }
1945
1946  /// \brief Retrieve the template arguments provided as part of this
1947  /// template-id.
1948  const TemplateArgumentLoc *getTemplateArgs() const {
1949    assert(HasExplicitTemplateArgs);
1950    return getExplicitTemplateArgumentList()->getTemplateArgs();
1951  }
1952
1953  /// \brief Retrieve the number of template arguments provided as part of this
1954  /// template-id.
1955  unsigned getNumTemplateArgs() const {
1956    assert(HasExplicitTemplateArgs);
1957    return getExplicitTemplateArgumentList()->NumTemplateArgs;
1958  }
1959
1960  /// \brief Retrieve the location of the right angle bracket following the
1961  /// template arguments ('>').
1962  SourceLocation getRAngleLoc() const {
1963    assert(HasExplicitTemplateArgs);
1964    return getExplicitTemplateArgumentList()->RAngleLoc;
1965  }
1966
1967  virtual SourceRange getSourceRange() const {
1968    SourceRange Range;
1969    if (!isImplicitAccess())
1970      Range.setBegin(Base->getSourceRange().getBegin());
1971    else if (getQualifier())
1972      Range.setBegin(getQualifierRange().getBegin());
1973    else
1974      Range.setBegin(MemberLoc);
1975
1976    if (hasExplicitTemplateArgs())
1977      Range.setEnd(getRAngleLoc());
1978    else
1979      Range.setEnd(MemberLoc);
1980    return Range;
1981  }
1982
1983  static bool classof(const Stmt *T) {
1984    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
1985  }
1986  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
1987
1988  // Iterators
1989  virtual child_iterator child_begin();
1990  virtual child_iterator child_end();
1991};
1992
1993/// \brief Represents a C++ member access expression for which lookup
1994/// produced a set of overloaded functions.
1995///
1996/// The member access may be explicit or implicit:
1997///    struct A {
1998///      int a, b;
1999///      int explicitAccess() { return this->a + this->A::b; }
2000///      int implicitAccess() { return a + A::b; }
2001///    };
2002///
2003/// In the final AST, an explicit access always becomes a MemberExpr.
2004/// An implicit access may become either a MemberExpr or a
2005/// DeclRefExpr, depending on whether the member is static.
2006class UnresolvedMemberExpr : public OverloadExpr {
2007  /// \brief Whether this member expression used the '->' operator or
2008  /// the '.' operator.
2009  bool IsArrow : 1;
2010
2011  /// \brief Whether the lookup results contain an unresolved using
2012  /// declaration.
2013  bool HasUnresolvedUsing : 1;
2014
2015  /// \brief The expression for the base pointer or class reference,
2016  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
2017  /// member expression
2018  Stmt *Base;
2019
2020  /// \brief The type of the base expression;  never null.
2021  QualType BaseType;
2022
2023  /// \brief The location of the '->' or '.' operator.
2024  SourceLocation OperatorLoc;
2025
2026  UnresolvedMemberExpr(QualType T, bool Dependent,
2027                       bool HasUnresolvedUsing,
2028                       Expr *Base, QualType BaseType, bool IsArrow,
2029                       SourceLocation OperatorLoc,
2030                       NestedNameSpecifier *Qualifier,
2031                       SourceRange QualifierRange,
2032                       DeclarationName Member,
2033                       SourceLocation MemberLoc,
2034                       const TemplateArgumentListInfo *TemplateArgs);
2035
2036public:
2037  static UnresolvedMemberExpr *
2038  Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing,
2039         Expr *Base, QualType BaseType, bool IsArrow,
2040         SourceLocation OperatorLoc,
2041         NestedNameSpecifier *Qualifier,
2042         SourceRange QualifierRange,
2043         DeclarationName Member,
2044         SourceLocation MemberLoc,
2045         const TemplateArgumentListInfo *TemplateArgs);
2046
2047  /// \brief True if this is an implicit access, i.e. one in which the
2048  /// member being accessed was not written in the source.  The source
2049  /// location of the operator is invalid in this case.
2050  bool isImplicitAccess() const { return Base == 0; }
2051
2052  /// \brief Retrieve the base object of this member expressions,
2053  /// e.g., the \c x in \c x.m.
2054  Expr *getBase() {
2055    assert(!isImplicitAccess());
2056    return cast<Expr>(Base);
2057  }
2058  const Expr *getBase() const {
2059    assert(!isImplicitAccess());
2060    return cast<Expr>(Base);
2061  }
2062  void setBase(Expr *E) { Base = E; }
2063
2064  QualType getBaseType() const { return BaseType; }
2065
2066  /// \brief Determine whether this member expression used the '->'
2067  /// operator; otherwise, it used the '.' operator.
2068  bool isArrow() const { return IsArrow; }
2069  void setArrow(bool A) { IsArrow = A; }
2070
2071  /// \brief Retrieve the location of the '->' or '.' operator.
2072  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2073  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2074
2075  /// \brief Retrieves the naming class of this lookup.
2076  CXXRecordDecl *getNamingClass() const;
2077
2078  /// \brief Retrieve the name of the member that this expression
2079  /// refers to.
2080  DeclarationName getMemberName() const { return getName(); }
2081  void setMemberName(DeclarationName N) { setName(N); }
2082
2083  // \brief Retrieve the location of the name of the member that this
2084  // expression refers to.
2085  SourceLocation getMemberLoc() const { return getNameLoc(); }
2086  void setMemberLoc(SourceLocation L) { setNameLoc(L); }
2087
2088  /// \brief Retrieve the explicit template argument list that followed the
2089  /// member template name.
2090  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2091    assert(hasExplicitTemplateArgs());
2092    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2093  }
2094
2095  /// \brief Retrieve the explicit template argument list that followed the
2096  /// member template name, if any.
2097  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2098    assert(hasExplicitTemplateArgs());
2099    return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2100  }
2101
2102  /// \brief Copies the template arguments into the given structure.
2103  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2104    getExplicitTemplateArgs().copyInto(List);
2105  }
2106
2107  /// \brief Retrieve the location of the left angle bracket following
2108  /// the member name ('<').
2109  SourceLocation getLAngleLoc() const {
2110    return getExplicitTemplateArgs().LAngleLoc;
2111  }
2112
2113  /// \brief Retrieve the template arguments provided as part of this
2114  /// template-id.
2115  const TemplateArgumentLoc *getTemplateArgs() const {
2116    return getExplicitTemplateArgs().getTemplateArgs();
2117  }
2118
2119  /// \brief Retrieve the number of template arguments provided as
2120  /// part of this template-id.
2121  unsigned getNumTemplateArgs() const {
2122    return getExplicitTemplateArgs().NumTemplateArgs;
2123  }
2124
2125  /// \brief Retrieve the location of the right angle bracket
2126  /// following the template arguments ('>').
2127  SourceLocation getRAngleLoc() const {
2128    return getExplicitTemplateArgs().RAngleLoc;
2129  }
2130
2131  virtual SourceRange getSourceRange() const {
2132    SourceRange Range;
2133    if (!isImplicitAccess())
2134      Range.setBegin(Base->getSourceRange().getBegin());
2135    else if (getQualifier())
2136      Range.setBegin(getQualifierRange().getBegin());
2137    else
2138      Range.setBegin(getMemberLoc());
2139
2140    if (hasExplicitTemplateArgs())
2141      Range.setEnd(getRAngleLoc());
2142    else
2143      Range.setEnd(getMemberLoc());
2144    return Range;
2145  }
2146
2147  static bool classof(const Stmt *T) {
2148    return T->getStmtClass() == UnresolvedMemberExprClass;
2149  }
2150  static bool classof(const UnresolvedMemberExpr *) { return true; }
2151
2152  // Iterators
2153  virtual child_iterator child_begin();
2154  virtual child_iterator child_end();
2155};
2156
2157inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2158  if (isa<UnresolvedLookupExpr>(this))
2159    return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2160  else
2161    return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2162}
2163
2164}  // end namespace clang
2165
2166#endif
2167