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