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