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