ExprCXX.h revision 7bb12da2b0749eeebb21854c77877736969e59f2
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 an overloaded function set, either an
1133/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1134class OverloadExpr : public Expr {
1135  /// The results.  These are undesugared, which is to say, they may
1136  /// include UsingShadowDecls.  Access is relative to the naming
1137  /// class.
1138  UnresolvedSet<4> Results;
1139
1140  /// The common name of these declarations.
1141  DeclarationName Name;
1142
1143  /// The scope specifier, if any.
1144  NestedNameSpecifier *Qualifier;
1145
1146  /// The source range of the scope specifier.
1147  SourceRange QualifierRange;
1148
1149  /// The location of the name.
1150  SourceLocation NameLoc;
1151
1152  /// True if the name was a template-id.
1153  bool HasExplicitTemplateArgs;
1154
1155protected:
1156  OverloadExpr(StmtClass K, QualType T, bool Dependent,
1157               NestedNameSpecifier *Qualifier, SourceRange QRange,
1158               DeclarationName Name, SourceLocation NameLoc,
1159               bool HasTemplateArgs)
1160    : Expr(K, T, Dependent, Dependent),
1161      Name(Name), Qualifier(Qualifier), QualifierRange(QRange),
1162      NameLoc(NameLoc), HasExplicitTemplateArgs(HasTemplateArgs)
1163  {}
1164
1165public:
1166  /// Computes whether an unresolved lookup on the given declarations
1167  /// and optional template arguments is type- and value-dependent.
1168  static bool ComputeDependence(UnresolvedSetIterator Begin,
1169                                UnresolvedSetIterator End,
1170                                const TemplateArgumentListInfo *Args);
1171
1172  /// Finds the overloaded expression in the given expression of
1173  /// OverloadTy.
1174  ///
1175  /// \return the expression (which must be there) and true if it is
1176  /// within an address-of operator.
1177  static llvm::PointerIntPair<OverloadExpr*,1> find(Expr *E) {
1178    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1179
1180    bool op = false;
1181    E = E->IgnoreParens();
1182    if (isa<UnaryOperator>(E))
1183      op = true, E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
1184    return llvm::PointerIntPair<OverloadExpr*,1>(cast<OverloadExpr>(E), op);
1185  }
1186
1187  void addDecls(UnresolvedSetIterator Begin, UnresolvedSetIterator End) {
1188    Results.append(Begin, End);
1189  }
1190
1191  typedef UnresolvedSetImpl::iterator decls_iterator;
1192  decls_iterator decls_begin() const { return Results.begin(); }
1193  decls_iterator decls_end() const { return Results.end(); }
1194
1195  /// Gets the decls as an unresolved set.
1196  const UnresolvedSetImpl &getDecls() { return Results; }
1197
1198  /// Gets the number of declarations in the unresolved set.
1199  unsigned getNumDecls() const { return Results.size(); }
1200
1201  /// Gets the name looked up.
1202  DeclarationName getName() const { return Name; }
1203  void setName(DeclarationName N) { Name = N; }
1204
1205  /// Gets the location of the name.
1206  SourceLocation getNameLoc() const { return NameLoc; }
1207  void setNameLoc(SourceLocation Loc) { NameLoc = Loc; }
1208
1209  /// Fetches the nested-name qualifier, if one was given.
1210  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1211
1212  /// Fetches the range of the nested-name qualifier.
1213  SourceRange getQualifierRange() const { return QualifierRange; }
1214
1215  /// \brief Determines whether this expression had an explicit
1216  /// template argument list, e.g. f<int>.
1217  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1218
1219  ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
1220
1221  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1222    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1223  }
1224
1225  ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1226    if (hasExplicitTemplateArgs())
1227      return &getExplicitTemplateArgs();
1228    return 0;
1229  }
1230
1231  static bool classof(const Stmt *T) {
1232    return T->getStmtClass() == UnresolvedLookupExprClass ||
1233           T->getStmtClass() == UnresolvedMemberExprClass;
1234  }
1235  static bool classof(const OverloadExpr *) { return true; }
1236};
1237
1238/// \brief A reference to a name which we were able to look up during
1239/// parsing but could not resolve to a specific declaration.  This
1240/// arises in several ways:
1241///   * we might be waiting for argument-dependent lookup
1242///   * the name might resolve to an overloaded function
1243/// and eventually:
1244///   * the lookup might have included a function template
1245/// These never include UnresolvedUsingValueDecls, which are always
1246/// class members and therefore appear only in
1247/// UnresolvedMemberLookupExprs.
1248class UnresolvedLookupExpr : public OverloadExpr {
1249  /// True if these lookup results should be extended by
1250  /// argument-dependent lookup if this is the operand of a function
1251  /// call.
1252  bool RequiresADL;
1253
1254  /// True if these lookup results are overloaded.  This is pretty
1255  /// trivially rederivable if we urgently need to kill this field.
1256  bool Overloaded;
1257
1258  /// The naming class (C++ [class.access.base]p5) of the lookup, if
1259  /// any.  This can generally be recalculated from the context chain,
1260  /// but that can be fairly expensive for unqualified lookups.  If we
1261  /// want to improve memory use here, this could go in a union
1262  /// against the qualified-lookup bits.
1263  CXXRecordDecl *NamingClass;
1264
1265  UnresolvedLookupExpr(QualType T, bool Dependent, CXXRecordDecl *NamingClass,
1266                       NestedNameSpecifier *Qualifier, SourceRange QRange,
1267                       DeclarationName Name, SourceLocation NameLoc,
1268                       bool RequiresADL, bool Overloaded, bool HasTemplateArgs)
1269    : OverloadExpr(UnresolvedLookupExprClass, T, Dependent, Qualifier, QRange,
1270                   Name, NameLoc, HasTemplateArgs),
1271      RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1272  {}
1273
1274public:
1275  static UnresolvedLookupExpr *Create(ASTContext &C,
1276                                      bool Dependent,
1277                                      CXXRecordDecl *NamingClass,
1278                                      NestedNameSpecifier *Qualifier,
1279                                      SourceRange QualifierRange,
1280                                      DeclarationName Name,
1281                                      SourceLocation NameLoc,
1282                                      bool ADL, bool Overloaded) {
1283    return new(C) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy,
1284                                       Dependent, NamingClass,
1285                                       Qualifier, QualifierRange,
1286                                       Name, NameLoc, ADL, Overloaded, false);
1287  }
1288
1289  static UnresolvedLookupExpr *Create(ASTContext &C,
1290                                      bool Dependent,
1291                                      CXXRecordDecl *NamingClass,
1292                                      NestedNameSpecifier *Qualifier,
1293                                      SourceRange QualifierRange,
1294                                      DeclarationName Name,
1295                                      SourceLocation NameLoc,
1296                                      bool ADL,
1297                                      const TemplateArgumentListInfo &Args);
1298
1299  /// True if this declaration should be extended by
1300  /// argument-dependent lookup.
1301  bool requiresADL() const { return RequiresADL; }
1302
1303  /// True if this lookup is overloaded.
1304  bool isOverloaded() const { return Overloaded; }
1305
1306  /// Gets the 'naming class' (in the sense of C++0x
1307  /// [class.access.base]p5) of the lookup.  This is the scope
1308  /// that was looked in to find these results.
1309  CXXRecordDecl *getNamingClass() const { return NamingClass; }
1310
1311  // Note that, inconsistently with the explicit-template-argument AST
1312  // nodes, users are *forbidden* from calling these methods on objects
1313  // without explicit template arguments.
1314
1315  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1316    assert(hasExplicitTemplateArgs());
1317    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1318  }
1319
1320  /// Gets a reference to the explicit template argument list.
1321  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1322    assert(hasExplicitTemplateArgs());
1323    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1324  }
1325
1326  /// \brief Copies the template arguments (if present) into the given
1327  /// structure.
1328  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1329    getExplicitTemplateArgs().copyInto(List);
1330  }
1331
1332  SourceLocation getLAngleLoc() const {
1333    return getExplicitTemplateArgs().LAngleLoc;
1334  }
1335
1336  SourceLocation getRAngleLoc() const {
1337    return getExplicitTemplateArgs().RAngleLoc;
1338  }
1339
1340  TemplateArgumentLoc const *getTemplateArgs() const {
1341    return getExplicitTemplateArgs().getTemplateArgs();
1342  }
1343
1344  unsigned getNumTemplateArgs() const {
1345    return getExplicitTemplateArgs().NumTemplateArgs;
1346  }
1347
1348  virtual SourceRange getSourceRange() const {
1349    SourceRange Range(getNameLoc());
1350    if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
1351    if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
1352    return Range;
1353  }
1354
1355  virtual StmtIterator child_begin();
1356  virtual StmtIterator child_end();
1357
1358  static bool classof(const Stmt *T) {
1359    return T->getStmtClass() == UnresolvedLookupExprClass;
1360  }
1361  static bool classof(const UnresolvedLookupExpr *) { return true; }
1362};
1363
1364/// \brief A qualified reference to a name whose declaration cannot
1365/// yet be resolved.
1366///
1367/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1368/// it expresses a reference to a declaration such as
1369/// X<T>::value. The difference, however, is that an
1370/// DependentScopeDeclRefExpr node is used only within C++ templates when
1371/// the qualification (e.g., X<T>::) refers to a dependent type. In
1372/// this case, X<T>::value cannot resolve to a declaration because the
1373/// declaration will differ from on instantiation of X<T> to the
1374/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1375/// qualifier (X<T>::) and the name of the entity being referenced
1376/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1377/// declaration can be found.
1378class DependentScopeDeclRefExpr : public Expr {
1379  /// The name of the entity we will be referencing.
1380  DeclarationName Name;
1381
1382  /// Location of the name of the declaration we're referencing.
1383  SourceLocation Loc;
1384
1385  /// QualifierRange - The source range that covers the
1386  /// nested-name-specifier.
1387  SourceRange QualifierRange;
1388
1389  /// \brief The nested-name-specifier that qualifies this unresolved
1390  /// declaration name.
1391  NestedNameSpecifier *Qualifier;
1392
1393  /// \brief Whether the name includes explicit template arguments.
1394  bool HasExplicitTemplateArgs;
1395
1396  DependentScopeDeclRefExpr(QualType T,
1397                            NestedNameSpecifier *Qualifier,
1398                            SourceRange QualifierRange,
1399                            DeclarationName Name,
1400                            SourceLocation NameLoc,
1401                            bool HasExplicitTemplateArgs)
1402    : Expr(DependentScopeDeclRefExprClass, T, true, true),
1403      Name(Name), Loc(NameLoc),
1404      QualifierRange(QualifierRange), Qualifier(Qualifier),
1405      HasExplicitTemplateArgs(HasExplicitTemplateArgs)
1406  {}
1407
1408public:
1409  static DependentScopeDeclRefExpr *Create(ASTContext &C,
1410                                           NestedNameSpecifier *Qualifier,
1411                                           SourceRange QualifierRange,
1412                                           DeclarationName Name,
1413                                           SourceLocation NameLoc,
1414                              const TemplateArgumentListInfo *TemplateArgs = 0);
1415
1416  /// \brief Retrieve the name that this expression refers to.
1417  DeclarationName getDeclName() const { return Name; }
1418
1419  /// \brief Retrieve the location of the name within the expression.
1420  SourceLocation getLocation() const { return Loc; }
1421
1422  /// \brief Retrieve the source range of the nested-name-specifier.
1423  SourceRange getQualifierRange() const { return QualifierRange; }
1424
1425  /// \brief Retrieve the nested-name-specifier that qualifies this
1426  /// declaration.
1427  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1428
1429  /// Determines whether this lookup had explicit template arguments.
1430  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1431
1432  // Note that, inconsistently with the explicit-template-argument AST
1433  // nodes, users are *forbidden* from calling these methods on objects
1434  // without explicit template arguments.
1435
1436  /// Gets a reference to the explicit template argument list.
1437  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1438    assert(hasExplicitTemplateArgs());
1439    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1440  }
1441
1442  /// \brief Copies the template arguments (if present) into the given
1443  /// structure.
1444  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1445    getExplicitTemplateArgs().copyInto(List);
1446  }
1447
1448  SourceLocation getLAngleLoc() const {
1449    return getExplicitTemplateArgs().LAngleLoc;
1450  }
1451
1452  SourceLocation getRAngleLoc() const {
1453    return getExplicitTemplateArgs().RAngleLoc;
1454  }
1455
1456  TemplateArgumentLoc const *getTemplateArgs() const {
1457    return getExplicitTemplateArgs().getTemplateArgs();
1458  }
1459
1460  unsigned getNumTemplateArgs() const {
1461    return getExplicitTemplateArgs().NumTemplateArgs;
1462  }
1463
1464  virtual SourceRange getSourceRange() const {
1465    SourceRange Range(QualifierRange.getBegin(), getLocation());
1466    if (hasExplicitTemplateArgs())
1467      Range.setEnd(getRAngleLoc());
1468    return Range;
1469  }
1470
1471  static bool classof(const Stmt *T) {
1472    return T->getStmtClass() == DependentScopeDeclRefExprClass;
1473  }
1474  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1475
1476  virtual StmtIterator child_begin();
1477  virtual StmtIterator child_end();
1478};
1479
1480class CXXExprWithTemporaries : public Expr {
1481  Stmt *SubExpr;
1482
1483  CXXTemporary **Temps;
1484  unsigned NumTemps;
1485
1486  CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps,
1487                         unsigned NumTemps);
1488  ~CXXExprWithTemporaries();
1489
1490protected:
1491  virtual void DoDestroy(ASTContext &C);
1492
1493public:
1494  static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
1495                                        CXXTemporary **Temps,
1496                                        unsigned NumTemps);
1497
1498  unsigned getNumTemporaries() const { return NumTemps; }
1499  CXXTemporary *getTemporary(unsigned i) {
1500    assert(i < NumTemps && "Index out of range");
1501    return Temps[i];
1502  }
1503  const CXXTemporary *getTemporary(unsigned i) const {
1504    return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i);
1505  }
1506
1507  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1508  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1509  void setSubExpr(Expr *E) { SubExpr = E; }
1510
1511  virtual SourceRange getSourceRange() const {
1512    return SubExpr->getSourceRange();
1513  }
1514
1515  // Implement isa/cast/dyncast/etc.
1516  static bool classof(const Stmt *T) {
1517    return T->getStmtClass() == CXXExprWithTemporariesClass;
1518  }
1519  static bool classof(const CXXExprWithTemporaries *) { return true; }
1520
1521  // Iterators
1522  virtual child_iterator child_begin();
1523  virtual child_iterator child_end();
1524};
1525
1526/// \brief Describes an explicit type conversion that uses functional
1527/// notion but could not be resolved because one or more arguments are
1528/// type-dependent.
1529///
1530/// The explicit type conversions expressed by
1531/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1532/// where \c T is some type and \c a1, a2, ..., aN are values, and
1533/// either \C T is a dependent type or one or more of the \c a's is
1534/// type-dependent. For example, this would occur in a template such
1535/// as:
1536///
1537/// \code
1538///   template<typename T, typename A1>
1539///   inline T make_a(const A1& a1) {
1540///     return T(a1);
1541///   }
1542/// \endcode
1543///
1544/// When the returned expression is instantiated, it may resolve to a
1545/// constructor call, conversion function call, or some kind of type
1546/// conversion.
1547class CXXUnresolvedConstructExpr : public Expr {
1548  /// \brief The starting location of the type
1549  SourceLocation TyBeginLoc;
1550
1551  /// \brief The type being constructed.
1552  QualType Type;
1553
1554  /// \brief The location of the left parentheses ('(').
1555  SourceLocation LParenLoc;
1556
1557  /// \brief The location of the right parentheses (')').
1558  SourceLocation RParenLoc;
1559
1560  /// \brief The number of arguments used to construct the type.
1561  unsigned NumArgs;
1562
1563  CXXUnresolvedConstructExpr(SourceLocation TyBegin,
1564                             QualType T,
1565                             SourceLocation LParenLoc,
1566                             Expr **Args,
1567                             unsigned NumArgs,
1568                             SourceLocation RParenLoc);
1569
1570public:
1571  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1572                                            SourceLocation TyBegin,
1573                                            QualType T,
1574                                            SourceLocation LParenLoc,
1575                                            Expr **Args,
1576                                            unsigned NumArgs,
1577                                            SourceLocation RParenLoc);
1578
1579  /// \brief Retrieve the source location where the type begins.
1580  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1581  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1582
1583  /// \brief Retrieve the type that is being constructed, as specified
1584  /// in the source code.
1585  QualType getTypeAsWritten() const { return Type; }
1586  void setTypeAsWritten(QualType T) { Type = T; }
1587
1588  /// \brief Retrieve the location of the left parentheses ('(') that
1589  /// precedes the argument list.
1590  SourceLocation getLParenLoc() const { return LParenLoc; }
1591  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1592
1593  /// \brief Retrieve the location of the right parentheses (')') that
1594  /// follows the argument list.
1595  SourceLocation getRParenLoc() const { return RParenLoc; }
1596  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1597
1598  /// \brief Retrieve the number of arguments.
1599  unsigned arg_size() const { return NumArgs; }
1600
1601  typedef Expr** arg_iterator;
1602  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1603  arg_iterator arg_end() { return arg_begin() + NumArgs; }
1604
1605  Expr *getArg(unsigned I) {
1606    assert(I < NumArgs && "Argument index out-of-range");
1607    return *(arg_begin() + I);
1608  }
1609
1610  virtual SourceRange getSourceRange() const {
1611    return SourceRange(TyBeginLoc, RParenLoc);
1612  }
1613  static bool classof(const Stmt *T) {
1614    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1615  }
1616  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
1617
1618  // Iterators
1619  virtual child_iterator child_begin();
1620  virtual child_iterator child_end();
1621};
1622
1623/// \brief Represents a C++ member access expression where the actual
1624/// member referenced could not be resolved because the base
1625/// expression or the member name was dependent.
1626///
1627/// Like UnresolvedMemberExprs, these can be either implicit or
1628/// explicit accesses.  It is only possible to get one of these with
1629/// an implicit access if a qualifier is provided.
1630class CXXDependentScopeMemberExpr : public Expr {
1631  /// \brief The expression for the base pointer or class reference,
1632  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
1633  Stmt *Base;
1634
1635  /// \brief The type of the base expression.  Never null, even for
1636  /// implicit accesses.
1637  QualType BaseType;
1638
1639  /// \brief Whether this member expression used the '->' operator or
1640  /// the '.' operator.
1641  bool IsArrow : 1;
1642
1643  /// \brief Whether this member expression has explicitly-specified template
1644  /// arguments.
1645  bool HasExplicitTemplateArgs : 1;
1646
1647  /// \brief The location of the '->' or '.' operator.
1648  SourceLocation OperatorLoc;
1649
1650  /// \brief The nested-name-specifier that precedes the member name, if any.
1651  NestedNameSpecifier *Qualifier;
1652
1653  /// \brief The source range covering the nested name specifier.
1654  SourceRange QualifierRange;
1655
1656  /// \brief In a qualified member access expression such as t->Base::f, this
1657  /// member stores the resolves of name lookup in the context of the member
1658  /// access expression, to be used at instantiation time.
1659  ///
1660  /// FIXME: This member, along with the Qualifier and QualifierRange, could
1661  /// be stuck into a structure that is optionally allocated at the end of
1662  /// the CXXDependentScopeMemberExpr, to save space in the common case.
1663  NamedDecl *FirstQualifierFoundInScope;
1664
1665  /// \brief The member to which this member expression refers, which
1666  /// can be name, overloaded operator, or destructor.
1667  /// FIXME: could also be a template-id
1668  DeclarationName Member;
1669
1670  /// \brief The location of the member name.
1671  SourceLocation MemberLoc;
1672
1673  /// \brief Retrieve the explicit template argument list that followed the
1674  /// member template name, if any.
1675  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
1676    assert(HasExplicitTemplateArgs);
1677    return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
1678  }
1679
1680  /// \brief Retrieve the explicit template argument list that followed the
1681  /// member template name, if any.
1682  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1683    return const_cast<CXXDependentScopeMemberExpr *>(this)
1684             ->getExplicitTemplateArgumentList();
1685  }
1686
1687  CXXDependentScopeMemberExpr(ASTContext &C,
1688                          Expr *Base, QualType BaseType, bool IsArrow,
1689                          SourceLocation OperatorLoc,
1690                          NestedNameSpecifier *Qualifier,
1691                          SourceRange QualifierRange,
1692                          NamedDecl *FirstQualifierFoundInScope,
1693                          DeclarationName Member,
1694                          SourceLocation MemberLoc,
1695                          const TemplateArgumentListInfo *TemplateArgs);
1696
1697public:
1698  CXXDependentScopeMemberExpr(ASTContext &C,
1699                          Expr *Base, QualType BaseType,
1700                          bool IsArrow,
1701                          SourceLocation OperatorLoc,
1702                          NestedNameSpecifier *Qualifier,
1703                          SourceRange QualifierRange,
1704                          NamedDecl *FirstQualifierFoundInScope,
1705                          DeclarationName Member,
1706                          SourceLocation MemberLoc)
1707  : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
1708    Base(Base), BaseType(BaseType), IsArrow(IsArrow),
1709    HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
1710    Qualifier(Qualifier), QualifierRange(QualifierRange),
1711    FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1712    Member(Member), MemberLoc(MemberLoc) { }
1713
1714  static CXXDependentScopeMemberExpr *
1715  Create(ASTContext &C,
1716         Expr *Base, QualType BaseType, bool IsArrow,
1717         SourceLocation OperatorLoc,
1718         NestedNameSpecifier *Qualifier,
1719         SourceRange QualifierRange,
1720         NamedDecl *FirstQualifierFoundInScope,
1721         DeclarationName Member,
1722         SourceLocation MemberLoc,
1723         const TemplateArgumentListInfo *TemplateArgs);
1724
1725  /// \brief True if this is an implicit access, i.e. one in which the
1726  /// member being accessed was not written in the source.  The source
1727  /// location of the operator is invalid in this case.
1728  bool isImplicitAccess() const { return Base == 0; }
1729
1730  /// \brief Retrieve the base object of this member expressions,
1731  /// e.g., the \c x in \c x.m.
1732  Expr *getBase() const {
1733    assert(!isImplicitAccess());
1734    return cast<Expr>(Base);
1735  }
1736  void setBase(Expr *E) { Base = E; }
1737
1738  QualType getBaseType() const { return BaseType; }
1739
1740  /// \brief Determine whether this member expression used the '->'
1741  /// operator; otherwise, it used the '.' operator.
1742  bool isArrow() const { return IsArrow; }
1743  void setArrow(bool A) { IsArrow = A; }
1744
1745  /// \brief Retrieve the location of the '->' or '.' operator.
1746  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1747  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1748
1749  /// \brief Retrieve the nested-name-specifier that qualifies the member
1750  /// name.
1751  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1752
1753  /// \brief Retrieve the source range covering the nested-name-specifier
1754  /// that qualifies the member name.
1755  SourceRange getQualifierRange() const { return QualifierRange; }
1756
1757  /// \brief Retrieve the first part of the nested-name-specifier that was
1758  /// found in the scope of the member access expression when the member access
1759  /// was initially parsed.
1760  ///
1761  /// This function only returns a useful result when member access expression
1762  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
1763  /// returned by this function describes what was found by unqualified name
1764  /// lookup for the identifier "Base" within the scope of the member access
1765  /// expression itself. At template instantiation time, this information is
1766  /// combined with the results of name lookup into the type of the object
1767  /// expression itself (the class type of x).
1768  NamedDecl *getFirstQualifierFoundInScope() const {
1769    return FirstQualifierFoundInScope;
1770  }
1771
1772  /// \brief Retrieve the name of the member that this expression
1773  /// refers to.
1774  DeclarationName getMember() const { return Member; }
1775  void setMember(DeclarationName N) { Member = N; }
1776
1777  // \brief Retrieve the location of the name of the member that this
1778  // expression refers to.
1779  SourceLocation getMemberLoc() const { return MemberLoc; }
1780  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
1781
1782  /// \brief Determines whether this member expression actually had a C++
1783  /// template argument list explicitly specified, e.g., x.f<int>.
1784  bool hasExplicitTemplateArgs() const {
1785    return HasExplicitTemplateArgs;
1786  }
1787
1788  /// \brief Copies the template arguments (if present) into the given
1789  /// structure.
1790  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1791    assert(HasExplicitTemplateArgs);
1792    getExplicitTemplateArgumentList()->copyInto(List);
1793  }
1794
1795  /// \brief Retrieve the location of the left angle bracket following the
1796  /// member name ('<'), if any.
1797  SourceLocation getLAngleLoc() const {
1798    assert(HasExplicitTemplateArgs);
1799    return getExplicitTemplateArgumentList()->LAngleLoc;
1800  }
1801
1802  /// \brief Retrieve the template arguments provided as part of this
1803  /// template-id.
1804  const TemplateArgumentLoc *getTemplateArgs() const {
1805    assert(HasExplicitTemplateArgs);
1806    return getExplicitTemplateArgumentList()->getTemplateArgs();
1807  }
1808
1809  /// \brief Retrieve the number of template arguments provided as part of this
1810  /// template-id.
1811  unsigned getNumTemplateArgs() const {
1812    assert(HasExplicitTemplateArgs);
1813    return getExplicitTemplateArgumentList()->NumTemplateArgs;
1814  }
1815
1816  /// \brief Retrieve the location of the right angle bracket following the
1817  /// template arguments ('>').
1818  SourceLocation getRAngleLoc() const {
1819    assert(HasExplicitTemplateArgs);
1820    return getExplicitTemplateArgumentList()->RAngleLoc;
1821  }
1822
1823  virtual SourceRange getSourceRange() const {
1824    SourceRange Range;
1825    if (!isImplicitAccess())
1826      Range.setBegin(Base->getSourceRange().getBegin());
1827    else if (getQualifier())
1828      Range.setBegin(getQualifierRange().getBegin());
1829    else
1830      Range.setBegin(MemberLoc);
1831
1832    if (hasExplicitTemplateArgs())
1833      Range.setEnd(getRAngleLoc());
1834    else
1835      Range.setEnd(MemberLoc);
1836    return Range;
1837  }
1838
1839  static bool classof(const Stmt *T) {
1840    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
1841  }
1842  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
1843
1844  // Iterators
1845  virtual child_iterator child_begin();
1846  virtual child_iterator child_end();
1847};
1848
1849/// \brief Represents a C++ member access expression for which lookup
1850/// produced a set of overloaded functions.
1851///
1852/// The member access may be explicit or implicit:
1853///    struct A {
1854///      int a, b;
1855///      int explicitAccess() { return this->a + this->A::b; }
1856///      int implicitAccess() { return a + A::b; }
1857///    };
1858///
1859/// In the final AST, an explicit access always becomes a MemberExpr.
1860/// An implicit access may become either a MemberExpr or a
1861/// DeclRefExpr, depending on whether the member is static.
1862class UnresolvedMemberExpr : public OverloadExpr {
1863  /// \brief Whether this member expression used the '->' operator or
1864  /// the '.' operator.
1865  bool IsArrow : 1;
1866
1867  /// \brief Whether the lookup results contain an unresolved using
1868  /// declaration.
1869  bool HasUnresolvedUsing : 1;
1870
1871  /// \brief The expression for the base pointer or class reference,
1872  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
1873  /// member expression
1874  Stmt *Base;
1875
1876  /// \brief The type of the base expression;  never null.
1877  QualType BaseType;
1878
1879  /// \brief The location of the '->' or '.' operator.
1880  SourceLocation OperatorLoc;
1881
1882  UnresolvedMemberExpr(QualType T, bool Dependent,
1883                       bool HasUnresolvedUsing,
1884                       Expr *Base, QualType BaseType, bool IsArrow,
1885                       SourceLocation OperatorLoc,
1886                       NestedNameSpecifier *Qualifier,
1887                       SourceRange QualifierRange,
1888                       DeclarationName Member,
1889                       SourceLocation MemberLoc,
1890                       const TemplateArgumentListInfo *TemplateArgs);
1891
1892public:
1893  static UnresolvedMemberExpr *
1894  Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing,
1895         Expr *Base, QualType BaseType, bool IsArrow,
1896         SourceLocation OperatorLoc,
1897         NestedNameSpecifier *Qualifier,
1898         SourceRange QualifierRange,
1899         DeclarationName Member,
1900         SourceLocation MemberLoc,
1901         const TemplateArgumentListInfo *TemplateArgs);
1902
1903  /// \brief True if this is an implicit access, i.e. one in which the
1904  /// member being accessed was not written in the source.  The source
1905  /// location of the operator is invalid in this case.
1906  bool isImplicitAccess() const { return Base == 0; }
1907
1908  /// \brief Retrieve the base object of this member expressions,
1909  /// e.g., the \c x in \c x.m.
1910  Expr *getBase() {
1911    assert(!isImplicitAccess());
1912    return cast<Expr>(Base);
1913  }
1914  void setBase(Expr *E) { Base = E; }
1915
1916  QualType getBaseType() const { return BaseType; }
1917
1918  /// \brief Determine whether this member expression used the '->'
1919  /// operator; otherwise, it used the '.' operator.
1920  bool isArrow() const { return IsArrow; }
1921  void setArrow(bool A) { IsArrow = A; }
1922
1923  /// \brief Retrieve the location of the '->' or '.' operator.
1924  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1925  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1926
1927  /// \brief Retrieves the naming class of this lookup.
1928  CXXRecordDecl *getNamingClass() const;
1929
1930  /// \brief Retrieve the name of the member that this expression
1931  /// refers to.
1932  DeclarationName getMemberName() const { return getName(); }
1933  void setMemberName(DeclarationName N) { setName(N); }
1934
1935  // \brief Retrieve the location of the name of the member that this
1936  // expression refers to.
1937  SourceLocation getMemberLoc() const { return getNameLoc(); }
1938  void setMemberLoc(SourceLocation L) { setNameLoc(L); }
1939
1940  /// \brief Retrieve the explicit template argument list that followed the
1941  /// member template name.
1942  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1943    assert(hasExplicitTemplateArgs());
1944    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
1945  }
1946
1947  /// \brief Retrieve the explicit template argument list that followed the
1948  /// member template name, if any.
1949  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1950    assert(hasExplicitTemplateArgs());
1951    return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
1952  }
1953
1954  /// \brief Copies the template arguments into the given structure.
1955  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1956    getExplicitTemplateArgs().copyInto(List);
1957  }
1958
1959  /// \brief Retrieve the location of the left angle bracket following
1960  /// the member name ('<').
1961  SourceLocation getLAngleLoc() const {
1962    return getExplicitTemplateArgs().LAngleLoc;
1963  }
1964
1965  /// \brief Retrieve the template arguments provided as part of this
1966  /// template-id.
1967  const TemplateArgumentLoc *getTemplateArgs() const {
1968    return getExplicitTemplateArgs().getTemplateArgs();
1969  }
1970
1971  /// \brief Retrieve the number of template arguments provided as
1972  /// part of this template-id.
1973  unsigned getNumTemplateArgs() const {
1974    return getExplicitTemplateArgs().NumTemplateArgs;
1975  }
1976
1977  /// \brief Retrieve the location of the right angle bracket
1978  /// following the template arguments ('>').
1979  SourceLocation getRAngleLoc() const {
1980    return getExplicitTemplateArgs().RAngleLoc;
1981  }
1982
1983  virtual SourceRange getSourceRange() const {
1984    SourceRange Range;
1985    if (!isImplicitAccess())
1986      Range.setBegin(Base->getSourceRange().getBegin());
1987    else if (getQualifier())
1988      Range.setBegin(getQualifierRange().getBegin());
1989    else
1990      Range.setBegin(getMemberLoc());
1991
1992    if (hasExplicitTemplateArgs())
1993      Range.setEnd(getRAngleLoc());
1994    else
1995      Range.setEnd(getMemberLoc());
1996    return Range;
1997  }
1998
1999  static bool classof(const Stmt *T) {
2000    return T->getStmtClass() == UnresolvedMemberExprClass;
2001  }
2002  static bool classof(const UnresolvedMemberExpr *) { return true; }
2003
2004  // Iterators
2005  virtual child_iterator child_begin();
2006  virtual child_iterator child_end();
2007};
2008
2009inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2010  if (isa<UnresolvedLookupExpr>(this))
2011    return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2012  else
2013    return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2014}
2015
2016}  // end namespace clang
2017
2018#endif
2019