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