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