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