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