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