]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/ExprCXX.h
Merge ACPICA 20110211.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / ExprCXX.h
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
22 namespace 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.
47 class CXXOperatorCallExpr : public CallExpr {
48   /// \brief The overloaded operator.
49   OverloadedOperatorKind Operator;
50
51 public:
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).
89 class CXXMemberCallExpr : public CallExpr {
90 public:
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.
118 class CXXNamedCastExpr : public ExplicitCastExpr {
119 private:
120   SourceLocation Loc; // the location of the casting op
121
122 protected:
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
131 public:
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).
160 class 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
170 public:
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).
190 class 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
200 public:
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).
221 class 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
231 public:
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).
250 class 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
259 public:
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 ///
272 class CXXBoolLiteralExpr : public Expr {
273   bool Value;
274   SourceLocation Loc;
275 public:
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
301 class CXXNullPtrLiteralExpr : public Expr {
302   SourceLocation Loc;
303 public:
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)
329 class CXXTypeidExpr : public Expr {
330 private:
331   llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
332   SourceRange Range;
333
334 public:
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
410 class CXXThisExpr : public Expr {
411   SourceLocation Loc;
412   bool Implicit : 1;
413   
414 public:
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 ///
446 class CXXThrowExpr : public Expr {
447   Stmt *Op;
448   SourceLocation ThrowLoc;
449 public:
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.
484 class 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   
509 public:
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.
567 class CXXTemporary {
568   /// Destructor - The destructor that needs to be called.
569   const CXXDestructorDecl *Destructor;
570
571   CXXTemporary(const CXXDestructorDecl *destructor)
572     : Destructor(destructor) { }
573
574 public:
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
595 class 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
604 public:
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 /// CXXConstructExpr - Represents a call to a C++ constructor.
635 class CXXConstructExpr : public Expr {
636 public:
637   enum ConstructionKind {
638     CK_Complete,
639     CK_NonVirtualBase,
640     CK_VirtualBase
641   };
642     
643 private:
644   CXXConstructorDecl *Constructor;
645
646   SourceLocation Loc;
647   bool Elidable : 1;
648   bool ZeroInitialization : 1;
649   unsigned ConstructKind : 2;
650   Stmt **Args;
651   unsigned NumArgs;
652
653 protected:
654   CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
655                    SourceLocation Loc,
656                    CXXConstructorDecl *d, bool elidable,
657                    Expr **args, unsigned numargs,
658                    bool ZeroInitialization = false,
659                    ConstructionKind ConstructKind = CK_Complete);
660
661   /// \brief Construct an empty C++ construction expression.
662   CXXConstructExpr(StmtClass SC, EmptyShell Empty)
663     : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0),
664       ConstructKind(0), Args(0), NumArgs(0) { }
665
666 public:
667   /// \brief Construct an empty C++ construction expression.
668   explicit CXXConstructExpr(EmptyShell Empty)
669     : Expr(CXXConstructExprClass, Empty), Constructor(0),
670       Elidable(0), ZeroInitialization(0),
671       ConstructKind(0), Args(0), NumArgs(0) { }
672
673   static CXXConstructExpr *Create(ASTContext &C, QualType T,
674                                   SourceLocation Loc,
675                                   CXXConstructorDecl *D, bool Elidable,
676                                   Expr **Args, unsigned NumArgs,
677                                   bool ZeroInitialization = false,
678                                   ConstructionKind ConstructKind = CK_Complete);
679
680
681   CXXConstructorDecl* getConstructor() const { return Constructor; }
682   void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
683   
684   SourceLocation getLocation() const { return Loc; }
685   void setLocation(SourceLocation Loc) { this->Loc = Loc; }
686   
687   /// \brief Whether this construction is elidable.
688   bool isElidable() const { return Elidable; }
689   void setElidable(bool E) { Elidable = E; }
690   
691   /// \brief Whether this construction first requires
692   /// zero-initialization before the initializer is called.
693   bool requiresZeroInitialization() const { return ZeroInitialization; }
694   void setRequiresZeroInitialization(bool ZeroInit) {
695     ZeroInitialization = ZeroInit;
696   }
697   
698   /// \brief Determines whether this constructor is actually constructing
699   /// a base class (rather than a complete object).
700   ConstructionKind getConstructionKind() const {
701     return (ConstructionKind)ConstructKind;
702   }
703   void setConstructionKind(ConstructionKind CK) { 
704     ConstructKind = CK;
705   }
706   
707   typedef ExprIterator arg_iterator;
708   typedef ConstExprIterator const_arg_iterator;
709
710   arg_iterator arg_begin() { return Args; }
711   arg_iterator arg_end() { return Args + NumArgs; }
712   const_arg_iterator arg_begin() const { return Args; }
713   const_arg_iterator arg_end() const { return Args + NumArgs; }
714
715   Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
716   unsigned getNumArgs() const { return NumArgs; }
717
718   /// getArg - Return the specified argument.
719   Expr *getArg(unsigned Arg) {
720     assert(Arg < NumArgs && "Arg access out of range!");
721     return cast<Expr>(Args[Arg]);
722   }
723   const Expr *getArg(unsigned Arg) const {
724     assert(Arg < NumArgs && "Arg access out of range!");
725     return cast<Expr>(Args[Arg]);
726   }
727
728   /// setArg - Set the specified argument.
729   void setArg(unsigned Arg, Expr *ArgExpr) {
730     assert(Arg < NumArgs && "Arg access out of range!");
731     Args[Arg] = ArgExpr;
732   }
733
734   virtual SourceRange getSourceRange() const;
735
736   static bool classof(const Stmt *T) {
737     return T->getStmtClass() == CXXConstructExprClass ||
738       T->getStmtClass() == CXXTemporaryObjectExprClass;
739   }
740   static bool classof(const CXXConstructExpr *) { return true; }
741
742   // Iterators
743   virtual child_iterator child_begin();
744   virtual child_iterator child_end();
745
746   friend class ASTStmtReader;
747 };
748
749 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
750 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
751 /// x = int(0.5);
752 class CXXFunctionalCastExpr : public ExplicitCastExpr {
753   SourceLocation TyBeginLoc;
754   SourceLocation RParenLoc;
755
756   CXXFunctionalCastExpr(QualType ty, TypeSourceInfo *writtenTy,
757                         SourceLocation tyBeginLoc, CastKind kind,
758                         Expr *castExpr, unsigned pathSize,
759                         SourceLocation rParenLoc) 
760     : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr, 
761                        pathSize, writtenTy),
762       TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
763
764   explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
765     : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
766
767 public:
768   static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
769                                        TypeSourceInfo *Written,
770                                        SourceLocation TyBeginLoc,
771                                        CastKind Kind, Expr *Op,
772                                        const CXXCastPath *Path,
773                                        SourceLocation RPLoc);
774   static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
775                                             unsigned PathSize);
776
777   SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
778   void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
779   SourceLocation getRParenLoc() const { return RParenLoc; }
780   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
781
782   virtual SourceRange getSourceRange() const {
783     return SourceRange(TyBeginLoc, RParenLoc);
784   }
785   static bool classof(const Stmt *T) {
786     return T->getStmtClass() == CXXFunctionalCastExprClass;
787   }
788   static bool classof(const CXXFunctionalCastExpr *) { return true; }
789 };
790
791 /// @brief Represents a C++ functional cast expression that builds a
792 /// temporary object.
793 ///
794 /// This expression type represents a C++ "functional" cast
795 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
796 /// constructor to build a temporary object. With N == 1 arguments the 
797 /// functional cast expression will be represented by CXXFunctionalCastExpr.
798 /// Example:
799 /// @code
800 /// struct X { X(int, float); }
801 ///
802 /// X create_X() {
803 ///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
804 /// };
805 /// @endcode
806 class CXXTemporaryObjectExpr : public CXXConstructExpr {
807   SourceLocation TyBeginLoc;
808   SourceLocation RParenLoc;
809
810 public:
811   CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
812                          QualType writtenTy, SourceLocation tyBeginLoc,
813                          Expr **Args,unsigned NumArgs,
814                          SourceLocation rParenLoc,
815                          bool ZeroInitialization = false);
816   explicit CXXTemporaryObjectExpr(EmptyShell Empty)
817     : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty) { }
818
819   SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
820   SourceLocation getRParenLoc() const { return RParenLoc; }
821
822   virtual SourceRange getSourceRange() const {
823     return SourceRange(TyBeginLoc, RParenLoc);
824   }
825   static bool classof(const Stmt *T) {
826     return T->getStmtClass() == CXXTemporaryObjectExprClass;
827   }
828   static bool classof(const CXXTemporaryObjectExpr *) { return true; }
829
830   friend class ASTStmtReader;
831 };
832
833 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
834 /// Expression "T()" which creates a value-initialized rvalue of type
835 /// T, which is a non-class type.
836 ///
837 class CXXScalarValueInitExpr : public Expr {
838   SourceLocation TyBeginLoc;
839   SourceLocation RParenLoc;
840
841 public:
842   CXXScalarValueInitExpr(QualType ty, SourceLocation tyBeginLoc,
843                        SourceLocation rParenLoc ) :
844     Expr(CXXScalarValueInitExprClass, ty, false, false),
845     TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
846   explicit CXXScalarValueInitExpr(EmptyShell Shell)
847     : Expr(CXXScalarValueInitExprClass, Shell) { }
848
849   SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
850   SourceLocation getRParenLoc() const { return RParenLoc; }
851
852   void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
853   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
854   
855   /// @brief Whether this initialization expression was
856   /// implicitly-generated.
857   bool isImplicit() const {
858     return TyBeginLoc.isInvalid() && RParenLoc.isInvalid();
859   }
860
861   virtual SourceRange getSourceRange() const {
862     return SourceRange(TyBeginLoc, RParenLoc);
863   }
864
865   static bool classof(const Stmt *T) {
866     return T->getStmtClass() == CXXScalarValueInitExprClass;
867   }
868   static bool classof(const CXXScalarValueInitExpr *) { return true; }
869
870   // Iterators
871   virtual child_iterator child_begin();
872   virtual child_iterator child_end();
873 };
874
875 /// CXXNewExpr - A new expression for memory allocation and constructor calls,
876 /// e.g: "new CXXNewExpr(foo)".
877 class CXXNewExpr : public Expr {
878   // Was the usage ::new, i.e. is the global new to be used?
879   bool GlobalNew : 1;
880   // Is there an initializer? If not, built-ins are uninitialized, else they're
881   // value-initialized.
882   bool Initializer : 1;
883   // Do we allocate an array? If so, the first SubExpr is the size expression.
884   bool Array : 1;
885   // The number of placement new arguments.
886   unsigned NumPlacementArgs : 15;
887   // The number of constructor arguments. This may be 1 even for non-class
888   // types; use the pseudo copy constructor.
889   unsigned NumConstructorArgs : 14;
890   // Contains an optional array size expression, any number of optional
891   // placement arguments, and any number of optional constructor arguments,
892   // in that order.
893   Stmt **SubExprs;
894   // Points to the allocation function used.
895   FunctionDecl *OperatorNew;
896   // Points to the deallocation function used in case of error. May be null.
897   FunctionDecl *OperatorDelete;
898   // Points to the constructor used. Cannot be null if AllocType is a record;
899   // it would still point at the default constructor (even an implicit one).
900   // Must be null for all other types.
901   CXXConstructorDecl *Constructor;
902
903   /// \brief If the allocated type was expressed as a parenthesized type-id, 
904   /// the source range covering the parenthesized type-id.
905   SourceRange TypeIdParens;
906   
907   SourceLocation StartLoc;
908   SourceLocation EndLoc;
909
910   friend class ASTStmtReader;
911 public:
912   CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
913              Expr **placementArgs, unsigned numPlaceArgs,
914              SourceRange TypeIdParens,
915              Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
916              Expr **constructorArgs, unsigned numConsArgs,
917              FunctionDecl *operatorDelete, QualType ty,
918              SourceLocation startLoc, SourceLocation endLoc);
919   explicit CXXNewExpr(EmptyShell Shell)
920     : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
921
922   void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
923                          unsigned numConsArgs);
924   
925   QualType getAllocatedType() const {
926     assert(getType()->isPointerType());
927     return getType()->getAs<PointerType>()->getPointeeType();
928   }
929
930   FunctionDecl *getOperatorNew() const { return OperatorNew; }
931   void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
932   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
933   void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
934   CXXConstructorDecl *getConstructor() const { return Constructor; }
935   void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
936
937   bool isArray() const { return Array; }
938   Expr *getArraySize() {
939     return Array ? cast<Expr>(SubExprs[0]) : 0;
940   }
941   const Expr *getArraySize() const {
942     return Array ? cast<Expr>(SubExprs[0]) : 0;
943   }
944
945   unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
946   Expr *getPlacementArg(unsigned i) {
947     assert(i < NumPlacementArgs && "Index out of range");
948     return cast<Expr>(SubExprs[Array + i]);
949   }
950   const Expr *getPlacementArg(unsigned i) const {
951     assert(i < NumPlacementArgs && "Index out of range");
952     return cast<Expr>(SubExprs[Array + i]);
953   }
954
955   bool isParenTypeId() const { return TypeIdParens.isValid(); }
956   SourceRange getTypeIdParens() const { return TypeIdParens; }
957
958   bool isGlobalNew() const { return GlobalNew; }
959   void setGlobalNew(bool V) { GlobalNew = V; }
960   bool hasInitializer() const { return Initializer; }
961   void setHasInitializer(bool V) { Initializer = V; }
962
963   unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
964   Expr *getConstructorArg(unsigned i) {
965     assert(i < NumConstructorArgs && "Index out of range");
966     return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
967   }
968   const Expr *getConstructorArg(unsigned i) const {
969     assert(i < NumConstructorArgs && "Index out of range");
970     return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
971   }
972
973   typedef ExprIterator arg_iterator;
974   typedef ConstExprIterator const_arg_iterator;
975
976   arg_iterator placement_arg_begin() {
977     return SubExprs + Array;
978   }
979   arg_iterator placement_arg_end() {
980     return SubExprs + Array + getNumPlacementArgs();
981   }
982   const_arg_iterator placement_arg_begin() const {
983     return SubExprs + Array;
984   }
985   const_arg_iterator placement_arg_end() const {
986     return SubExprs + Array + getNumPlacementArgs();
987   }
988
989   arg_iterator constructor_arg_begin() {
990     return SubExprs + Array + getNumPlacementArgs();
991   }
992   arg_iterator constructor_arg_end() {
993     return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
994   }
995   const_arg_iterator constructor_arg_begin() const {
996     return SubExprs + Array + getNumPlacementArgs();
997   }
998   const_arg_iterator constructor_arg_end() const {
999     return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1000   }
1001   
1002   typedef Stmt **raw_arg_iterator;
1003   raw_arg_iterator raw_arg_begin() { return SubExprs; }
1004   raw_arg_iterator raw_arg_end() {
1005     return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1006   }
1007   const_arg_iterator raw_arg_begin() const { return SubExprs; }
1008   const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
1009
1010   
1011   SourceLocation getStartLoc() const { return StartLoc; }
1012   void setStartLoc(SourceLocation L) { StartLoc = L; }
1013   SourceLocation getEndLoc() const { return EndLoc; }
1014   void setEndLoc(SourceLocation L) { EndLoc = L; }
1015   
1016   virtual SourceRange getSourceRange() const {
1017     return SourceRange(StartLoc, EndLoc);
1018   }
1019
1020   static bool classof(const Stmt *T) {
1021     return T->getStmtClass() == CXXNewExprClass;
1022   }
1023   static bool classof(const CXXNewExpr *) { return true; }
1024
1025   // Iterators
1026   virtual child_iterator child_begin();
1027   virtual child_iterator child_end();
1028 };
1029
1030 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1031 /// calls, e.g. "delete[] pArray".
1032 class CXXDeleteExpr : public Expr {
1033   // Is this a forced global delete, i.e. "::delete"?
1034   bool GlobalDelete : 1;
1035   // Is this the array form of delete, i.e. "delete[]"?
1036   bool ArrayForm : 1;
1037   // Points to the operator delete overload that is used. Could be a member.
1038   FunctionDecl *OperatorDelete;
1039   // The pointer expression to be deleted.
1040   Stmt *Argument;
1041   // Location of the expression.
1042   SourceLocation Loc;
1043 public:
1044   CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1045                 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1046     : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete),
1047       ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg),
1048       Loc(loc) { }
1049   explicit CXXDeleteExpr(EmptyShell Shell)
1050     : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1051
1052   bool isGlobalDelete() const { return GlobalDelete; }
1053   bool isArrayForm() const { return ArrayForm; }
1054   
1055   void setGlobalDelete(bool V) { GlobalDelete = V; }
1056   void setArrayForm(bool V) { ArrayForm = V; }
1057
1058   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1059   void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1060
1061   Expr *getArgument() { return cast<Expr>(Argument); }
1062   const Expr *getArgument() const { return cast<Expr>(Argument); }
1063   void setArgument(Expr *E) { Argument = E; }
1064
1065   virtual SourceRange getSourceRange() const {
1066     return SourceRange(Loc, Argument->getLocEnd());
1067   }
1068   void setStartLoc(SourceLocation L) { Loc = L; } 
1069
1070   static bool classof(const Stmt *T) {
1071     return T->getStmtClass() == CXXDeleteExprClass;
1072   }
1073   static bool classof(const CXXDeleteExpr *) { return true; }
1074
1075   // Iterators
1076   virtual child_iterator child_begin();
1077   virtual child_iterator child_end();
1078 };
1079
1080 /// \brief Structure used to store the type being destroyed by a 
1081 /// pseudo-destructor expression.
1082 class PseudoDestructorTypeStorage {
1083   /// \brief Either the type source information or the name of the type, if 
1084   /// it couldn't be resolved due to type-dependence.
1085   llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1086   
1087   /// \brief The starting source location of the pseudo-destructor type.
1088   SourceLocation Location;
1089   
1090 public:
1091   PseudoDestructorTypeStorage() { }
1092   
1093   PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1094     : Type(II), Location(Loc) { }
1095   
1096   PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1097   
1098   TypeSourceInfo *getTypeSourceInfo() const { 
1099     return Type.dyn_cast<TypeSourceInfo *>(); 
1100   }
1101   
1102   IdentifierInfo *getIdentifier() const {
1103     return Type.dyn_cast<IdentifierInfo *>();
1104   }
1105   
1106   SourceLocation getLocation() const { return Location; }
1107 };
1108   
1109 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1110 ///
1111 /// A pseudo-destructor is an expression that looks like a member access to a
1112 /// destructor of a scalar type, except that scalar types don't have 
1113 /// destructors. For example:
1114 ///
1115 /// \code
1116 /// typedef int T;
1117 /// void f(int *p) {
1118 ///   p->T::~T();
1119 /// }
1120 /// \endcode
1121 ///
1122 /// Pseudo-destructors typically occur when instantiating templates such as:
1123 /// 
1124 /// \code
1125 /// template<typename T>
1126 /// void destroy(T* ptr) {
1127 ///   ptr->T::~T();
1128 /// }
1129 /// \endcode
1130 ///
1131 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1132 /// beyond evaluating the base expression.
1133 class CXXPseudoDestructorExpr : public Expr {
1134   /// \brief The base expression (that is being destroyed).
1135   Stmt *Base;
1136
1137   /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1138   /// period ('.').
1139   bool IsArrow : 1;
1140
1141   /// \brief The location of the '.' or '->' operator.
1142   SourceLocation OperatorLoc;
1143
1144   /// \brief The nested-name-specifier that follows the operator, if present.
1145   NestedNameSpecifier *Qualifier;
1146
1147   /// \brief The source range that covers the nested-name-specifier, if
1148   /// present.
1149   SourceRange QualifierRange;
1150
1151   /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1152   /// expression.
1153   TypeSourceInfo *ScopeType;
1154   
1155   /// \brief The location of the '::' in a qualified pseudo-destructor 
1156   /// expression.
1157   SourceLocation ColonColonLoc;
1158   
1159   /// \brief The location of the '~'.
1160   SourceLocation TildeLoc;
1161   
1162   /// \brief The type being destroyed, or its name if we were unable to 
1163   /// resolve the name.
1164   PseudoDestructorTypeStorage DestroyedType;
1165
1166 public:
1167   CXXPseudoDestructorExpr(ASTContext &Context,
1168                           Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1169                           NestedNameSpecifier *Qualifier,
1170                           SourceRange QualifierRange,
1171                           TypeSourceInfo *ScopeType,
1172                           SourceLocation ColonColonLoc,
1173                           SourceLocation TildeLoc,
1174                           PseudoDestructorTypeStorage DestroyedType)
1175     : Expr(CXXPseudoDestructorExprClass,
1176            Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
1177                                                           false, 0, false, 
1178                                                           false, 0, 0,
1179                                                       FunctionType::ExtInfo())),
1180            /*isTypeDependent=*/(Base->isTypeDependent() ||
1181             (DestroyedType.getTypeSourceInfo() &&
1182               DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
1183            /*isValueDependent=*/Base->isValueDependent()),
1184       Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
1185       OperatorLoc(OperatorLoc), Qualifier(Qualifier),
1186       QualifierRange(QualifierRange), 
1187       ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
1188       DestroyedType(DestroyedType) { }
1189
1190   explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1191     : Expr(CXXPseudoDestructorExprClass, Shell),
1192       Base(0), IsArrow(false), Qualifier(0), ScopeType(0) { }
1193
1194   void setBase(Expr *E) { Base = E; }
1195   Expr *getBase() const { return cast<Expr>(Base); }
1196
1197   /// \brief Determines whether this member expression actually had
1198   /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1199   /// x->Base::foo.
1200   bool hasQualifier() const { return Qualifier != 0; }
1201
1202   /// \brief If the member name was qualified, retrieves the source range of
1203   /// the nested-name-specifier that precedes the member name. Otherwise,
1204   /// returns an empty source range.
1205   SourceRange getQualifierRange() const { return QualifierRange; }
1206   void setQualifierRange(SourceRange R) { QualifierRange = R; }
1207
1208   /// \brief If the member name was qualified, retrieves the
1209   /// nested-name-specifier that precedes the member name. Otherwise, returns
1210   /// NULL.
1211   NestedNameSpecifier *getQualifier() const { return Qualifier; }
1212   void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1213
1214   /// \brief Determine whether this pseudo-destructor expression was written
1215   /// using an '->' (otherwise, it used a '.').
1216   bool isArrow() const { return IsArrow; }
1217   void setArrow(bool A) { IsArrow = A; }
1218
1219   /// \brief Retrieve the location of the '.' or '->' operator.
1220   SourceLocation getOperatorLoc() const { return OperatorLoc; }
1221   void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1222
1223   /// \brief Retrieve the scope type in a qualified pseudo-destructor 
1224   /// expression.
1225   ///
1226   /// Pseudo-destructor expressions can have extra qualification within them
1227   /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1228   /// Here, if the object type of the expression is (or may be) a scalar type,
1229   /// \p T may also be a scalar type and, therefore, cannot be part of a 
1230   /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1231   /// destructor expression.
1232   TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1233   void setScopeTypeInfo(TypeSourceInfo *Info) { ScopeType = Info; }
1234   
1235   /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1236   /// expression.
1237   SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1238   void setColonColonLoc(SourceLocation L) { ColonColonLoc = L; }
1239   
1240   /// \brief Retrieve the location of the '~'.
1241   SourceLocation getTildeLoc() const { return TildeLoc; }
1242   void setTildeLoc(SourceLocation L) { TildeLoc = L; }
1243   
1244   /// \brief Retrieve the source location information for the type
1245   /// being destroyed.
1246   ///
1247   /// This type-source information is available for non-dependent 
1248   /// pseudo-destructor expressions and some dependent pseudo-destructor
1249   /// expressions. Returns NULL if we only have the identifier for a
1250   /// dependent pseudo-destructor expression.
1251   TypeSourceInfo *getDestroyedTypeInfo() const { 
1252     return DestroyedType.getTypeSourceInfo(); 
1253   }
1254   
1255   /// \brief In a dependent pseudo-destructor expression for which we do not
1256   /// have full type information on the destroyed type, provides the name
1257   /// of the destroyed type.
1258   IdentifierInfo *getDestroyedTypeIdentifier() const {
1259     return DestroyedType.getIdentifier();
1260   }
1261   
1262   /// \brief Retrieve the type being destroyed.
1263   QualType getDestroyedType() const;
1264   
1265   /// \brief Retrieve the starting location of the type being destroyed.
1266   SourceLocation getDestroyedTypeLoc() const { 
1267     return DestroyedType.getLocation(); 
1268   }
1269
1270   /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1271   /// expression.
1272   void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1273     DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1274   }
1275
1276   /// \brief Set the destroyed type.
1277   void setDestroyedType(TypeSourceInfo *Info) {
1278     DestroyedType = PseudoDestructorTypeStorage(Info);
1279   }
1280
1281   virtual SourceRange getSourceRange() const;
1282
1283   static bool classof(const Stmt *T) {
1284     return T->getStmtClass() == CXXPseudoDestructorExprClass;
1285   }
1286   static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1287
1288   // Iterators
1289   virtual child_iterator child_begin();
1290   virtual child_iterator child_end();
1291 };
1292
1293 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1294 /// implementation of TR1/C++0x type trait templates.
1295 /// Example:
1296 /// __is_pod(int) == true
1297 /// __is_enum(std::string) == false
1298 class UnaryTypeTraitExpr : public Expr {
1299   /// UTT - The trait.
1300   UnaryTypeTrait UTT;
1301
1302   /// Loc - The location of the type trait keyword.
1303   SourceLocation Loc;
1304
1305   /// RParen - The location of the closing paren.
1306   SourceLocation RParen;
1307
1308   /// QueriedType - The type we're testing.
1309   QualType QueriedType;
1310
1311 public:
1312   UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried,
1313                      SourceLocation rparen, QualType ty)
1314     : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
1315       UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
1316
1317   explicit UnaryTypeTraitExpr(EmptyShell Empty)
1318     : Expr(UnaryTypeTraitExprClass, Empty), UTT((UnaryTypeTrait)0) { }
1319
1320   virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1321
1322   UnaryTypeTrait getTrait() const { return UTT; }
1323
1324   QualType getQueriedType() const { return QueriedType; }
1325
1326   bool EvaluateTrait(ASTContext&) const;
1327
1328   static bool classof(const Stmt *T) {
1329     return T->getStmtClass() == UnaryTypeTraitExprClass;
1330   }
1331   static bool classof(const UnaryTypeTraitExpr *) { return true; }
1332
1333   // Iterators
1334   virtual child_iterator child_begin();
1335   virtual child_iterator child_end();
1336
1337   friend class ASTStmtReader;
1338 };
1339
1340 /// \brief A reference to an overloaded function set, either an
1341 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1342 class OverloadExpr : public Expr {
1343   /// The results.  These are undesugared, which is to say, they may
1344   /// include UsingShadowDecls.  Access is relative to the naming
1345   /// class.
1346   // FIXME: Allocate this data after the OverloadExpr subclass.
1347   DeclAccessPair *Results;
1348   unsigned NumResults;
1349
1350   /// The common name of these declarations.
1351   DeclarationNameInfo NameInfo;
1352
1353   /// The scope specifier, if any.
1354   NestedNameSpecifier *Qualifier;
1355   
1356   /// The source range of the scope specifier.
1357   SourceRange QualifierRange;
1358
1359 protected:
1360   /// True if the name was a template-id.
1361   bool HasExplicitTemplateArgs;
1362
1363   OverloadExpr(StmtClass K, ASTContext &C, QualType T, bool Dependent,
1364                NestedNameSpecifier *Qualifier, SourceRange QRange,
1365                const DeclarationNameInfo &NameInfo,
1366                bool HasTemplateArgs,
1367                UnresolvedSetIterator Begin, UnresolvedSetIterator End);
1368
1369   OverloadExpr(StmtClass K, EmptyShell Empty)
1370     : Expr(K, Empty), Results(0), NumResults(0),
1371       Qualifier(0), HasExplicitTemplateArgs(false) { }
1372
1373 public:
1374   /// Computes whether an unresolved lookup on the given declarations
1375   /// and optional template arguments is type- and value-dependent.
1376   static bool ComputeDependence(UnresolvedSetIterator Begin,
1377                                 UnresolvedSetIterator End,
1378                                 const TemplateArgumentListInfo *Args);
1379
1380   struct FindResult {
1381     OverloadExpr *Expression;
1382     bool IsAddressOfOperand;
1383     bool HasFormOfMemberPointer;
1384   };
1385
1386   /// Finds the overloaded expression in the given expression of
1387   /// OverloadTy.
1388   ///
1389   /// \return the expression (which must be there) and true if it has
1390   /// the particular form of a member pointer expression
1391   static FindResult find(Expr *E) {
1392     assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1393
1394     FindResult Result;
1395
1396     E = E->IgnoreParens();
1397     if (isa<UnaryOperator>(E)) {
1398       assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
1399       E = cast<UnaryOperator>(E)->getSubExpr();
1400       OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
1401
1402       Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
1403       Result.IsAddressOfOperand = true;
1404       Result.Expression = Ovl;
1405     } else {
1406       Result.HasFormOfMemberPointer = false;
1407       Result.IsAddressOfOperand = false;
1408       Result.Expression = cast<OverloadExpr>(E);
1409     }
1410
1411     return Result;
1412   }
1413
1414   /// Gets the naming class of this lookup, if any.
1415   CXXRecordDecl *getNamingClass() const;
1416
1417   typedef UnresolvedSetImpl::iterator decls_iterator;
1418   decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
1419   decls_iterator decls_end() const { 
1420     return UnresolvedSetIterator(Results + NumResults);
1421   }
1422   
1423   void initializeResults(ASTContext &C,
1424                          UnresolvedSetIterator Begin,UnresolvedSetIterator End);
1425
1426   /// Gets the number of declarations in the unresolved set.
1427   unsigned getNumDecls() const { return NumResults; }
1428
1429   /// Gets the full name info.
1430   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1431   void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; }
1432
1433   /// Gets the name looked up.
1434   DeclarationName getName() const { return NameInfo.getName(); }
1435   void setName(DeclarationName N) { NameInfo.setName(N); }
1436
1437   /// Gets the location of the name.
1438   SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
1439   void setNameLoc(SourceLocation Loc) { NameInfo.setLoc(Loc); }
1440
1441   /// Fetches the nested-name qualifier, if one was given.
1442   NestedNameSpecifier *getQualifier() const { return Qualifier; }
1443   void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1444
1445   /// Fetches the range of the nested-name qualifier.
1446   SourceRange getQualifierRange() const { return QualifierRange; }
1447   void setQualifierRange(SourceRange R) { QualifierRange = R; }
1448
1449   /// \brief Determines whether this expression had an explicit
1450   /// template argument list, e.g. f<int>.
1451   bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1452
1453   ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
1454
1455   const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1456     return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1457   }
1458
1459   /// \brief Retrieves the optional explicit template arguments.
1460   /// This points to the same data as getExplicitTemplateArgs(), but
1461   /// returns null if there are no explicit template arguments.
1462   const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1463     if (!hasExplicitTemplateArgs()) return 0;
1464     return &getExplicitTemplateArgs();
1465   }
1466
1467   static bool classof(const Stmt *T) {
1468     return T->getStmtClass() == UnresolvedLookupExprClass ||
1469            T->getStmtClass() == UnresolvedMemberExprClass;
1470   }
1471   static bool classof(const OverloadExpr *) { return true; }
1472 };
1473
1474 /// \brief A reference to a name which we were able to look up during
1475 /// parsing but could not resolve to a specific declaration.  This
1476 /// arises in several ways:
1477 ///   * we might be waiting for argument-dependent lookup
1478 ///   * the name might resolve to an overloaded function
1479 /// and eventually:
1480 ///   * the lookup might have included a function template
1481 /// These never include UnresolvedUsingValueDecls, which are always
1482 /// class members and therefore appear only in
1483 /// UnresolvedMemberLookupExprs.
1484 class UnresolvedLookupExpr : public OverloadExpr {
1485   /// True if these lookup results should be extended by
1486   /// argument-dependent lookup if this is the operand of a function
1487   /// call.
1488   bool RequiresADL;
1489
1490   /// True if these lookup results are overloaded.  This is pretty
1491   /// trivially rederivable if we urgently need to kill this field.
1492   bool Overloaded;
1493
1494   /// The naming class (C++ [class.access.base]p5) of the lookup, if
1495   /// any.  This can generally be recalculated from the context chain,
1496   /// but that can be fairly expensive for unqualified lookups.  If we
1497   /// want to improve memory use here, this could go in a union
1498   /// against the qualified-lookup bits.
1499   CXXRecordDecl *NamingClass;
1500
1501   UnresolvedLookupExpr(ASTContext &C, QualType T, bool Dependent, 
1502                        CXXRecordDecl *NamingClass,
1503                        NestedNameSpecifier *Qualifier, SourceRange QRange,
1504                        const DeclarationNameInfo &NameInfo,
1505                        bool RequiresADL, bool Overloaded, bool HasTemplateArgs,
1506                        UnresolvedSetIterator Begin, UnresolvedSetIterator End)
1507     : OverloadExpr(UnresolvedLookupExprClass, C, T, Dependent, Qualifier, 
1508                    QRange, NameInfo, HasTemplateArgs, Begin, End),
1509       RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1510   {}
1511
1512   UnresolvedLookupExpr(EmptyShell Empty)
1513     : OverloadExpr(UnresolvedLookupExprClass, Empty),
1514       RequiresADL(false), Overloaded(false), NamingClass(0)
1515   {}
1516
1517 public:
1518   static UnresolvedLookupExpr *Create(ASTContext &C,
1519                                       bool Dependent,
1520                                       CXXRecordDecl *NamingClass,
1521                                       NestedNameSpecifier *Qualifier,
1522                                       SourceRange QualifierRange,
1523                                       const DeclarationNameInfo &NameInfo,
1524                                       bool ADL, bool Overloaded,
1525                                       UnresolvedSetIterator Begin, 
1526                                       UnresolvedSetIterator End) {
1527     return new(C) UnresolvedLookupExpr(C,
1528                                        Dependent ? C.DependentTy : C.OverloadTy,
1529                                        Dependent, NamingClass,
1530                                        Qualifier, QualifierRange, NameInfo,
1531                                        ADL, Overloaded, false,
1532                                        Begin, End);
1533   }
1534
1535   static UnresolvedLookupExpr *Create(ASTContext &C,
1536                                       bool Dependent,
1537                                       CXXRecordDecl *NamingClass,
1538                                       NestedNameSpecifier *Qualifier,
1539                                       SourceRange QualifierRange,
1540                                       const DeclarationNameInfo &NameInfo,
1541                                       bool ADL,
1542                                       const TemplateArgumentListInfo &Args,
1543                                       UnresolvedSetIterator Begin, 
1544                                       UnresolvedSetIterator End);
1545
1546   static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
1547                                            unsigned NumTemplateArgs);
1548
1549   /// True if this declaration should be extended by
1550   /// argument-dependent lookup.
1551   bool requiresADL() const { return RequiresADL; }
1552   void setRequiresADL(bool V) { RequiresADL = V; }
1553
1554   /// True if this lookup is overloaded.
1555   bool isOverloaded() const { return Overloaded; }
1556   void setOverloaded(bool V) { Overloaded = V; }
1557
1558   /// Gets the 'naming class' (in the sense of C++0x
1559   /// [class.access.base]p5) of the lookup.  This is the scope
1560   /// that was looked in to find these results.
1561   CXXRecordDecl *getNamingClass() const { return NamingClass; }
1562   void setNamingClass(CXXRecordDecl *D) { NamingClass = D; }
1563
1564   // Note that, inconsistently with the explicit-template-argument AST
1565   // nodes, users are *forbidden* from calling these methods on objects
1566   // without explicit template arguments.
1567
1568   ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1569     assert(hasExplicitTemplateArgs());
1570     return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1571   }
1572
1573   /// Gets a reference to the explicit template argument list.
1574   const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1575     assert(hasExplicitTemplateArgs());
1576     return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1577   }
1578
1579   /// \brief Retrieves the optional explicit template arguments.
1580   /// This points to the same data as getExplicitTemplateArgs(), but
1581   /// returns null if there are no explicit template arguments.
1582   const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1583     if (!hasExplicitTemplateArgs()) return 0;
1584     return &getExplicitTemplateArgs();
1585   }
1586
1587   /// \brief Copies the template arguments (if present) into the given
1588   /// structure.
1589   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1590     getExplicitTemplateArgs().copyInto(List);
1591   }
1592   
1593   SourceLocation getLAngleLoc() const {
1594     return getExplicitTemplateArgs().LAngleLoc;
1595   }
1596
1597   SourceLocation getRAngleLoc() const {
1598     return getExplicitTemplateArgs().RAngleLoc;
1599   }
1600
1601   TemplateArgumentLoc const *getTemplateArgs() const {
1602     return getExplicitTemplateArgs().getTemplateArgs();
1603   }
1604
1605   unsigned getNumTemplateArgs() const {
1606     return getExplicitTemplateArgs().NumTemplateArgs;
1607   }
1608
1609   virtual SourceRange getSourceRange() const {
1610     SourceRange Range(getNameInfo().getSourceRange());
1611     if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
1612     if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
1613     return Range;
1614   }
1615
1616   virtual StmtIterator child_begin();
1617   virtual StmtIterator child_end();
1618
1619   static bool classof(const Stmt *T) {
1620     return T->getStmtClass() == UnresolvedLookupExprClass;
1621   }
1622   static bool classof(const UnresolvedLookupExpr *) { return true; }
1623 };
1624
1625 /// \brief A qualified reference to a name whose declaration cannot
1626 /// yet be resolved.
1627 ///
1628 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1629 /// it expresses a reference to a declaration such as
1630 /// X<T>::value. The difference, however, is that an
1631 /// DependentScopeDeclRefExpr node is used only within C++ templates when
1632 /// the qualification (e.g., X<T>::) refers to a dependent type. In
1633 /// this case, X<T>::value cannot resolve to a declaration because the
1634 /// declaration will differ from on instantiation of X<T> to the
1635 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1636 /// qualifier (X<T>::) and the name of the entity being referenced
1637 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1638 /// declaration can be found.
1639 class DependentScopeDeclRefExpr : public Expr {
1640   /// The name of the entity we will be referencing.
1641   DeclarationNameInfo NameInfo;
1642
1643   /// QualifierRange - The source range that covers the
1644   /// nested-name-specifier.
1645   SourceRange QualifierRange;
1646
1647   /// \brief The nested-name-specifier that qualifies this unresolved
1648   /// declaration name.
1649   NestedNameSpecifier *Qualifier;
1650
1651   /// \brief Whether the name includes explicit template arguments.
1652   bool HasExplicitTemplateArgs;
1653
1654   DependentScopeDeclRefExpr(QualType T,
1655                             NestedNameSpecifier *Qualifier,
1656                             SourceRange QualifierRange,
1657                             const DeclarationNameInfo &NameInfo,
1658                             bool HasExplicitTemplateArgs)
1659     : Expr(DependentScopeDeclRefExprClass, T, true, true),
1660       NameInfo(NameInfo), QualifierRange(QualifierRange), Qualifier(Qualifier),
1661       HasExplicitTemplateArgs(HasExplicitTemplateArgs)
1662   {}
1663
1664 public:
1665   static DependentScopeDeclRefExpr *Create(ASTContext &C,
1666                                            NestedNameSpecifier *Qualifier,
1667                                            SourceRange QualifierRange,
1668                                            const DeclarationNameInfo &NameInfo,
1669                               const TemplateArgumentListInfo *TemplateArgs = 0);
1670
1671   static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
1672                                                 unsigned NumTemplateArgs);
1673
1674   /// \brief Retrieve the name that this expression refers to.
1675   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1676   void setNameInfo(const DeclarationNameInfo &N) { NameInfo =  N; }
1677
1678   /// \brief Retrieve the name that this expression refers to.
1679   DeclarationName getDeclName() const { return NameInfo.getName(); }
1680   void setDeclName(DeclarationName N) { NameInfo.setName(N); }
1681
1682   /// \brief Retrieve the location of the name within the expression.
1683   SourceLocation getLocation() const { return NameInfo.getLoc(); }
1684   void setLocation(SourceLocation L) { NameInfo.setLoc(L); }
1685
1686   /// \brief Retrieve the source range of the nested-name-specifier.
1687   SourceRange getQualifierRange() const { return QualifierRange; }
1688   void setQualifierRange(SourceRange R) { QualifierRange = R; }
1689
1690   /// \brief Retrieve the nested-name-specifier that qualifies this
1691   /// declaration.
1692   NestedNameSpecifier *getQualifier() const { return Qualifier; }
1693   void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1694
1695   /// Determines whether this lookup had explicit template arguments.
1696   bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1697
1698   // Note that, inconsistently with the explicit-template-argument AST
1699   // nodes, users are *forbidden* from calling these methods on objects
1700   // without explicit template arguments.
1701
1702   ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1703     assert(hasExplicitTemplateArgs());
1704     return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1705   }
1706
1707   /// Gets a reference to the explicit template argument list.
1708   const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1709     assert(hasExplicitTemplateArgs());
1710     return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1711   }
1712
1713   /// \brief Retrieves the optional explicit template arguments.
1714   /// This points to the same data as getExplicitTemplateArgs(), but
1715   /// returns null if there are no explicit template arguments.
1716   const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1717     if (!hasExplicitTemplateArgs()) return 0;
1718     return &getExplicitTemplateArgs();
1719   }
1720
1721   /// \brief Copies the template arguments (if present) into the given
1722   /// structure.
1723   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1724     getExplicitTemplateArgs().copyInto(List);
1725   }
1726   
1727   SourceLocation getLAngleLoc() const {
1728     return getExplicitTemplateArgs().LAngleLoc;
1729   }
1730
1731   SourceLocation getRAngleLoc() const {
1732     return getExplicitTemplateArgs().RAngleLoc;
1733   }
1734
1735   TemplateArgumentLoc const *getTemplateArgs() const {
1736     return getExplicitTemplateArgs().getTemplateArgs();
1737   }
1738
1739   unsigned getNumTemplateArgs() const {
1740     return getExplicitTemplateArgs().NumTemplateArgs;
1741   }
1742
1743   virtual SourceRange getSourceRange() const {
1744     SourceRange Range(QualifierRange.getBegin(), getLocation());
1745     if (hasExplicitTemplateArgs())
1746       Range.setEnd(getRAngleLoc());
1747     return Range;
1748   }
1749
1750   static bool classof(const Stmt *T) {
1751     return T->getStmtClass() == DependentScopeDeclRefExprClass;
1752   }
1753   static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1754
1755   virtual StmtIterator child_begin();
1756   virtual StmtIterator child_end();
1757 };
1758
1759 class CXXExprWithTemporaries : public Expr {
1760   Stmt *SubExpr;
1761
1762   CXXTemporary **Temps;
1763   unsigned NumTemps;
1764
1765   CXXExprWithTemporaries(ASTContext &C, Expr *SubExpr, CXXTemporary **Temps,
1766                          unsigned NumTemps);
1767
1768 public:
1769   CXXExprWithTemporaries(EmptyShell Empty)
1770     : Expr(CXXExprWithTemporariesClass, Empty),
1771       SubExpr(0), Temps(0), NumTemps(0) {}
1772                          
1773   static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
1774                                         CXXTemporary **Temps, 
1775                                         unsigned NumTemps);
1776
1777   unsigned getNumTemporaries() const { return NumTemps; }
1778   void setNumTemporaries(ASTContext &C, unsigned N);
1779     
1780   CXXTemporary *getTemporary(unsigned i) {
1781     assert(i < NumTemps && "Index out of range");
1782     return Temps[i];
1783   }
1784   const CXXTemporary *getTemporary(unsigned i) const {
1785     return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i);
1786   }
1787   void setTemporary(unsigned i, CXXTemporary *T) {
1788     assert(i < NumTemps && "Index out of range");
1789     Temps[i] = T;
1790   }
1791
1792   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1793   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1794   void setSubExpr(Expr *E) { SubExpr = E; }
1795
1796   virtual SourceRange getSourceRange() const { 
1797     return SubExpr->getSourceRange();
1798   }
1799
1800   // Implement isa/cast/dyncast/etc.
1801   static bool classof(const Stmt *T) {
1802     return T->getStmtClass() == CXXExprWithTemporariesClass;
1803   }
1804   static bool classof(const CXXExprWithTemporaries *) { return true; }
1805
1806   // Iterators
1807   virtual child_iterator child_begin();
1808   virtual child_iterator child_end();
1809 };
1810
1811 /// \brief Describes an explicit type conversion that uses functional
1812 /// notion but could not be resolved because one or more arguments are
1813 /// type-dependent.
1814 ///
1815 /// The explicit type conversions expressed by
1816 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1817 /// where \c T is some type and \c a1, a2, ..., aN are values, and
1818 /// either \C T is a dependent type or one or more of the \c a's is
1819 /// type-dependent. For example, this would occur in a template such
1820 /// as:
1821 ///
1822 /// \code
1823 ///   template<typename T, typename A1>
1824 ///   inline T make_a(const A1& a1) {
1825 ///     return T(a1);
1826 ///   }
1827 /// \endcode
1828 ///
1829 /// When the returned expression is instantiated, it may resolve to a
1830 /// constructor call, conversion function call, or some kind of type
1831 /// conversion.
1832 class CXXUnresolvedConstructExpr : public Expr {
1833   /// \brief The starting location of the type
1834   SourceLocation TyBeginLoc;
1835
1836   /// \brief The type being constructed.
1837   QualType Type;
1838
1839   /// \brief The location of the left parentheses ('(').
1840   SourceLocation LParenLoc;
1841
1842   /// \brief The location of the right parentheses (')').
1843   SourceLocation RParenLoc;
1844
1845   /// \brief The number of arguments used to construct the type.
1846   unsigned NumArgs;
1847
1848   CXXUnresolvedConstructExpr(SourceLocation TyBegin,
1849                              QualType T,
1850                              SourceLocation LParenLoc,
1851                              Expr **Args,
1852                              unsigned NumArgs,
1853                              SourceLocation RParenLoc);
1854
1855   CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
1856     : Expr(CXXUnresolvedConstructExprClass, Empty), NumArgs(NumArgs) { }
1857
1858 public:
1859   static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1860                                             SourceLocation TyBegin,
1861                                             QualType T,
1862                                             SourceLocation LParenLoc,
1863                                             Expr **Args,
1864                                             unsigned NumArgs,
1865                                             SourceLocation RParenLoc);
1866
1867   static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
1868                                                  unsigned NumArgs);
1869
1870   /// \brief Retrieve the source location where the type begins.
1871   SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1872   void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1873
1874   /// \brief Retrieve the type that is being constructed, as specified
1875   /// in the source code.
1876   QualType getTypeAsWritten() const { return Type; }
1877   void setTypeAsWritten(QualType T) { Type = T; }
1878
1879   /// \brief Retrieve the location of the left parentheses ('(') that
1880   /// precedes the argument list.
1881   SourceLocation getLParenLoc() const { return LParenLoc; }
1882   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1883
1884   /// \brief Retrieve the location of the right parentheses (')') that
1885   /// follows the argument list.
1886   SourceLocation getRParenLoc() const { return RParenLoc; }
1887   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1888
1889   /// \brief Retrieve the number of arguments.
1890   unsigned arg_size() const { return NumArgs; }
1891
1892   typedef Expr** arg_iterator;
1893   arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1894   arg_iterator arg_end() { return arg_begin() + NumArgs; }
1895
1896   typedef const Expr* const * const_arg_iterator;
1897   const_arg_iterator arg_begin() const {
1898     return reinterpret_cast<const Expr* const *>(this + 1);
1899   }
1900   const_arg_iterator arg_end() const {
1901     return arg_begin() + NumArgs;
1902   }
1903
1904   Expr *getArg(unsigned I) {
1905     assert(I < NumArgs && "Argument index out-of-range");
1906     return *(arg_begin() + I);
1907   }
1908
1909   const Expr *getArg(unsigned I) const {
1910     assert(I < NumArgs && "Argument index out-of-range");
1911     return *(arg_begin() + I);
1912   }
1913
1914   void setArg(unsigned I, Expr *E) {
1915     assert(I < NumArgs && "Argument index out-of-range");
1916     *(arg_begin() + I) = E;
1917   }
1918
1919   virtual SourceRange getSourceRange() const {
1920     return SourceRange(TyBeginLoc, RParenLoc);
1921   }
1922   static bool classof(const Stmt *T) {
1923     return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1924   }
1925   static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
1926
1927   // Iterators
1928   virtual child_iterator child_begin();
1929   virtual child_iterator child_end();
1930 };
1931
1932 /// \brief Represents a C++ member access expression where the actual
1933 /// member referenced could not be resolved because the base
1934 /// expression or the member name was dependent.
1935 ///
1936 /// Like UnresolvedMemberExprs, these can be either implicit or
1937 /// explicit accesses.  It is only possible to get one of these with
1938 /// an implicit access if a qualifier is provided.
1939 class CXXDependentScopeMemberExpr : public Expr {
1940   /// \brief The expression for the base pointer or class reference,
1941   /// e.g., the \c x in x.f.  Can be null in implicit accesses.
1942   Stmt *Base;
1943
1944   /// \brief The type of the base expression.  Never null, even for
1945   /// implicit accesses.
1946   QualType BaseType;
1947
1948   /// \brief Whether this member expression used the '->' operator or
1949   /// the '.' operator.
1950   bool IsArrow : 1;
1951
1952   /// \brief Whether this member expression has explicitly-specified template
1953   /// arguments.
1954   bool HasExplicitTemplateArgs : 1;
1955
1956   /// \brief The location of the '->' or '.' operator.
1957   SourceLocation OperatorLoc;
1958
1959   /// \brief The nested-name-specifier that precedes the member name, if any.
1960   NestedNameSpecifier *Qualifier;
1961
1962   /// \brief The source range covering the nested name specifier.
1963   SourceRange QualifierRange;
1964
1965   /// \brief In a qualified member access expression such as t->Base::f, this
1966   /// member stores the resolves of name lookup in the context of the member
1967   /// access expression, to be used at instantiation time.
1968   ///
1969   /// FIXME: This member, along with the Qualifier and QualifierRange, could
1970   /// be stuck into a structure that is optionally allocated at the end of
1971   /// the CXXDependentScopeMemberExpr, to save space in the common case.
1972   NamedDecl *FirstQualifierFoundInScope;
1973
1974   /// \brief The member to which this member expression refers, which
1975   /// can be name, overloaded operator, or destructor.
1976   /// FIXME: could also be a template-id
1977   DeclarationNameInfo MemberNameInfo;
1978
1979   CXXDependentScopeMemberExpr(ASTContext &C,
1980                           Expr *Base, QualType BaseType, bool IsArrow,
1981                           SourceLocation OperatorLoc,
1982                           NestedNameSpecifier *Qualifier,
1983                           SourceRange QualifierRange,
1984                           NamedDecl *FirstQualifierFoundInScope,
1985                           DeclarationNameInfo MemberNameInfo,
1986                           const TemplateArgumentListInfo *TemplateArgs);
1987
1988 public:
1989   CXXDependentScopeMemberExpr(ASTContext &C,
1990                           Expr *Base, QualType BaseType,
1991                           bool IsArrow,
1992                           SourceLocation OperatorLoc,
1993                           NestedNameSpecifier *Qualifier,
1994                           SourceRange QualifierRange,
1995                           NamedDecl *FirstQualifierFoundInScope,
1996                           DeclarationNameInfo MemberNameInfo)
1997   : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
1998     Base(Base), BaseType(BaseType), IsArrow(IsArrow),
1999     HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
2000     Qualifier(Qualifier), QualifierRange(QualifierRange),
2001     FirstQualifierFoundInScope(FirstQualifierFoundInScope),
2002     MemberNameInfo(MemberNameInfo) { }
2003
2004   static CXXDependentScopeMemberExpr *
2005   Create(ASTContext &C,
2006          Expr *Base, QualType BaseType, bool IsArrow,
2007          SourceLocation OperatorLoc,
2008          NestedNameSpecifier *Qualifier,
2009          SourceRange QualifierRange,
2010          NamedDecl *FirstQualifierFoundInScope,
2011          DeclarationNameInfo MemberNameInfo,
2012          const TemplateArgumentListInfo *TemplateArgs);
2013
2014   static CXXDependentScopeMemberExpr *
2015   CreateEmpty(ASTContext &C, unsigned NumTemplateArgs);
2016
2017   /// \brief True if this is an implicit access, i.e. one in which the
2018   /// member being accessed was not written in the source.  The source
2019   /// location of the operator is invalid in this case.
2020   bool isImplicitAccess() const { return Base == 0; }
2021
2022   /// \brief Retrieve the base object of this member expressions,
2023   /// e.g., the \c x in \c x.m.
2024   Expr *getBase() const {
2025     assert(!isImplicitAccess());
2026     return cast<Expr>(Base);
2027   }
2028   void setBase(Expr *E) { Base = E; }
2029
2030   QualType getBaseType() const { return BaseType; }
2031   void setBaseType(QualType T) { BaseType = T; }
2032
2033   /// \brief Determine whether this member expression used the '->'
2034   /// operator; otherwise, it used the '.' operator.
2035   bool isArrow() const { return IsArrow; }
2036   void setArrow(bool A) { IsArrow = A; }
2037
2038   /// \brief Retrieve the location of the '->' or '.' operator.
2039   SourceLocation getOperatorLoc() const { return OperatorLoc; }
2040   void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2041
2042   /// \brief Retrieve the nested-name-specifier that qualifies the member
2043   /// name.
2044   NestedNameSpecifier *getQualifier() const { return Qualifier; }
2045   void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
2046
2047   /// \brief Retrieve the source range covering the nested-name-specifier
2048   /// that qualifies the member name.
2049   SourceRange getQualifierRange() const { return QualifierRange; }
2050   void setQualifierRange(SourceRange R) { QualifierRange = R; }
2051
2052   /// \brief Retrieve the first part of the nested-name-specifier that was
2053   /// found in the scope of the member access expression when the member access
2054   /// was initially parsed.
2055   ///
2056   /// This function only returns a useful result when member access expression
2057   /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2058   /// returned by this function describes what was found by unqualified name
2059   /// lookup for the identifier "Base" within the scope of the member access
2060   /// expression itself. At template instantiation time, this information is
2061   /// combined with the results of name lookup into the type of the object
2062   /// expression itself (the class type of x).
2063   NamedDecl *getFirstQualifierFoundInScope() const {
2064     return FirstQualifierFoundInScope;
2065   }
2066   void setFirstQualifierFoundInScope(NamedDecl *D) {
2067     FirstQualifierFoundInScope = D;
2068   }
2069
2070   /// \brief Retrieve the name of the member that this expression
2071   /// refers to.
2072   const DeclarationNameInfo &getMemberNameInfo() const {
2073     return MemberNameInfo;
2074   }
2075   void setMemberNameInfo(const DeclarationNameInfo &N) { MemberNameInfo = N; }
2076
2077   /// \brief Retrieve the name of the member that this expression
2078   /// refers to.
2079   DeclarationName getMember() const { return MemberNameInfo.getName(); }
2080   void setMember(DeclarationName N) { MemberNameInfo.setName(N); }
2081
2082   // \brief Retrieve the location of the name of the member that this
2083   // expression refers to.
2084   SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
2085   void setMemberLoc(SourceLocation L) { MemberNameInfo.setLoc(L); }
2086
2087   /// \brief Determines whether this member expression actually had a C++
2088   /// template argument list explicitly specified, e.g., x.f<int>.
2089   bool hasExplicitTemplateArgs() const {
2090     return HasExplicitTemplateArgs;
2091   }
2092
2093   /// \brief Retrieve the explicit template argument list that followed the
2094   /// member template name, if any.
2095   ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2096     assert(HasExplicitTemplateArgs);
2097     return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2098   }
2099
2100   /// \brief Retrieve the explicit template argument list that followed the
2101   /// member template name, if any.
2102   const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2103     return const_cast<CXXDependentScopeMemberExpr *>(this)
2104              ->getExplicitTemplateArgs();
2105   }
2106
2107   /// \brief Retrieves the optional explicit template arguments.
2108   /// This points to the same data as getExplicitTemplateArgs(), but
2109   /// returns null if there are no explicit template arguments.
2110   const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2111     if (!hasExplicitTemplateArgs()) return 0;
2112     return &getExplicitTemplateArgs();
2113   }
2114
2115   /// \brief Copies the template arguments (if present) into the given
2116   /// structure.
2117   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2118     getExplicitTemplateArgs().copyInto(List);
2119   }
2120
2121   /// \brief Initializes the template arguments using the given structure.
2122   void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2123     getExplicitTemplateArgs().initializeFrom(List);
2124   }
2125
2126   /// \brief Retrieve the location of the left angle bracket following the
2127   /// member name ('<'), if any.
2128   SourceLocation getLAngleLoc() const {
2129     return getExplicitTemplateArgs().LAngleLoc;
2130   }
2131
2132   /// \brief Retrieve the template arguments provided as part of this
2133   /// template-id.
2134   const TemplateArgumentLoc *getTemplateArgs() const {
2135     return getExplicitTemplateArgs().getTemplateArgs();
2136   }
2137
2138   /// \brief Retrieve the number of template arguments provided as part of this
2139   /// template-id.
2140   unsigned getNumTemplateArgs() const {
2141     return getExplicitTemplateArgs().NumTemplateArgs;
2142   }
2143
2144   /// \brief Retrieve the location of the right angle bracket following the
2145   /// template arguments ('>').
2146   SourceLocation getRAngleLoc() const {
2147     return getExplicitTemplateArgs().RAngleLoc;
2148   }
2149
2150   virtual SourceRange getSourceRange() const {
2151     SourceRange Range;
2152     if (!isImplicitAccess())
2153       Range.setBegin(Base->getSourceRange().getBegin());
2154     else if (getQualifier())
2155       Range.setBegin(getQualifierRange().getBegin());
2156     else
2157       Range.setBegin(MemberNameInfo.getBeginLoc());
2158
2159     if (hasExplicitTemplateArgs())
2160       Range.setEnd(getRAngleLoc());
2161     else
2162       Range.setEnd(MemberNameInfo.getEndLoc());
2163     return Range;
2164   }
2165
2166   static bool classof(const Stmt *T) {
2167     return T->getStmtClass() == CXXDependentScopeMemberExprClass;
2168   }
2169   static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
2170
2171   // Iterators
2172   virtual child_iterator child_begin();
2173   virtual child_iterator child_end();
2174 };
2175
2176 /// \brief Represents a C++ member access expression for which lookup
2177 /// produced a set of overloaded functions.
2178 ///
2179 /// The member access may be explicit or implicit:
2180 ///    struct A {
2181 ///      int a, b;
2182 ///      int explicitAccess() { return this->a + this->A::b; }
2183 ///      int implicitAccess() { return a + A::b; }
2184 ///    };
2185 ///
2186 /// In the final AST, an explicit access always becomes a MemberExpr.
2187 /// An implicit access may become either a MemberExpr or a
2188 /// DeclRefExpr, depending on whether the member is static.
2189 class UnresolvedMemberExpr : public OverloadExpr {
2190   /// \brief Whether this member expression used the '->' operator or
2191   /// the '.' operator.
2192   bool IsArrow : 1;
2193
2194   /// \brief Whether the lookup results contain an unresolved using
2195   /// declaration.
2196   bool HasUnresolvedUsing : 1;
2197
2198   /// \brief The expression for the base pointer or class reference,
2199   /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
2200   /// member expression
2201   Stmt *Base;
2202
2203   /// \brief The type of the base expression;  never null.
2204   QualType BaseType;
2205
2206   /// \brief The location of the '->' or '.' operator.
2207   SourceLocation OperatorLoc;
2208
2209   UnresolvedMemberExpr(ASTContext &C, QualType T, bool Dependent,
2210                        bool HasUnresolvedUsing,
2211                        Expr *Base, QualType BaseType, bool IsArrow,
2212                        SourceLocation OperatorLoc,
2213                        NestedNameSpecifier *Qualifier,
2214                        SourceRange QualifierRange,
2215                        const DeclarationNameInfo &MemberNameInfo,
2216                        const TemplateArgumentListInfo *TemplateArgs,
2217                        UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2218   
2219   UnresolvedMemberExpr(EmptyShell Empty)
2220     : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2221       HasUnresolvedUsing(false), Base(0) { }
2222
2223 public:
2224   static UnresolvedMemberExpr *
2225   Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing,
2226          Expr *Base, QualType BaseType, bool IsArrow,
2227          SourceLocation OperatorLoc,
2228          NestedNameSpecifier *Qualifier,
2229          SourceRange QualifierRange,
2230          const DeclarationNameInfo &MemberNameInfo,
2231          const TemplateArgumentListInfo *TemplateArgs,
2232          UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2233
2234   static UnresolvedMemberExpr *
2235   CreateEmpty(ASTContext &C, unsigned NumTemplateArgs);
2236
2237   /// \brief True if this is an implicit access, i.e. one in which the
2238   /// member being accessed was not written in the source.  The source
2239   /// location of the operator is invalid in this case.
2240   bool isImplicitAccess() const { return Base == 0; }
2241
2242   /// \brief Retrieve the base object of this member expressions,
2243   /// e.g., the \c x in \c x.m.
2244   Expr *getBase() {
2245     assert(!isImplicitAccess());
2246     return cast<Expr>(Base);
2247   }
2248   const Expr *getBase() const {
2249     assert(!isImplicitAccess());
2250     return cast<Expr>(Base);
2251   }
2252   void setBase(Expr *E) { Base = E; }
2253
2254   QualType getBaseType() const { return BaseType; }
2255   void setBaseType(QualType T) { BaseType = T; }
2256
2257   /// \brief Determine whether the lookup results contain an unresolved using
2258   /// declaration.
2259   bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2260   void setHasUnresolvedUsing(bool V) { HasUnresolvedUsing = V; }
2261
2262   /// \brief Determine whether this member expression used the '->'
2263   /// operator; otherwise, it used the '.' operator.
2264   bool isArrow() const { return IsArrow; }
2265   void setArrow(bool A) { IsArrow = A; }
2266
2267   /// \brief Retrieve the location of the '->' or '.' operator.
2268   SourceLocation getOperatorLoc() const { return OperatorLoc; }
2269   void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2270
2271   /// \brief Retrieves the naming class of this lookup.
2272   CXXRecordDecl *getNamingClass() const;
2273
2274   /// \brief Retrieve the full name info for the member that this expression
2275   /// refers to.
2276   const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
2277   void setMemberNameInfo(const DeclarationNameInfo &N) { setNameInfo(N); }
2278
2279   /// \brief Retrieve the name of the member that this expression
2280   /// refers to.
2281   DeclarationName getMemberName() const { return getName(); }
2282   void setMemberName(DeclarationName N) { setName(N); }
2283
2284   // \brief Retrieve the location of the name of the member that this
2285   // expression refers to.
2286   SourceLocation getMemberLoc() const { return getNameLoc(); }
2287   void setMemberLoc(SourceLocation L) { setNameLoc(L); }
2288
2289   /// \brief Retrieve the explicit template argument list that followed the
2290   /// member template name.
2291   ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2292     assert(hasExplicitTemplateArgs());
2293     return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2294   }
2295
2296   /// \brief Retrieve the explicit template argument list that followed the
2297   /// member template name, if any.
2298   const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2299     assert(hasExplicitTemplateArgs());
2300     return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2301   }
2302
2303   /// \brief Retrieves the optional explicit template arguments.
2304   /// This points to the same data as getExplicitTemplateArgs(), but
2305   /// returns null if there are no explicit template arguments.
2306   const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2307     if (!hasExplicitTemplateArgs()) return 0;
2308     return &getExplicitTemplateArgs();
2309   }
2310
2311   /// \brief Copies the template arguments into the given structure.
2312   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2313     getExplicitTemplateArgs().copyInto(List);
2314   }
2315
2316   /// \brief Retrieve the location of the left angle bracket following
2317   /// the member name ('<').
2318   SourceLocation getLAngleLoc() const {
2319     return getExplicitTemplateArgs().LAngleLoc;
2320   }
2321
2322   /// \brief Retrieve the template arguments provided as part of this
2323   /// template-id.
2324   const TemplateArgumentLoc *getTemplateArgs() const {
2325     return getExplicitTemplateArgs().getTemplateArgs();
2326   }
2327
2328   /// \brief Retrieve the number of template arguments provided as
2329   /// part of this template-id.
2330   unsigned getNumTemplateArgs() const {
2331     return getExplicitTemplateArgs().NumTemplateArgs;
2332   }
2333
2334   /// \brief Retrieve the location of the right angle bracket
2335   /// following the template arguments ('>').
2336   SourceLocation getRAngleLoc() const {
2337     return getExplicitTemplateArgs().RAngleLoc;
2338   }
2339
2340   virtual SourceRange getSourceRange() const {
2341     SourceRange Range = getMemberNameInfo().getSourceRange();
2342     if (!isImplicitAccess())
2343       Range.setBegin(Base->getSourceRange().getBegin());
2344     else if (getQualifier())
2345       Range.setBegin(getQualifierRange().getBegin());
2346
2347     if (hasExplicitTemplateArgs())
2348       Range.setEnd(getRAngleLoc());
2349     return Range;
2350   }
2351
2352   static bool classof(const Stmt *T) {
2353     return T->getStmtClass() == UnresolvedMemberExprClass;
2354   }
2355   static bool classof(const UnresolvedMemberExpr *) { return true; }
2356
2357   // Iterators
2358   virtual child_iterator child_begin();
2359   virtual child_iterator child_end();
2360 };
2361
2362 inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2363   if (isa<UnresolvedLookupExpr>(this))
2364     return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2365   else
2366     return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2367 }
2368
2369 }  // end namespace clang
2370
2371 #endif