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