ExprCXX.h revision 5a84dec38cfa9e084377a3167b474c79283c82fa
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
1086  bool isGlobalDelete() const { return GlobalDelete; }
1087  bool isArrayForm() const { return ArrayForm; }
1088
1089  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1090
1091  Expr *getArgument() { return cast<Expr>(Argument); }
1092  const Expr *getArgument() const { return cast<Expr>(Argument); }
1093
1094  virtual SourceRange getSourceRange() const {
1095    return SourceRange(Loc, Argument->getLocEnd());
1096  }
1097
1098  static bool classof(const Stmt *T) {
1099    return T->getStmtClass() == CXXDeleteExprClass;
1100  }
1101  static bool classof(const CXXDeleteExpr *) { return true; }
1102
1103  // Iterators
1104  virtual child_iterator child_begin();
1105  virtual child_iterator child_end();
1106};
1107
1108/// \brief Structure used to store the type being destroyed by a
1109/// pseudo-destructor expression.
1110class PseudoDestructorTypeStorage {
1111  /// \brief Either the type source information or the name of the type, if
1112  /// it couldn't be resolved due to type-dependence.
1113  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1114
1115  /// \brief The starting source location of the pseudo-destructor type.
1116  SourceLocation Location;
1117
1118public:
1119  PseudoDestructorTypeStorage() { }
1120
1121  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1122    : Type(II), Location(Loc) { }
1123
1124  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1125
1126  TypeSourceInfo *getTypeSourceInfo() const {
1127    return Type.dyn_cast<TypeSourceInfo *>();
1128  }
1129
1130  IdentifierInfo *getIdentifier() const {
1131    return Type.dyn_cast<IdentifierInfo *>();
1132  }
1133
1134  SourceLocation getLocation() const { return Location; }
1135};
1136
1137/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1138///
1139/// A pseudo-destructor is an expression that looks like a member access to a
1140/// destructor of a scalar type, except that scalar types don't have
1141/// destructors. For example:
1142///
1143/// \code
1144/// typedef int T;
1145/// void f(int *p) {
1146///   p->T::~T();
1147/// }
1148/// \endcode
1149///
1150/// Pseudo-destructors typically occur when instantiating templates such as:
1151///
1152/// \code
1153/// template<typename T>
1154/// void destroy(T* ptr) {
1155///   ptr->T::~T();
1156/// }
1157/// \endcode
1158///
1159/// for scalar types. A pseudo-destructor expression has no run-time semantics
1160/// beyond evaluating the base expression.
1161class CXXPseudoDestructorExpr : public Expr {
1162  /// \brief The base expression (that is being destroyed).
1163  Stmt *Base;
1164
1165  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1166  /// period ('.').
1167  bool IsArrow : 1;
1168
1169  /// \brief The location of the '.' or '->' operator.
1170  SourceLocation OperatorLoc;
1171
1172  /// \brief The nested-name-specifier that follows the operator, if present.
1173  NestedNameSpecifier *Qualifier;
1174
1175  /// \brief The source range that covers the nested-name-specifier, if
1176  /// present.
1177  SourceRange QualifierRange;
1178
1179  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1180  /// expression.
1181  TypeSourceInfo *ScopeType;
1182
1183  /// \brief The location of the '::' in a qualified pseudo-destructor
1184  /// expression.
1185  SourceLocation ColonColonLoc;
1186
1187  /// \brief The location of the '~'.
1188  SourceLocation TildeLoc;
1189
1190  /// \brief The type being destroyed, or its name if we were unable to
1191  /// resolve the name.
1192  PseudoDestructorTypeStorage DestroyedType;
1193
1194public:
1195  CXXPseudoDestructorExpr(ASTContext &Context,
1196                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1197                          NestedNameSpecifier *Qualifier,
1198                          SourceRange QualifierRange,
1199                          TypeSourceInfo *ScopeType,
1200                          SourceLocation ColonColonLoc,
1201                          SourceLocation TildeLoc,
1202                          PseudoDestructorTypeStorage DestroyedType)
1203    : Expr(CXXPseudoDestructorExprClass,
1204           Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
1205                                                          false, 0, false,
1206                                                          false, 0, 0,
1207                                                      FunctionType::ExtInfo())),
1208           /*isTypeDependent=*/(Base->isTypeDependent() ||
1209            (DestroyedType.getTypeSourceInfo() &&
1210              DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
1211           /*isValueDependent=*/Base->isValueDependent()),
1212      Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
1213      OperatorLoc(OperatorLoc), Qualifier(Qualifier),
1214      QualifierRange(QualifierRange),
1215      ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
1216      DestroyedType(DestroyedType) { }
1217
1218  void setBase(Expr *E) { Base = E; }
1219  Expr *getBase() const { return cast<Expr>(Base); }
1220
1221  /// \brief Determines whether this member expression actually had
1222  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1223  /// x->Base::foo.
1224  bool hasQualifier() const { return Qualifier != 0; }
1225
1226  /// \brief If the member name was qualified, retrieves the source range of
1227  /// the nested-name-specifier that precedes the member name. Otherwise,
1228  /// returns an empty source range.
1229  SourceRange getQualifierRange() const { return QualifierRange; }
1230
1231  /// \brief If the member name was qualified, retrieves the
1232  /// nested-name-specifier that precedes the member name. Otherwise, returns
1233  /// NULL.
1234  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1235
1236  /// \brief Determine whether this pseudo-destructor expression was written
1237  /// using an '->' (otherwise, it used a '.').
1238  bool isArrow() const { return IsArrow; }
1239  void setArrow(bool A) { IsArrow = A; }
1240
1241  /// \brief Retrieve the location of the '.' or '->' operator.
1242  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1243
1244  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1245  /// expression.
1246  ///
1247  /// Pseudo-destructor expressions can have extra qualification within them
1248  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1249  /// Here, if the object type of the expression is (or may be) a scalar type,
1250  /// \p T may also be a scalar type and, therefore, cannot be part of a
1251  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1252  /// destructor expression.
1253  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1254
1255  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1256  /// expression.
1257  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1258
1259  /// \brief Retrieve the location of the '~'.
1260  SourceLocation getTildeLoc() const { return TildeLoc; }
1261
1262  /// \brief Retrieve the source location information for the type
1263  /// being destroyed.
1264  ///
1265  /// This type-source information is available for non-dependent
1266  /// pseudo-destructor expressions and some dependent pseudo-destructor
1267  /// expressions. Returns NULL if we only have the identifier for a
1268  /// dependent pseudo-destructor expression.
1269  TypeSourceInfo *getDestroyedTypeInfo() const {
1270    return DestroyedType.getTypeSourceInfo();
1271  }
1272
1273  /// \brief In a dependent pseudo-destructor expression for which we do not
1274  /// have full type information on the destroyed type, provides the name
1275  /// of the destroyed type.
1276  IdentifierInfo *getDestroyedTypeIdentifier() const {
1277    return DestroyedType.getIdentifier();
1278  }
1279
1280  /// \brief Retrieve the type being destroyed.
1281  QualType getDestroyedType() const;
1282
1283  /// \brief Retrieve the starting location of the type being destroyed.
1284  SourceLocation getDestroyedTypeLoc() const {
1285    return DestroyedType.getLocation();
1286  }
1287
1288  virtual SourceRange getSourceRange() const;
1289
1290  static bool classof(const Stmt *T) {
1291    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1292  }
1293  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1294
1295  // Iterators
1296  virtual child_iterator child_begin();
1297  virtual child_iterator child_end();
1298};
1299
1300/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1301/// implementation of TR1/C++0x type trait templates.
1302/// Example:
1303/// __is_pod(int) == true
1304/// __is_enum(std::string) == false
1305class UnaryTypeTraitExpr : public Expr {
1306  /// UTT - The trait.
1307  UnaryTypeTrait UTT;
1308
1309  /// Loc - The location of the type trait keyword.
1310  SourceLocation Loc;
1311
1312  /// RParen - The location of the closing paren.
1313  SourceLocation RParen;
1314
1315  /// QueriedType - The type we're testing.
1316  QualType QueriedType;
1317
1318public:
1319  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried,
1320                     SourceLocation rparen, QualType ty)
1321    : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
1322      UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
1323
1324  virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1325
1326  UnaryTypeTrait getTrait() const { return UTT; }
1327
1328  QualType getQueriedType() const { return QueriedType; }
1329
1330  bool EvaluateTrait(ASTContext&) const;
1331
1332  static bool classof(const Stmt *T) {
1333    return T->getStmtClass() == UnaryTypeTraitExprClass;
1334  }
1335  static bool classof(const UnaryTypeTraitExpr *) { return true; }
1336
1337  // Iterators
1338  virtual child_iterator child_begin();
1339  virtual child_iterator child_end();
1340};
1341
1342/// \brief A reference to an overloaded function set, either an
1343/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1344class OverloadExpr : public Expr {
1345  /// The results.  These are undesugared, which is to say, they may
1346  /// include UsingShadowDecls.  Access is relative to the naming
1347  /// class.
1348  UnresolvedSet<4> Results;
1349
1350  /// The common name of these declarations.
1351  DeclarationName Name;
1352
1353  /// The scope specifier, if any.
1354  NestedNameSpecifier *Qualifier;
1355
1356  /// The source range of the scope specifier.
1357  SourceRange QualifierRange;
1358
1359  /// The location of the name.
1360  SourceLocation NameLoc;
1361
1362  /// True if the name was a template-id.
1363  bool HasExplicitTemplateArgs;
1364
1365protected:
1366  OverloadExpr(StmtClass K, QualType T, bool Dependent,
1367               NestedNameSpecifier *Qualifier, SourceRange QRange,
1368               DeclarationName Name, SourceLocation NameLoc,
1369               bool HasTemplateArgs,
1370               UnresolvedSetIterator Begin, UnresolvedSetIterator End)
1371    : Expr(K, T, Dependent, Dependent),
1372      Name(Name), Qualifier(Qualifier), QualifierRange(QRange),
1373      NameLoc(NameLoc), HasExplicitTemplateArgs(HasTemplateArgs)
1374  {
1375    Results.append(Begin, End);
1376  }
1377
1378public:
1379  /// Computes whether an unresolved lookup on the given declarations
1380  /// and optional template arguments is type- and value-dependent.
1381  static bool ComputeDependence(UnresolvedSetIterator Begin,
1382                                UnresolvedSetIterator End,
1383                                const TemplateArgumentListInfo *Args);
1384
1385  /// Finds the overloaded expression in the given expression of
1386  /// OverloadTy.
1387  ///
1388  /// \return the expression (which must be there) and true if it is
1389  /// within an address-of operator.
1390  static llvm::PointerIntPair<OverloadExpr*,1> find(Expr *E) {
1391    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1392
1393    bool op = false;
1394    E = E->IgnoreParens();
1395    if (isa<UnaryOperator>(E))
1396      op = true, E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
1397    return llvm::PointerIntPair<OverloadExpr*,1>(cast<OverloadExpr>(E), op);
1398  }
1399
1400  /// Gets the naming class of this lookup, if any.
1401  CXXRecordDecl *getNamingClass() const;
1402
1403  typedef UnresolvedSetImpl::iterator decls_iterator;
1404  decls_iterator decls_begin() const { return Results.begin(); }
1405  decls_iterator decls_end() const { return Results.end(); }
1406
1407  /// Gets the number of declarations in the unresolved set.
1408  unsigned getNumDecls() const { return Results.size(); }
1409
1410  /// Gets the name looked up.
1411  DeclarationName getName() const { return Name; }
1412  void setName(DeclarationName N) { Name = N; }
1413
1414  /// Gets the location of the name.
1415  SourceLocation getNameLoc() const { return NameLoc; }
1416  void setNameLoc(SourceLocation Loc) { NameLoc = Loc; }
1417
1418  /// Fetches the nested-name qualifier, if one was given.
1419  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1420
1421  /// Fetches the range of the nested-name qualifier.
1422  SourceRange getQualifierRange() const { return QualifierRange; }
1423
1424  /// \brief Determines whether this expression had an explicit
1425  /// template argument list, e.g. f<int>.
1426  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1427
1428  ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
1429
1430  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1431    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1432  }
1433
1434  ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1435    if (hasExplicitTemplateArgs())
1436      return &getExplicitTemplateArgs();
1437    return 0;
1438  }
1439
1440  static bool classof(const Stmt *T) {
1441    return T->getStmtClass() == UnresolvedLookupExprClass ||
1442           T->getStmtClass() == UnresolvedMemberExprClass;
1443  }
1444  static bool classof(const OverloadExpr *) { return true; }
1445};
1446
1447/// \brief A reference to a name which we were able to look up during
1448/// parsing but could not resolve to a specific declaration.  This
1449/// arises in several ways:
1450///   * we might be waiting for argument-dependent lookup
1451///   * the name might resolve to an overloaded function
1452/// and eventually:
1453///   * the lookup might have included a function template
1454/// These never include UnresolvedUsingValueDecls, which are always
1455/// class members and therefore appear only in
1456/// UnresolvedMemberLookupExprs.
1457class UnresolvedLookupExpr : public OverloadExpr {
1458  /// True if these lookup results should be extended by
1459  /// argument-dependent lookup if this is the operand of a function
1460  /// call.
1461  bool RequiresADL;
1462
1463  /// True if these lookup results are overloaded.  This is pretty
1464  /// trivially rederivable if we urgently need to kill this field.
1465  bool Overloaded;
1466
1467  /// The naming class (C++ [class.access.base]p5) of the lookup, if
1468  /// any.  This can generally be recalculated from the context chain,
1469  /// but that can be fairly expensive for unqualified lookups.  If we
1470  /// want to improve memory use here, this could go in a union
1471  /// against the qualified-lookup bits.
1472  CXXRecordDecl *NamingClass;
1473
1474  UnresolvedLookupExpr(QualType T, bool Dependent, CXXRecordDecl *NamingClass,
1475                       NestedNameSpecifier *Qualifier, SourceRange QRange,
1476                       DeclarationName Name, SourceLocation NameLoc,
1477                       bool RequiresADL, bool Overloaded, bool HasTemplateArgs,
1478                       UnresolvedSetIterator Begin, UnresolvedSetIterator End)
1479    : OverloadExpr(UnresolvedLookupExprClass, T, Dependent, Qualifier, QRange,
1480                   Name, NameLoc, HasTemplateArgs, Begin, End),
1481      RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1482  {}
1483
1484public:
1485  static UnresolvedLookupExpr *Create(ASTContext &C,
1486                                      bool Dependent,
1487                                      CXXRecordDecl *NamingClass,
1488                                      NestedNameSpecifier *Qualifier,
1489                                      SourceRange QualifierRange,
1490                                      DeclarationName Name,
1491                                      SourceLocation NameLoc,
1492                                      bool ADL, bool Overloaded,
1493                                      UnresolvedSetIterator Begin,
1494                                      UnresolvedSetIterator End) {
1495    return new(C) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy,
1496                                       Dependent, NamingClass,
1497                                       Qualifier, QualifierRange,
1498                                       Name, NameLoc, ADL, Overloaded, false,
1499                                       Begin, End);
1500  }
1501
1502  static UnresolvedLookupExpr *Create(ASTContext &C,
1503                                      bool Dependent,
1504                                      CXXRecordDecl *NamingClass,
1505                                      NestedNameSpecifier *Qualifier,
1506                                      SourceRange QualifierRange,
1507                                      DeclarationName Name,
1508                                      SourceLocation NameLoc,
1509                                      bool ADL,
1510                                      const TemplateArgumentListInfo &Args,
1511                                      UnresolvedSetIterator Begin,
1512                                      UnresolvedSetIterator End);
1513
1514  /// True if this declaration should be extended by
1515  /// argument-dependent lookup.
1516  bool requiresADL() const { return RequiresADL; }
1517
1518  /// True if this lookup is overloaded.
1519  bool isOverloaded() const { return Overloaded; }
1520
1521  /// Gets the 'naming class' (in the sense of C++0x
1522  /// [class.access.base]p5) of the lookup.  This is the scope
1523  /// that was looked in to find these results.
1524  CXXRecordDecl *getNamingClass() const { return NamingClass; }
1525
1526  // Note that, inconsistently with the explicit-template-argument AST
1527  // nodes, users are *forbidden* from calling these methods on objects
1528  // without explicit template arguments.
1529
1530  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1531    assert(hasExplicitTemplateArgs());
1532    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1533  }
1534
1535  /// Gets a reference to the explicit template argument list.
1536  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1537    assert(hasExplicitTemplateArgs());
1538    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1539  }
1540
1541  /// \brief Copies the template arguments (if present) into the given
1542  /// structure.
1543  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1544    getExplicitTemplateArgs().copyInto(List);
1545  }
1546
1547  SourceLocation getLAngleLoc() const {
1548    return getExplicitTemplateArgs().LAngleLoc;
1549  }
1550
1551  SourceLocation getRAngleLoc() const {
1552    return getExplicitTemplateArgs().RAngleLoc;
1553  }
1554
1555  TemplateArgumentLoc const *getTemplateArgs() const {
1556    return getExplicitTemplateArgs().getTemplateArgs();
1557  }
1558
1559  unsigned getNumTemplateArgs() const {
1560    return getExplicitTemplateArgs().NumTemplateArgs;
1561  }
1562
1563  virtual SourceRange getSourceRange() const {
1564    SourceRange Range(getNameLoc());
1565    if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
1566    if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
1567    return Range;
1568  }
1569
1570  virtual StmtIterator child_begin();
1571  virtual StmtIterator child_end();
1572
1573  static bool classof(const Stmt *T) {
1574    return T->getStmtClass() == UnresolvedLookupExprClass;
1575  }
1576  static bool classof(const UnresolvedLookupExpr *) { return true; }
1577};
1578
1579/// \brief A qualified reference to a name whose declaration cannot
1580/// yet be resolved.
1581///
1582/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1583/// it expresses a reference to a declaration such as
1584/// X<T>::value. The difference, however, is that an
1585/// DependentScopeDeclRefExpr node is used only within C++ templates when
1586/// the qualification (e.g., X<T>::) refers to a dependent type. In
1587/// this case, X<T>::value cannot resolve to a declaration because the
1588/// declaration will differ from on instantiation of X<T> to the
1589/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1590/// qualifier (X<T>::) and the name of the entity being referenced
1591/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1592/// declaration can be found.
1593class DependentScopeDeclRefExpr : public Expr {
1594  /// The name of the entity we will be referencing.
1595  DeclarationName Name;
1596
1597  /// Location of the name of the declaration we're referencing.
1598  SourceLocation Loc;
1599
1600  /// QualifierRange - The source range that covers the
1601  /// nested-name-specifier.
1602  SourceRange QualifierRange;
1603
1604  /// \brief The nested-name-specifier that qualifies this unresolved
1605  /// declaration name.
1606  NestedNameSpecifier *Qualifier;
1607
1608  /// \brief Whether the name includes explicit template arguments.
1609  bool HasExplicitTemplateArgs;
1610
1611  DependentScopeDeclRefExpr(QualType T,
1612                            NestedNameSpecifier *Qualifier,
1613                            SourceRange QualifierRange,
1614                            DeclarationName Name,
1615                            SourceLocation NameLoc,
1616                            bool HasExplicitTemplateArgs)
1617    : Expr(DependentScopeDeclRefExprClass, T, true, true),
1618      Name(Name), Loc(NameLoc),
1619      QualifierRange(QualifierRange), Qualifier(Qualifier),
1620      HasExplicitTemplateArgs(HasExplicitTemplateArgs)
1621  {}
1622
1623public:
1624  static DependentScopeDeclRefExpr *Create(ASTContext &C,
1625                                           NestedNameSpecifier *Qualifier,
1626                                           SourceRange QualifierRange,
1627                                           DeclarationName Name,
1628                                           SourceLocation NameLoc,
1629                              const TemplateArgumentListInfo *TemplateArgs = 0);
1630
1631  /// \brief Retrieve the name that this expression refers to.
1632  DeclarationName getDeclName() const { return Name; }
1633
1634  /// \brief Retrieve the location of the name within the expression.
1635  SourceLocation getLocation() const { return Loc; }
1636
1637  /// \brief Retrieve the source range of the nested-name-specifier.
1638  SourceRange getQualifierRange() const { return QualifierRange; }
1639
1640  /// \brief Retrieve the nested-name-specifier that qualifies this
1641  /// declaration.
1642  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1643
1644  /// Determines whether this lookup had explicit template arguments.
1645  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1646
1647  // Note that, inconsistently with the explicit-template-argument AST
1648  // nodes, users are *forbidden* from calling these methods on objects
1649  // without explicit template arguments.
1650
1651  /// Gets a reference to the explicit template argument list.
1652  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1653    assert(hasExplicitTemplateArgs());
1654    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1655  }
1656
1657  /// \brief Copies the template arguments (if present) into the given
1658  /// structure.
1659  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1660    getExplicitTemplateArgs().copyInto(List);
1661  }
1662
1663  SourceLocation getLAngleLoc() const {
1664    return getExplicitTemplateArgs().LAngleLoc;
1665  }
1666
1667  SourceLocation getRAngleLoc() const {
1668    return getExplicitTemplateArgs().RAngleLoc;
1669  }
1670
1671  TemplateArgumentLoc const *getTemplateArgs() const {
1672    return getExplicitTemplateArgs().getTemplateArgs();
1673  }
1674
1675  unsigned getNumTemplateArgs() const {
1676    return getExplicitTemplateArgs().NumTemplateArgs;
1677  }
1678
1679  virtual SourceRange getSourceRange() const {
1680    SourceRange Range(QualifierRange.getBegin(), getLocation());
1681    if (hasExplicitTemplateArgs())
1682      Range.setEnd(getRAngleLoc());
1683    return Range;
1684  }
1685
1686  static bool classof(const Stmt *T) {
1687    return T->getStmtClass() == DependentScopeDeclRefExprClass;
1688  }
1689  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1690
1691  virtual StmtIterator child_begin();
1692  virtual StmtIterator child_end();
1693};
1694
1695class CXXExprWithTemporaries : public Expr {
1696  Stmt *SubExpr;
1697
1698  CXXTemporary **Temps;
1699  unsigned NumTemps;
1700
1701  CXXExprWithTemporaries(ASTContext &C, Expr *SubExpr, CXXTemporary **Temps,
1702                         unsigned NumTemps);
1703  ~CXXExprWithTemporaries();
1704
1705protected:
1706  virtual void DoDestroy(ASTContext &C);
1707
1708public:
1709  CXXExprWithTemporaries(EmptyShell Empty)
1710    : Expr(CXXExprWithTemporariesClass, Empty),
1711      SubExpr(0), Temps(0), NumTemps(0) {}
1712
1713  static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
1714                                        CXXTemporary **Temps,
1715                                        unsigned NumTemps);
1716
1717  unsigned getNumTemporaries() const { return NumTemps; }
1718  void setNumTemporaries(ASTContext &C, unsigned N);
1719
1720  CXXTemporary *getTemporary(unsigned i) {
1721    assert(i < NumTemps && "Index out of range");
1722    return Temps[i];
1723  }
1724  const CXXTemporary *getTemporary(unsigned i) const {
1725    return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i);
1726  }
1727  void setTemporary(unsigned i, CXXTemporary *T) {
1728    assert(i < NumTemps && "Index out of range");
1729    Temps[i] = T;
1730  }
1731
1732  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1733  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1734  void setSubExpr(Expr *E) { SubExpr = E; }
1735
1736  virtual SourceRange getSourceRange() const {
1737    return SubExpr->getSourceRange();
1738  }
1739
1740  // Implement isa/cast/dyncast/etc.
1741  static bool classof(const Stmt *T) {
1742    return T->getStmtClass() == CXXExprWithTemporariesClass;
1743  }
1744  static bool classof(const CXXExprWithTemporaries *) { return true; }
1745
1746  // Iterators
1747  virtual child_iterator child_begin();
1748  virtual child_iterator child_end();
1749};
1750
1751/// \brief Describes an explicit type conversion that uses functional
1752/// notion but could not be resolved because one or more arguments are
1753/// type-dependent.
1754///
1755/// The explicit type conversions expressed by
1756/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1757/// where \c T is some type and \c a1, a2, ..., aN are values, and
1758/// either \C T is a dependent type or one or more of the \c a's is
1759/// type-dependent. For example, this would occur in a template such
1760/// as:
1761///
1762/// \code
1763///   template<typename T, typename A1>
1764///   inline T make_a(const A1& a1) {
1765///     return T(a1);
1766///   }
1767/// \endcode
1768///
1769/// When the returned expression is instantiated, it may resolve to a
1770/// constructor call, conversion function call, or some kind of type
1771/// conversion.
1772class CXXUnresolvedConstructExpr : public Expr {
1773  /// \brief The starting location of the type
1774  SourceLocation TyBeginLoc;
1775
1776  /// \brief The type being constructed.
1777  QualType Type;
1778
1779  /// \brief The location of the left parentheses ('(').
1780  SourceLocation LParenLoc;
1781
1782  /// \brief The location of the right parentheses (')').
1783  SourceLocation RParenLoc;
1784
1785  /// \brief The number of arguments used to construct the type.
1786  unsigned NumArgs;
1787
1788  CXXUnresolvedConstructExpr(SourceLocation TyBegin,
1789                             QualType T,
1790                             SourceLocation LParenLoc,
1791                             Expr **Args,
1792                             unsigned NumArgs,
1793                             SourceLocation RParenLoc);
1794
1795public:
1796  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1797                                            SourceLocation TyBegin,
1798                                            QualType T,
1799                                            SourceLocation LParenLoc,
1800                                            Expr **Args,
1801                                            unsigned NumArgs,
1802                                            SourceLocation RParenLoc);
1803
1804  /// \brief Retrieve the source location where the type begins.
1805  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1806  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1807
1808  /// \brief Retrieve the type that is being constructed, as specified
1809  /// in the source code.
1810  QualType getTypeAsWritten() const { return Type; }
1811  void setTypeAsWritten(QualType T) { Type = T; }
1812
1813  /// \brief Retrieve the location of the left parentheses ('(') that
1814  /// precedes the argument list.
1815  SourceLocation getLParenLoc() const { return LParenLoc; }
1816  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1817
1818  /// \brief Retrieve the location of the right parentheses (')') that
1819  /// follows the argument list.
1820  SourceLocation getRParenLoc() const { return RParenLoc; }
1821  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1822
1823  /// \brief Retrieve the number of arguments.
1824  unsigned arg_size() const { return NumArgs; }
1825
1826  typedef Expr** arg_iterator;
1827  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1828  arg_iterator arg_end() { return arg_begin() + NumArgs; }
1829
1830  typedef const Expr* const * const_arg_iterator;
1831  const_arg_iterator arg_begin() const {
1832    return reinterpret_cast<const Expr* const *>(this + 1);
1833  }
1834  const_arg_iterator arg_end() const {
1835    return arg_begin() + NumArgs;
1836  }
1837
1838  Expr *getArg(unsigned I) {
1839    assert(I < NumArgs && "Argument index out-of-range");
1840    return *(arg_begin() + I);
1841  }
1842
1843  const Expr *getArg(unsigned I) const {
1844    assert(I < NumArgs && "Argument index out-of-range");
1845    return *(arg_begin() + I);
1846  }
1847
1848  virtual SourceRange getSourceRange() const {
1849    return SourceRange(TyBeginLoc, RParenLoc);
1850  }
1851  static bool classof(const Stmt *T) {
1852    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1853  }
1854  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
1855
1856  // Iterators
1857  virtual child_iterator child_begin();
1858  virtual child_iterator child_end();
1859};
1860
1861/// \brief Represents a C++ member access expression where the actual
1862/// member referenced could not be resolved because the base
1863/// expression or the member name was dependent.
1864///
1865/// Like UnresolvedMemberExprs, these can be either implicit or
1866/// explicit accesses.  It is only possible to get one of these with
1867/// an implicit access if a qualifier is provided.
1868class CXXDependentScopeMemberExpr : public Expr {
1869  /// \brief The expression for the base pointer or class reference,
1870  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
1871  Stmt *Base;
1872
1873  /// \brief The type of the base expression.  Never null, even for
1874  /// implicit accesses.
1875  QualType BaseType;
1876
1877  /// \brief Whether this member expression used the '->' operator or
1878  /// the '.' operator.
1879  bool IsArrow : 1;
1880
1881  /// \brief Whether this member expression has explicitly-specified template
1882  /// arguments.
1883  bool HasExplicitTemplateArgs : 1;
1884
1885  /// \brief The location of the '->' or '.' operator.
1886  SourceLocation OperatorLoc;
1887
1888  /// \brief The nested-name-specifier that precedes the member name, if any.
1889  NestedNameSpecifier *Qualifier;
1890
1891  /// \brief The source range covering the nested name specifier.
1892  SourceRange QualifierRange;
1893
1894  /// \brief In a qualified member access expression such as t->Base::f, this
1895  /// member stores the resolves of name lookup in the context of the member
1896  /// access expression, to be used at instantiation time.
1897  ///
1898  /// FIXME: This member, along with the Qualifier and QualifierRange, could
1899  /// be stuck into a structure that is optionally allocated at the end of
1900  /// the CXXDependentScopeMemberExpr, to save space in the common case.
1901  NamedDecl *FirstQualifierFoundInScope;
1902
1903  /// \brief The member to which this member expression refers, which
1904  /// can be name, overloaded operator, or destructor.
1905  /// FIXME: could also be a template-id
1906  DeclarationName Member;
1907
1908  /// \brief The location of the member name.
1909  SourceLocation MemberLoc;
1910
1911  /// \brief Retrieve the explicit template argument list that followed the
1912  /// member template name, if any.
1913  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
1914    assert(HasExplicitTemplateArgs);
1915    return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
1916  }
1917
1918  /// \brief Retrieve the explicit template argument list that followed the
1919  /// member template name, if any.
1920  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1921    return const_cast<CXXDependentScopeMemberExpr *>(this)
1922             ->getExplicitTemplateArgumentList();
1923  }
1924
1925  CXXDependentScopeMemberExpr(ASTContext &C,
1926                          Expr *Base, QualType BaseType, bool IsArrow,
1927                          SourceLocation OperatorLoc,
1928                          NestedNameSpecifier *Qualifier,
1929                          SourceRange QualifierRange,
1930                          NamedDecl *FirstQualifierFoundInScope,
1931                          DeclarationName Member,
1932                          SourceLocation MemberLoc,
1933                          const TemplateArgumentListInfo *TemplateArgs);
1934
1935public:
1936  CXXDependentScopeMemberExpr(ASTContext &C,
1937                          Expr *Base, QualType BaseType,
1938                          bool IsArrow,
1939                          SourceLocation OperatorLoc,
1940                          NestedNameSpecifier *Qualifier,
1941                          SourceRange QualifierRange,
1942                          NamedDecl *FirstQualifierFoundInScope,
1943                          DeclarationName Member,
1944                          SourceLocation MemberLoc)
1945  : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
1946    Base(Base), BaseType(BaseType), IsArrow(IsArrow),
1947    HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
1948    Qualifier(Qualifier), QualifierRange(QualifierRange),
1949    FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1950    Member(Member), MemberLoc(MemberLoc) { }
1951
1952  static CXXDependentScopeMemberExpr *
1953  Create(ASTContext &C,
1954         Expr *Base, QualType BaseType, bool IsArrow,
1955         SourceLocation OperatorLoc,
1956         NestedNameSpecifier *Qualifier,
1957         SourceRange QualifierRange,
1958         NamedDecl *FirstQualifierFoundInScope,
1959         DeclarationName Member,
1960         SourceLocation MemberLoc,
1961         const TemplateArgumentListInfo *TemplateArgs);
1962
1963  /// \brief True if this is an implicit access, i.e. one in which the
1964  /// member being accessed was not written in the source.  The source
1965  /// location of the operator is invalid in this case.
1966  bool isImplicitAccess() const { return Base == 0; }
1967
1968  /// \brief Retrieve the base object of this member expressions,
1969  /// e.g., the \c x in \c x.m.
1970  Expr *getBase() const {
1971    assert(!isImplicitAccess());
1972    return cast<Expr>(Base);
1973  }
1974  void setBase(Expr *E) { Base = E; }
1975
1976  QualType getBaseType() const { return BaseType; }
1977
1978  /// \brief Determine whether this member expression used the '->'
1979  /// operator; otherwise, it used the '.' operator.
1980  bool isArrow() const { return IsArrow; }
1981  void setArrow(bool A) { IsArrow = A; }
1982
1983  /// \brief Retrieve the location of the '->' or '.' operator.
1984  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1985  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1986
1987  /// \brief Retrieve the nested-name-specifier that qualifies the member
1988  /// name.
1989  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1990
1991  /// \brief Retrieve the source range covering the nested-name-specifier
1992  /// that qualifies the member name.
1993  SourceRange getQualifierRange() const { return QualifierRange; }
1994
1995  /// \brief Retrieve the first part of the nested-name-specifier that was
1996  /// found in the scope of the member access expression when the member access
1997  /// was initially parsed.
1998  ///
1999  /// This function only returns a useful result when member access expression
2000  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2001  /// returned by this function describes what was found by unqualified name
2002  /// lookup for the identifier "Base" within the scope of the member access
2003  /// expression itself. At template instantiation time, this information is
2004  /// combined with the results of name lookup into the type of the object
2005  /// expression itself (the class type of x).
2006  NamedDecl *getFirstQualifierFoundInScope() const {
2007    return FirstQualifierFoundInScope;
2008  }
2009
2010  /// \brief Retrieve the name of the member that this expression
2011  /// refers to.
2012  DeclarationName getMember() const { return Member; }
2013  void setMember(DeclarationName N) { Member = N; }
2014
2015  // \brief Retrieve the location of the name of the member that this
2016  // expression refers to.
2017  SourceLocation getMemberLoc() const { return MemberLoc; }
2018  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
2019
2020  /// \brief Determines whether this member expression actually had a C++
2021  /// template argument list explicitly specified, e.g., x.f<int>.
2022  bool hasExplicitTemplateArgs() const {
2023    return HasExplicitTemplateArgs;
2024  }
2025
2026  /// \brief Copies the template arguments (if present) into the given
2027  /// structure.
2028  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2029    assert(HasExplicitTemplateArgs);
2030    getExplicitTemplateArgumentList()->copyInto(List);
2031  }
2032
2033  /// \brief Retrieve the location of the left angle bracket following the
2034  /// member name ('<'), if any.
2035  SourceLocation getLAngleLoc() const {
2036    assert(HasExplicitTemplateArgs);
2037    return getExplicitTemplateArgumentList()->LAngleLoc;
2038  }
2039
2040  /// \brief Retrieve the template arguments provided as part of this
2041  /// template-id.
2042  const TemplateArgumentLoc *getTemplateArgs() const {
2043    assert(HasExplicitTemplateArgs);
2044    return getExplicitTemplateArgumentList()->getTemplateArgs();
2045  }
2046
2047  /// \brief Retrieve the number of template arguments provided as part of this
2048  /// template-id.
2049  unsigned getNumTemplateArgs() const {
2050    assert(HasExplicitTemplateArgs);
2051    return getExplicitTemplateArgumentList()->NumTemplateArgs;
2052  }
2053
2054  /// \brief Retrieve the location of the right angle bracket following the
2055  /// template arguments ('>').
2056  SourceLocation getRAngleLoc() const {
2057    assert(HasExplicitTemplateArgs);
2058    return getExplicitTemplateArgumentList()->RAngleLoc;
2059  }
2060
2061  virtual SourceRange getSourceRange() const {
2062    SourceRange Range;
2063    if (!isImplicitAccess())
2064      Range.setBegin(Base->getSourceRange().getBegin());
2065    else if (getQualifier())
2066      Range.setBegin(getQualifierRange().getBegin());
2067    else
2068      Range.setBegin(MemberLoc);
2069
2070    if (hasExplicitTemplateArgs())
2071      Range.setEnd(getRAngleLoc());
2072    else
2073      Range.setEnd(MemberLoc);
2074    return Range;
2075  }
2076
2077  static bool classof(const Stmt *T) {
2078    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
2079  }
2080  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
2081
2082  // Iterators
2083  virtual child_iterator child_begin();
2084  virtual child_iterator child_end();
2085};
2086
2087/// \brief Represents a C++ member access expression for which lookup
2088/// produced a set of overloaded functions.
2089///
2090/// The member access may be explicit or implicit:
2091///    struct A {
2092///      int a, b;
2093///      int explicitAccess() { return this->a + this->A::b; }
2094///      int implicitAccess() { return a + A::b; }
2095///    };
2096///
2097/// In the final AST, an explicit access always becomes a MemberExpr.
2098/// An implicit access may become either a MemberExpr or a
2099/// DeclRefExpr, depending on whether the member is static.
2100class UnresolvedMemberExpr : public OverloadExpr {
2101  /// \brief Whether this member expression used the '->' operator or
2102  /// the '.' operator.
2103  bool IsArrow : 1;
2104
2105  /// \brief Whether the lookup results contain an unresolved using
2106  /// declaration.
2107  bool HasUnresolvedUsing : 1;
2108
2109  /// \brief The expression for the base pointer or class reference,
2110  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
2111  /// member expression
2112  Stmt *Base;
2113
2114  /// \brief The type of the base expression;  never null.
2115  QualType BaseType;
2116
2117  /// \brief The location of the '->' or '.' operator.
2118  SourceLocation OperatorLoc;
2119
2120  UnresolvedMemberExpr(QualType T, bool Dependent,
2121                       bool HasUnresolvedUsing,
2122                       Expr *Base, QualType BaseType, bool IsArrow,
2123                       SourceLocation OperatorLoc,
2124                       NestedNameSpecifier *Qualifier,
2125                       SourceRange QualifierRange,
2126                       DeclarationName Member,
2127                       SourceLocation MemberLoc,
2128                       const TemplateArgumentListInfo *TemplateArgs,
2129                       UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2130
2131public:
2132  static UnresolvedMemberExpr *
2133  Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing,
2134         Expr *Base, QualType BaseType, bool IsArrow,
2135         SourceLocation OperatorLoc,
2136         NestedNameSpecifier *Qualifier,
2137         SourceRange QualifierRange,
2138         DeclarationName Member,
2139         SourceLocation MemberLoc,
2140         const TemplateArgumentListInfo *TemplateArgs,
2141         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2142
2143  /// \brief True if this is an implicit access, i.e. one in which the
2144  /// member being accessed was not written in the source.  The source
2145  /// location of the operator is invalid in this case.
2146  bool isImplicitAccess() const { return Base == 0; }
2147
2148  /// \brief Retrieve the base object of this member expressions,
2149  /// e.g., the \c x in \c x.m.
2150  Expr *getBase() {
2151    assert(!isImplicitAccess());
2152    return cast<Expr>(Base);
2153  }
2154  const Expr *getBase() const {
2155    assert(!isImplicitAccess());
2156    return cast<Expr>(Base);
2157  }
2158  void setBase(Expr *E) { Base = E; }
2159
2160  QualType getBaseType() const { return BaseType; }
2161
2162  /// \brief Determine whether this member expression used the '->'
2163  /// operator; otherwise, it used the '.' operator.
2164  bool isArrow() const { return IsArrow; }
2165  void setArrow(bool A) { IsArrow = A; }
2166
2167  /// \brief Retrieve the location of the '->' or '.' operator.
2168  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2169  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2170
2171  /// \brief Retrieves the naming class of this lookup.
2172  CXXRecordDecl *getNamingClass() const;
2173
2174  /// \brief Retrieve the name of the member that this expression
2175  /// refers to.
2176  DeclarationName getMemberName() const { return getName(); }
2177  void setMemberName(DeclarationName N) { setName(N); }
2178
2179  // \brief Retrieve the location of the name of the member that this
2180  // expression refers to.
2181  SourceLocation getMemberLoc() const { return getNameLoc(); }
2182  void setMemberLoc(SourceLocation L) { setNameLoc(L); }
2183
2184  /// \brief Retrieve the explicit template argument list that followed the
2185  /// member template name.
2186  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2187    assert(hasExplicitTemplateArgs());
2188    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2189  }
2190
2191  /// \brief Retrieve the explicit template argument list that followed the
2192  /// member template name, if any.
2193  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2194    assert(hasExplicitTemplateArgs());
2195    return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2196  }
2197
2198  /// \brief Copies the template arguments into the given structure.
2199  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2200    getExplicitTemplateArgs().copyInto(List);
2201  }
2202
2203  /// \brief Retrieve the location of the left angle bracket following
2204  /// the member name ('<').
2205  SourceLocation getLAngleLoc() const {
2206    return getExplicitTemplateArgs().LAngleLoc;
2207  }
2208
2209  /// \brief Retrieve the template arguments provided as part of this
2210  /// template-id.
2211  const TemplateArgumentLoc *getTemplateArgs() const {
2212    return getExplicitTemplateArgs().getTemplateArgs();
2213  }
2214
2215  /// \brief Retrieve the number of template arguments provided as
2216  /// part of this template-id.
2217  unsigned getNumTemplateArgs() const {
2218    return getExplicitTemplateArgs().NumTemplateArgs;
2219  }
2220
2221  /// \brief Retrieve the location of the right angle bracket
2222  /// following the template arguments ('>').
2223  SourceLocation getRAngleLoc() const {
2224    return getExplicitTemplateArgs().RAngleLoc;
2225  }
2226
2227  virtual SourceRange getSourceRange() const {
2228    SourceRange Range;
2229    if (!isImplicitAccess())
2230      Range.setBegin(Base->getSourceRange().getBegin());
2231    else if (getQualifier())
2232      Range.setBegin(getQualifierRange().getBegin());
2233    else
2234      Range.setBegin(getMemberLoc());
2235
2236    if (hasExplicitTemplateArgs())
2237      Range.setEnd(getRAngleLoc());
2238    else
2239      Range.setEnd(getMemberLoc());
2240    return Range;
2241  }
2242
2243  static bool classof(const Stmt *T) {
2244    return T->getStmtClass() == UnresolvedMemberExprClass;
2245  }
2246  static bool classof(const UnresolvedMemberExpr *) { return true; }
2247
2248  // Iterators
2249  virtual child_iterator child_begin();
2250  virtual child_iterator child_end();
2251};
2252
2253inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2254  if (isa<UnresolvedLookupExpr>(this))
2255    return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2256  else
2257    return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2258}
2259
2260}  // end namespace clang
2261
2262#endif
2263