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