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