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