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