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