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