ExprCXX.h revision a71d819bb8f50c28938db0f2867d3fb6e2ce5910
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/Decl.h"
20
21namespace clang {
22
23  class CXXConstructorDecl;
24  class CXXDestructorDecl;
25  class CXXMethodDecl;
26  class CXXTemporary;
27
28//===--------------------------------------------------------------------===//
29// C++ Expressions.
30//===--------------------------------------------------------------------===//
31
32/// \brief A call to an overloaded operator written using operator
33/// syntax.
34///
35/// Represents a call to an overloaded operator written using operator
36/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
37/// normal call, this AST node provides better information about the
38/// syntactic representation of the call.
39///
40/// In a C++ template, this expression node kind will be used whenever
41/// any of the arguments are type-dependent. In this case, the
42/// function itself will be a (possibly empty) set of functions and
43/// function templates that were found by name lookup at template
44/// definition time.
45class CXXOperatorCallExpr : public CallExpr {
46  /// \brief The overloaded operator.
47  OverloadedOperatorKind Operator;
48
49public:
50  CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
51                      Expr **args, unsigned numargs, QualType t,
52                      SourceLocation operatorloc)
53    : CallExpr(C, CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc),
54      Operator(Op) {}
55  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
56    CallExpr(C, CXXOperatorCallExprClass, Empty) { }
57
58
59  /// getOperator - Returns the kind of overloaded operator that this
60  /// expression refers to.
61  OverloadedOperatorKind getOperator() const { return Operator; }
62  void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
63
64  /// getOperatorLoc - Returns the location of the operator symbol in
65  /// the expression. When @c getOperator()==OO_Call, this is the
66  /// location of the right parentheses; when @c
67  /// getOperator()==OO_Subscript, this is the location of the right
68  /// bracket.
69  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
70
71  virtual SourceRange getSourceRange() const;
72
73  static bool classof(const Stmt *T) {
74    return T->getStmtClass() == CXXOperatorCallExprClass;
75  }
76  static bool classof(const CXXOperatorCallExpr *) { return true; }
77};
78
79/// CXXMemberCallExpr - Represents a call to a member function that
80/// may be written either with member call syntax (e.g., "obj.func()"
81/// or "objptr->func()") or with normal function-call syntax
82/// ("func()") within a member function that ends up calling a member
83/// function. The callee in either case is a MemberExpr that contains
84/// both the object argument and the member function, while the
85/// arguments are the arguments within the parentheses (not including
86/// the object argument).
87class CXXMemberCallExpr : public CallExpr {
88public:
89  CXXMemberCallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs,
90                    QualType t, SourceLocation rparenloc)
91    : CallExpr(C, CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) {}
92
93  /// getImplicitObjectArgument - Retrieves the implicit object
94  /// argument for the member call. For example, in "x.f(5)", this
95  /// operation would return "x".
96  Expr *getImplicitObjectArgument();
97
98  static bool classof(const Stmt *T) {
99    return T->getStmtClass() == CXXMemberCallExprClass;
100  }
101  static bool classof(const CXXMemberCallExpr *) { return true; }
102};
103
104/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
105/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
106/// const_cast.
107///
108/// This abstract class is inherited by all of the classes
109/// representing "named" casts, e.g., CXXStaticCastExpr,
110/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
111class CXXNamedCastExpr : public ExplicitCastExpr {
112private:
113  SourceLocation Loc; // the location of the casting op
114
115protected:
116  CXXNamedCastExpr(StmtClass SC, QualType ty, const CastInfo &info, Expr *op,
117                   QualType writtenTy, SourceLocation l)
118    : ExplicitCastExpr(SC, ty, info, op, writtenTy), Loc(l) {}
119
120public:
121  const char *getCastName() const;
122
123  /// \brief Retrieve the location of the cast operator keyword, e.g.,
124  /// "static_cast".
125  SourceLocation getOperatorLoc() const { return Loc; }
126  void setOperatorLoc(SourceLocation L) { Loc = L; }
127
128  virtual SourceRange getSourceRange() const {
129    return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
130  }
131  static bool classof(const Stmt *T) {
132    switch (T->getStmtClass()) {
133    case CXXNamedCastExprClass:
134    case CXXStaticCastExprClass:
135    case CXXDynamicCastExprClass:
136    case CXXReinterpretCastExprClass:
137    case CXXConstCastExprClass:
138      return true;
139    default:
140      return false;
141    }
142  }
143  static bool classof(const CXXNamedCastExpr *) { return true; }
144};
145
146/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
147///
148/// This expression node represents a C++ static cast, e.g.,
149/// @c static_cast<int>(1.0).
150class CXXStaticCastExpr : public CXXNamedCastExpr {
151public:
152  CXXStaticCastExpr(QualType ty, const CastInfo &info, Expr *op,
153                    QualType writtenTy, SourceLocation l)
154    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, info, op, writtenTy, l) {}
155
156  static bool classof(const Stmt *T) {
157    return T->getStmtClass() == CXXStaticCastExprClass;
158  }
159  static bool classof(const CXXStaticCastExpr *) { return true; }
160};
161
162/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
163/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
164/// determine how to perform the type cast.
165///
166/// This expression node represents a dynamic cast, e.g.,
167/// @c dynamic_cast<Derived*>(BasePtr).
168class CXXDynamicCastExpr : public CXXNamedCastExpr {
169public:
170  CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op, QualType writtenTy,
171                     SourceLocation l)
172    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, writtenTy, l) {}
173
174  static bool classof(const Stmt *T) {
175    return T->getStmtClass() == CXXDynamicCastExprClass;
176  }
177  static bool classof(const CXXDynamicCastExpr *) { return true; }
178};
179
180/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
181/// [expr.reinterpret.cast]), which provides a differently-typed view
182/// of a value but performs no actual work at run time.
183///
184/// This expression node represents a reinterpret cast, e.g.,
185/// @c reinterpret_cast<int>(VoidPtr).
186class CXXReinterpretCastExpr : public CXXNamedCastExpr {
187public:
188  CXXReinterpretCastExpr(QualType ty, Expr *op, QualType writtenTy,
189                         SourceLocation l)
190    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, CK_BitCast, op,
191                       writtenTy, l) {}
192
193  static bool classof(const Stmt *T) {
194    return T->getStmtClass() == CXXReinterpretCastExprClass;
195  }
196  static bool classof(const CXXReinterpretCastExpr *) { return true; }
197};
198
199/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
200/// which can remove type qualifiers but does not change the underlying value.
201///
202/// This expression node represents a const cast, e.g.,
203/// @c const_cast<char*>(PtrToConstChar).
204class CXXConstCastExpr : public CXXNamedCastExpr {
205public:
206  CXXConstCastExpr(QualType ty, Expr *op, QualType writtenTy,
207                   SourceLocation l)
208    : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op, writtenTy, l) {}
209
210  static bool classof(const Stmt *T) {
211    return T->getStmtClass() == CXXConstCastExprClass;
212  }
213  static bool classof(const CXXConstCastExpr *) { return true; }
214};
215
216/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
217///
218class CXXBoolLiteralExpr : public Expr {
219  bool Value;
220  SourceLocation Loc;
221public:
222  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
223    Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {}
224
225  bool getValue() const { return Value; }
226
227  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
228
229  static bool classof(const Stmt *T) {
230    return T->getStmtClass() == CXXBoolLiteralExprClass;
231  }
232  static bool classof(const CXXBoolLiteralExpr *) { return true; }
233
234  // Iterators
235  virtual child_iterator child_begin();
236  virtual child_iterator child_end();
237};
238
239/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
240class CXXNullPtrLiteralExpr : public Expr {
241  SourceLocation Loc;
242public:
243  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
244    Expr(CXXNullPtrLiteralExprClass, Ty), Loc(l) {}
245
246  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
247
248  static bool classof(const Stmt *T) {
249    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
250  }
251  static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
252
253  virtual child_iterator child_begin();
254  virtual child_iterator child_end();
255};
256
257/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
258/// the type_info that corresponds to the supplied type, or the (possibly
259/// dynamic) type of the supplied expression.
260///
261/// This represents code like @c typeid(int) or @c typeid(*objPtr)
262class CXXTypeidExpr : public Expr {
263private:
264  bool isTypeOp : 1;
265  union {
266    void *Ty;
267    Stmt *Ex;
268  } Operand;
269  SourceRange Range;
270
271public:
272  CXXTypeidExpr(bool isTypeOp, void *op, QualType Ty, const SourceRange r) :
273      Expr(CXXTypeidExprClass, Ty,
274        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
275        false,
276        // typeid is value-dependent if the type or expression are dependent
277        (isTypeOp ? QualType::getFromOpaquePtr(op)->isDependentType()
278                  : static_cast<Expr*>(op)->isValueDependent())),
279      isTypeOp(isTypeOp), Range(r) {
280    if (isTypeOp)
281      Operand.Ty = op;
282    else
283      // op was an Expr*, so cast it back to that to be safe
284      Operand.Ex = static_cast<Expr*>(op);
285  }
286
287  bool isTypeOperand() const { return isTypeOp; }
288  QualType getTypeOperand() const {
289    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
290    return QualType::getFromOpaquePtr(Operand.Ty);
291  }
292  Expr* getExprOperand() const {
293    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
294    return static_cast<Expr*>(Operand.Ex);
295  }
296
297  virtual SourceRange getSourceRange() const {
298    return Range;
299  }
300  static bool classof(const Stmt *T) {
301    return T->getStmtClass() == CXXTypeidExprClass;
302  }
303  static bool classof(const CXXTypeidExpr *) { return true; }
304
305  // Iterators
306  virtual child_iterator child_begin();
307  virtual child_iterator child_end();
308};
309
310/// CXXThisExpr - Represents the "this" expression in C++, which is a
311/// pointer to the object on which the current member function is
312/// executing (C++ [expr.prim]p3). Example:
313///
314/// @code
315/// class Foo {
316/// public:
317///   void bar();
318///   void test() { this->bar(); }
319/// };
320/// @endcode
321class CXXThisExpr : public Expr {
322  SourceLocation Loc;
323
324public:
325  CXXThisExpr(SourceLocation L, QualType Type)
326    : Expr(CXXThisExprClass, Type,
327           // 'this' is type-dependent if the class type of the enclosing
328           // member function is dependent (C++ [temp.dep.expr]p2)
329           Type->isDependentType(), Type->isDependentType()),
330      Loc(L) { }
331
332  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
333
334  static bool classof(const Stmt *T) {
335    return T->getStmtClass() == CXXThisExprClass;
336  }
337  static bool classof(const CXXThisExpr *) { return true; }
338
339  // Iterators
340  virtual child_iterator child_begin();
341  virtual child_iterator child_end();
342};
343
344///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
345///  'throw' and 'throw' assignment-expression.  When
346///  assignment-expression isn't present, Op will be null.
347///
348class CXXThrowExpr : public Expr {
349  Stmt *Op;
350  SourceLocation ThrowLoc;
351public:
352  // Ty is the void type which is used as the result type of the
353  // exepression.  The l is the location of the throw keyword.  expr
354  // can by null, if the optional expression to throw isn't present.
355  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
356    Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {}
357  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
358  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
359  void setSubExpr(Expr *E) { Op = E; }
360
361  SourceLocation getThrowLoc() const { return ThrowLoc; }
362  void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
363
364  virtual SourceRange getSourceRange() const {
365    if (getSubExpr() == 0)
366      return SourceRange(ThrowLoc, ThrowLoc);
367    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
368  }
369
370  static bool classof(const Stmt *T) {
371    return T->getStmtClass() == CXXThrowExprClass;
372  }
373  static bool classof(const CXXThrowExpr *) { return true; }
374
375  // Iterators
376  virtual child_iterator child_begin();
377  virtual child_iterator child_end();
378};
379
380/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
381/// function call argument that was created from the corresponding
382/// parameter's default argument, when the call did not explicitly
383/// supply arguments for all of the parameters.
384class CXXDefaultArgExpr : public Expr {
385  ParmVarDecl *Param;
386
387protected:
388  CXXDefaultArgExpr(StmtClass SC, ParmVarDecl *param)
389    : Expr(SC, param->hasUnparsedDefaultArg() ?
390           param->getType().getNonReferenceType()
391           : param->getDefaultArg()->getType()),
392    Param(param) { }
393
394public:
395  // Param is the parameter whose default argument is used by this
396  // expression.
397  static CXXDefaultArgExpr *Create(ASTContext &C, ParmVarDecl *Param) {
398    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Param);
399  }
400
401  // Retrieve the parameter that the argument was created from.
402  const ParmVarDecl *getParam() const { return Param; }
403  ParmVarDecl *getParam() { return Param; }
404
405  // Retrieve the actual argument to the function call.
406  const Expr *getExpr() const { return Param->getDefaultArg(); }
407  Expr *getExpr() { return Param->getDefaultArg(); }
408
409  virtual SourceRange getSourceRange() const {
410    // Default argument expressions have no representation in the
411    // source, so they have an empty source range.
412    return SourceRange();
413  }
414
415  static bool classof(const Stmt *T) {
416    return T->getStmtClass() == CXXDefaultArgExprClass;
417  }
418  static bool classof(const CXXDefaultArgExpr *) { return true; }
419
420  // Iterators
421  virtual child_iterator child_begin();
422  virtual child_iterator child_end();
423};
424
425/// CXXTemporary - Represents a C++ temporary.
426class CXXTemporary {
427  /// Destructor - The destructor that needs to be called.
428  const CXXDestructorDecl *Destructor;
429
430  CXXTemporary(const CXXDestructorDecl *destructor)
431    : Destructor(destructor) { }
432  ~CXXTemporary() { }
433
434public:
435  static CXXTemporary *Create(ASTContext &C,
436                              const CXXDestructorDecl *Destructor);
437
438  void Destroy(ASTContext &Ctx);
439
440  const CXXDestructorDecl *getDestructor() const { return Destructor; }
441};
442
443/// CXXBindTemporaryExpr - Represents binding an expression to a temporary,
444/// so its destructor can be called later.
445class CXXBindTemporaryExpr : public Expr {
446  CXXTemporary *Temp;
447
448  Stmt *SubExpr;
449
450  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr)
451   : Expr(CXXBindTemporaryExprClass,
452          subexpr->getType()), Temp(temp), SubExpr(subexpr) { }
453  ~CXXBindTemporaryExpr() { }
454
455protected:
456  virtual void DoDestroy(ASTContext &C);
457
458public:
459  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
460                                      Expr* SubExpr);
461
462  CXXTemporary *getTemporary() { return Temp; }
463  const CXXTemporary *getTemporary() const { return Temp; }
464
465  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
466  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
467  void setSubExpr(Expr *E) { SubExpr = E; }
468
469  virtual SourceRange getSourceRange() const { return SourceRange(); }
470
471  // Implement isa/cast/dyncast/etc.
472  static bool classof(const Stmt *T) {
473    return T->getStmtClass() == CXXBindTemporaryExprClass;
474  }
475  static bool classof(const CXXBindTemporaryExpr *) { return true; }
476
477  // Iterators
478  virtual child_iterator child_begin();
479  virtual child_iterator child_end();
480};
481
482/// CXXConstructExpr - Represents a call to a C++ constructor.
483class CXXConstructExpr : public Expr {
484  CXXConstructorDecl *Constructor;
485
486  bool Elidable;
487
488  Stmt **Args;
489  unsigned NumArgs;
490
491protected:
492  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
493                   CXXConstructorDecl *d, bool elidable,
494                   Expr **args, unsigned numargs);
495  ~CXXConstructExpr() { }
496
497  virtual void DoDestroy(ASTContext &C);
498
499public:
500  static CXXConstructExpr *Create(ASTContext &C, QualType T,
501                                  CXXConstructorDecl *D, bool Elidable,
502                                  Expr **Args, unsigned NumArgs);
503
504
505  CXXConstructorDecl* getConstructor() const { return Constructor; }
506
507  /// \brief Whether this construction is elidable.
508  bool isElidable() const { return Elidable; }
509
510  typedef ExprIterator arg_iterator;
511  typedef ConstExprIterator const_arg_iterator;
512
513  arg_iterator arg_begin() { return Args; }
514  arg_iterator arg_end() { return Args + NumArgs; }
515  const_arg_iterator arg_begin() const { return Args; }
516  const_arg_iterator arg_end() const { return Args + NumArgs; }
517
518  unsigned getNumArgs() const { return NumArgs; }
519
520  /// setArg - Set the specified argument.
521  void setArg(unsigned Arg, Expr *ArgExpr) {
522    assert(Arg < NumArgs && "Arg access out of range!");
523    Args[Arg] = ArgExpr;
524  }
525
526  virtual SourceRange getSourceRange() const { return SourceRange(); }
527
528  static bool classof(const Stmt *T) {
529    return T->getStmtClass() == CXXConstructExprClass ||
530      T->getStmtClass() == CXXTemporaryObjectExprClass;
531  }
532  static bool classof(const CXXConstructExpr *) { return true; }
533
534  // Iterators
535  virtual child_iterator child_begin();
536  virtual child_iterator child_end();
537};
538
539/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
540/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
541/// x = int(0.5);
542class CXXFunctionalCastExpr : public ExplicitCastExpr {
543  CXXMethodDecl *TypeConversionMethod;
544  SourceLocation TyBeginLoc;
545  SourceLocation RParenLoc;
546public:
547  CXXFunctionalCastExpr(QualType ty, QualType writtenTy,
548                        SourceLocation tyBeginLoc, CastKind kind,
549                        Expr *castExpr, CXXMethodDecl *typeConversionMethod,
550                        SourceLocation rParenLoc) :
551    ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr, writtenTy),
552    TypeConversionMethod(typeConversionMethod),
553    TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
554
555  CXXMethodDecl *getTypeConversionMethod() const
556  { return TypeConversionMethod; }
557  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
558  SourceLocation getRParenLoc() const { return RParenLoc; }
559
560  virtual SourceRange getSourceRange() const {
561    return SourceRange(TyBeginLoc, RParenLoc);
562  }
563  static bool classof(const Stmt *T) {
564    return T->getStmtClass() == CXXFunctionalCastExprClass;
565  }
566  static bool classof(const CXXFunctionalCastExpr *) { return true; }
567};
568
569/// @brief Represents a C++ functional cast expression that builds a
570/// temporary object.
571///
572/// This expression type represents a C++ "functional" cast
573/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
574/// constructor to build a temporary object. If N == 0 but no
575/// constructor will be called (because the functional cast is
576/// performing a value-initialized an object whose class type has no
577/// user-declared constructors), CXXZeroInitValueExpr will represent
578/// the functional cast. Finally, with N == 1 arguments the functional
579/// cast expression will be represented by CXXFunctionalCastExpr.
580/// Example:
581/// @code
582/// struct X { X(int, float); }
583///
584/// X create_X() {
585///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
586/// };
587/// @endcode
588class CXXTemporaryObjectExpr : public CXXConstructExpr {
589  SourceLocation TyBeginLoc;
590  SourceLocation RParenLoc;
591
592public:
593  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
594                         QualType writtenTy, SourceLocation tyBeginLoc,
595                         Expr **Args,unsigned NumArgs,
596                         SourceLocation rParenLoc);
597
598  ~CXXTemporaryObjectExpr() { }
599
600  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
601  SourceLocation getRParenLoc() const { return RParenLoc; }
602
603  virtual SourceRange getSourceRange() const {
604    return SourceRange(TyBeginLoc, RParenLoc);
605  }
606  static bool classof(const Stmt *T) {
607    return T->getStmtClass() == CXXTemporaryObjectExprClass;
608  }
609  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
610};
611
612/// CXXZeroInitValueExpr - [C++ 5.2.3p2]
613/// Expression "T()" which creates a value-initialized rvalue of type
614/// T, which is either a non-class type or a class type without any
615/// user-defined constructors.
616///
617class CXXZeroInitValueExpr : public Expr {
618  SourceLocation TyBeginLoc;
619  SourceLocation RParenLoc;
620
621public:
622  CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc,
623                       SourceLocation rParenLoc ) :
624    Expr(CXXZeroInitValueExprClass, ty, false, false),
625    TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
626
627  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
628  SourceLocation getRParenLoc() const { return RParenLoc; }
629
630  /// @brief Whether this initialization expression was
631  /// implicitly-generated.
632  bool isImplicit() const {
633    return TyBeginLoc.isInvalid() && RParenLoc.isInvalid();
634  }
635
636  virtual SourceRange getSourceRange() const {
637    return SourceRange(TyBeginLoc, RParenLoc);
638  }
639
640  static bool classof(const Stmt *T) {
641    return T->getStmtClass() == CXXZeroInitValueExprClass;
642  }
643  static bool classof(const CXXZeroInitValueExpr *) { return true; }
644
645  // Iterators
646  virtual child_iterator child_begin();
647  virtual child_iterator child_end();
648};
649
650/// CXXConditionDeclExpr - Condition declaration of a if/switch/while/for
651/// statement, e.g: "if (int x = f()) {...}".
652/// The main difference with DeclRefExpr is that CXXConditionDeclExpr owns the
653/// decl that it references.
654///
655class CXXConditionDeclExpr : public DeclRefExpr {
656public:
657  CXXConditionDeclExpr(SourceLocation startLoc,
658                       SourceLocation eqLoc, VarDecl *var)
659    : DeclRefExpr(CXXConditionDeclExprClass, var,
660                  var->getType().getNonReferenceType(), startLoc,
661                  var->getType()->isDependentType(),
662                  /*FIXME:integral constant?*/
663                    var->getType()->isDependentType()) {}
664
665  SourceLocation getStartLoc() const { return getLocation(); }
666
667  VarDecl *getVarDecl() { return cast<VarDecl>(getDecl()); }
668  const VarDecl *getVarDecl() const { return cast<VarDecl>(getDecl()); }
669
670  virtual SourceRange getSourceRange() const {
671    return SourceRange(getStartLoc(), getVarDecl()->getInit()->getLocEnd());
672  }
673
674  static bool classof(const Stmt *T) {
675    return T->getStmtClass() == CXXConditionDeclExprClass;
676  }
677  static bool classof(const CXXConditionDeclExpr *) { return true; }
678
679  // Iterators
680  virtual child_iterator child_begin();
681  virtual child_iterator child_end();
682};
683
684/// CXXNewExpr - A new expression for memory allocation and constructor calls,
685/// e.g: "new CXXNewExpr(foo)".
686class CXXNewExpr : public Expr {
687  // Was the usage ::new, i.e. is the global new to be used?
688  bool GlobalNew : 1;
689  // Was the form (type-id) used? Otherwise, it was new-type-id.
690  bool ParenTypeId : 1;
691  // Is there an initializer? If not, built-ins are uninitialized, else they're
692  // value-initialized.
693  bool Initializer : 1;
694  // Do we allocate an array? If so, the first SubExpr is the size expression.
695  bool Array : 1;
696  // The number of placement new arguments.
697  unsigned NumPlacementArgs : 14;
698  // The number of constructor arguments. This may be 1 even for non-class
699  // types; use the pseudo copy constructor.
700  unsigned NumConstructorArgs : 14;
701  // Contains an optional array size expression, any number of optional
702  // placement arguments, and any number of optional constructor arguments,
703  // in that order.
704  Stmt **SubExprs;
705  // Points to the allocation function used.
706  FunctionDecl *OperatorNew;
707  // Points to the deallocation function used in case of error. May be null.
708  FunctionDecl *OperatorDelete;
709  // Points to the constructor used. Cannot be null if AllocType is a record;
710  // it would still point at the default constructor (even an implicit one).
711  // Must be null for all other types.
712  CXXConstructorDecl *Constructor;
713
714  SourceLocation StartLoc;
715  SourceLocation EndLoc;
716
717public:
718  CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, Expr **placementArgs,
719             unsigned numPlaceArgs, bool ParenTypeId, Expr *arraySize,
720             CXXConstructorDecl *constructor, bool initializer,
721             Expr **constructorArgs, unsigned numConsArgs,
722             FunctionDecl *operatorDelete, QualType ty,
723             SourceLocation startLoc, SourceLocation endLoc);
724  ~CXXNewExpr() {
725    delete[] SubExprs;
726  }
727
728  QualType getAllocatedType() const {
729    assert(getType()->isPointerType());
730    return getType()->getAs<PointerType>()->getPointeeType();
731  }
732
733  FunctionDecl *getOperatorNew() const { return OperatorNew; }
734  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
735  CXXConstructorDecl *getConstructor() const { return Constructor; }
736
737  bool isArray() const { return Array; }
738  Expr *getArraySize() {
739    return Array ? cast<Expr>(SubExprs[0]) : 0;
740  }
741  const Expr *getArraySize() const {
742    return Array ? cast<Expr>(SubExprs[0]) : 0;
743  }
744
745  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
746  Expr *getPlacementArg(unsigned i) {
747    assert(i < NumPlacementArgs && "Index out of range");
748    return cast<Expr>(SubExprs[Array + i]);
749  }
750  const Expr *getPlacementArg(unsigned i) const {
751    assert(i < NumPlacementArgs && "Index out of range");
752    return cast<Expr>(SubExprs[Array + i]);
753  }
754
755  bool isGlobalNew() const { return GlobalNew; }
756  bool isParenTypeId() const { return ParenTypeId; }
757  bool hasInitializer() const { return Initializer; }
758
759  unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
760  Expr *getConstructorArg(unsigned i) {
761    assert(i < NumConstructorArgs && "Index out of range");
762    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
763  }
764  const Expr *getConstructorArg(unsigned i) const {
765    assert(i < NumConstructorArgs && "Index out of range");
766    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
767  }
768
769  typedef ExprIterator arg_iterator;
770  typedef ConstExprIterator const_arg_iterator;
771
772  arg_iterator placement_arg_begin() {
773    return SubExprs + Array;
774  }
775  arg_iterator placement_arg_end() {
776    return SubExprs + Array + getNumPlacementArgs();
777  }
778  const_arg_iterator placement_arg_begin() const {
779    return SubExprs + Array;
780  }
781  const_arg_iterator placement_arg_end() const {
782    return SubExprs + Array + getNumPlacementArgs();
783  }
784
785  arg_iterator constructor_arg_begin() {
786    return SubExprs + Array + getNumPlacementArgs();
787  }
788  arg_iterator constructor_arg_end() {
789    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
790  }
791  const_arg_iterator constructor_arg_begin() const {
792    return SubExprs + Array + getNumPlacementArgs();
793  }
794  const_arg_iterator constructor_arg_end() const {
795    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
796  }
797
798  virtual SourceRange getSourceRange() const {
799    return SourceRange(StartLoc, EndLoc);
800  }
801
802  static bool classof(const Stmt *T) {
803    return T->getStmtClass() == CXXNewExprClass;
804  }
805  static bool classof(const CXXNewExpr *) { return true; }
806
807  // Iterators
808  virtual child_iterator child_begin();
809  virtual child_iterator child_end();
810};
811
812/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
813/// calls, e.g. "delete[] pArray".
814class CXXDeleteExpr : public Expr {
815  // Is this a forced global delete, i.e. "::delete"?
816  bool GlobalDelete : 1;
817  // Is this the array form of delete, i.e. "delete[]"?
818  bool ArrayForm : 1;
819  // Points to the operator delete overload that is used. Could be a member.
820  FunctionDecl *OperatorDelete;
821  // The pointer expression to be deleted.
822  Stmt *Argument;
823  // Location of the expression.
824  SourceLocation Loc;
825public:
826  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
827                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
828    : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete),
829      ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg),
830      Loc(loc) { }
831
832  bool isGlobalDelete() const { return GlobalDelete; }
833  bool isArrayForm() const { return ArrayForm; }
834
835  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
836
837  Expr *getArgument() { return cast<Expr>(Argument); }
838  const Expr *getArgument() const { return cast<Expr>(Argument); }
839
840  virtual SourceRange getSourceRange() const {
841    return SourceRange(Loc, Argument->getLocEnd());
842  }
843
844  static bool classof(const Stmt *T) {
845    return T->getStmtClass() == CXXDeleteExprClass;
846  }
847  static bool classof(const CXXDeleteExpr *) { return true; }
848
849  // Iterators
850  virtual child_iterator child_begin();
851  virtual child_iterator child_end();
852};
853
854/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
855///
856/// Example:
857///
858/// \code
859/// template<typename T>
860/// void destroy(T* ptr) {
861///   ptr->~T();
862/// }
863/// \endcode
864///
865/// When the template is parsed, the expression \c ptr->~T will be stored as
866/// a member reference expression. If it then instantiated with a scalar type
867/// as a template argument for T, the resulting expression will be a
868/// pseudo-destructor expression.
869class CXXPseudoDestructorExpr : public Expr {
870  /// \brief The base expression (that is being destroyed).
871  Stmt *Base;
872
873  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
874  /// period ('.').
875  bool IsArrow : 1;
876
877  /// \brief The location of the '.' or '->' operator.
878  SourceLocation OperatorLoc;
879
880  /// \brief The nested-name-specifier that follows the operator, if present.
881  NestedNameSpecifier *Qualifier;
882
883  /// \brief The source range that covers the nested-name-specifier, if
884  /// present.
885  SourceRange QualifierRange;
886
887  /// \brief The type being destroyed.
888  QualType DestroyedType;
889
890  /// \brief The location of the type after the '~'.
891  SourceLocation DestroyedTypeLoc;
892
893public:
894  CXXPseudoDestructorExpr(ASTContext &Context,
895                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
896                          NestedNameSpecifier *Qualifier,
897                          SourceRange QualifierRange,
898                          QualType DestroyedType,
899                          SourceLocation DestroyedTypeLoc)
900    : Expr(CXXPseudoDestructorExprClass,
901           Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
902                                                          false, 0)),
903           /*isTypeDependent=*/false,
904           /*isValueDependent=*/Base->isValueDependent()),
905      Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
906      OperatorLoc(OperatorLoc), Qualifier(Qualifier),
907      QualifierRange(QualifierRange), DestroyedType(DestroyedType),
908      DestroyedTypeLoc(DestroyedTypeLoc) { }
909
910  void setBase(Expr *E) { Base = E; }
911  Expr *getBase() const { return cast<Expr>(Base); }
912
913  /// \brief Determines whether this member expression actually had
914  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
915  /// x->Base::foo.
916  bool hasQualifier() const { return Qualifier != 0; }
917
918  /// \brief If the member name was qualified, retrieves the source range of
919  /// the nested-name-specifier that precedes the member name. Otherwise,
920  /// returns an empty source range.
921  SourceRange getQualifierRange() const { return QualifierRange; }
922
923  /// \brief If the member name was qualified, retrieves the
924  /// nested-name-specifier that precedes the member name. Otherwise, returns
925  /// NULL.
926  NestedNameSpecifier *getQualifier() const { return Qualifier; }
927
928  /// \brief Determine whether this pseudo-destructor expression was written
929  /// using an '->' (otherwise, it used a '.').
930  bool isArrow() const { return IsArrow; }
931  void setArrow(bool A) { IsArrow = A; }
932
933  /// \brief Retrieve the location of the '.' or '->' operator.
934  SourceLocation getOperatorLoc() const { return OperatorLoc; }
935
936  /// \brief Retrieve the type that is being destroyed.
937  QualType getDestroyedType() const { return DestroyedType; }
938
939  /// \brief Retrieve the location of the type being destroyed.
940  SourceLocation getDestroyedTypeLoc() const { return DestroyedTypeLoc; }
941
942  virtual SourceRange getSourceRange() const {
943    return SourceRange(Base->getLocStart(), DestroyedTypeLoc);
944  }
945
946  static bool classof(const Stmt *T) {
947    return T->getStmtClass() == CXXPseudoDestructorExprClass;
948  }
949  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
950
951  // Iterators
952  virtual child_iterator child_begin();
953  virtual child_iterator child_end();
954};
955
956/// \brief Represents the name of a function that has not been
957/// resolved to any declaration.
958///
959/// Unresolved function names occur when a function name is
960/// encountered prior to an open parentheses ('(') in a C++ function
961/// call, and the function name itself did not resolve to a
962/// declaration. These function names can only be resolved when they
963/// form the postfix-expression of a function call, so that
964/// argument-dependent lookup finds declarations corresponding to
965/// these functions.
966
967/// @code
968/// template<typename T> void f(T x) {
969///   g(x); // g is an unresolved function name (that is also a dependent name)
970/// }
971/// @endcode
972class UnresolvedFunctionNameExpr : public Expr {
973  /// The name that was present in the source
974  DeclarationName Name;
975
976  /// The location of this name in the source code
977  SourceLocation Loc;
978
979public:
980  UnresolvedFunctionNameExpr(DeclarationName N, QualType T, SourceLocation L)
981    : Expr(UnresolvedFunctionNameExprClass, T, false, false), Name(N), Loc(L) { }
982
983  /// \brief Retrieves the name that occurred in the source code.
984  DeclarationName getName() const { return Name; }
985
986  /// getLocation - Retrieves the location in the source code where
987  /// the name occurred.
988  SourceLocation getLocation() const { return Loc; }
989
990  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
991
992  static bool classof(const Stmt *T) {
993    return T->getStmtClass() == UnresolvedFunctionNameExprClass;
994  }
995  static bool classof(const UnresolvedFunctionNameExpr *) { return true; }
996
997  // Iterators
998  virtual child_iterator child_begin();
999  virtual child_iterator child_end();
1000};
1001
1002/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1003/// implementation of TR1/C++0x type trait templates.
1004/// Example:
1005/// __is_pod(int) == true
1006/// __is_enum(std::string) == false
1007class UnaryTypeTraitExpr : public Expr {
1008  /// UTT - The trait.
1009  UnaryTypeTrait UTT;
1010
1011  /// Loc - The location of the type trait keyword.
1012  SourceLocation Loc;
1013
1014  /// RParen - The location of the closing paren.
1015  SourceLocation RParen;
1016
1017  /// QueriedType - The type we're testing.
1018  QualType QueriedType;
1019
1020public:
1021  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried,
1022                     SourceLocation rparen, QualType ty)
1023    : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
1024      UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
1025
1026  virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1027
1028  UnaryTypeTrait getTrait() const { return UTT; }
1029
1030  QualType getQueriedType() const { return QueriedType; }
1031
1032  bool EvaluateTrait(ASTContext&) const;
1033
1034  static bool classof(const Stmt *T) {
1035    return T->getStmtClass() == UnaryTypeTraitExprClass;
1036  }
1037  static bool classof(const UnaryTypeTraitExpr *) { return true; }
1038
1039  // Iterators
1040  virtual child_iterator child_begin();
1041  virtual child_iterator child_end();
1042};
1043
1044/// QualifiedDeclRefExpr - A reference to a declared variable,
1045/// function, enum, etc., that includes a qualification, e.g.,
1046/// "N::foo".
1047class QualifiedDeclRefExpr : public DeclRefExpr {
1048  /// QualifierRange - The source range that covers the
1049  /// nested-name-specifier.
1050  SourceRange QualifierRange;
1051
1052  /// \brief The nested-name-specifier that qualifies this declaration
1053  /// name.
1054  NestedNameSpecifier *NNS;
1055
1056public:
1057  QualifiedDeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD,
1058                       bool VD, SourceRange R, NestedNameSpecifier *NNS)
1059    : DeclRefExpr(QualifiedDeclRefExprClass, d, t, l, TD, VD),
1060      QualifierRange(R), NNS(NNS) { }
1061
1062  /// \brief Retrieve the source range of the nested-name-specifier.
1063  SourceRange getQualifierRange() const { return QualifierRange; }
1064
1065  /// \brief Retrieve the nested-name-specifier that qualifies this
1066  /// declaration.
1067  NestedNameSpecifier *getQualifier() const { return NNS; }
1068
1069  virtual SourceRange getSourceRange() const {
1070    return SourceRange(QualifierRange.getBegin(), getLocation());
1071  }
1072
1073  static bool classof(const Stmt *T) {
1074    return T->getStmtClass() == QualifiedDeclRefExprClass;
1075  }
1076  static bool classof(const QualifiedDeclRefExpr *) { return true; }
1077};
1078
1079/// \brief A qualified reference to a name whose declaration cannot
1080/// yet be resolved.
1081///
1082/// UnresolvedDeclRefExpr is similar to QualifiedDeclRefExpr in that
1083/// it expresses a qualified reference to a declaration such as
1084/// X<T>::value. The difference, however, is that an
1085/// UnresolvedDeclRefExpr node is used only within C++ templates when
1086/// the qualification (e.g., X<T>::) refers to a dependent type. In
1087/// this case, X<T>::value cannot resolve to a declaration because the
1088/// declaration will differ from on instantiation of X<T> to the
1089/// next. Therefore, UnresolvedDeclRefExpr keeps track of the
1090/// qualifier (X<T>::) and the name of the entity being referenced
1091/// ("value"). Such expressions will instantiate to
1092/// QualifiedDeclRefExprs.
1093class UnresolvedDeclRefExpr : public Expr {
1094  /// The name of the entity we will be referencing.
1095  DeclarationName Name;
1096
1097  /// Location of the name of the declaration we're referencing.
1098  SourceLocation Loc;
1099
1100  /// QualifierRange - The source range that covers the
1101  /// nested-name-specifier.
1102  SourceRange QualifierRange;
1103
1104  /// \brief The nested-name-specifier that qualifies this unresolved
1105  /// declaration name.
1106  NestedNameSpecifier *NNS;
1107
1108  /// \brief Whether this expr is an address of (&) operand.
1109  bool IsAddressOfOperand;
1110
1111public:
1112  UnresolvedDeclRefExpr(DeclarationName N, QualType T, SourceLocation L,
1113                        SourceRange R, NestedNameSpecifier *NNS,
1114                        bool IsAddressOfOperand)
1115    : Expr(UnresolvedDeclRefExprClass, T, true, true),
1116      Name(N), Loc(L), QualifierRange(R), NNS(NNS),
1117      IsAddressOfOperand(IsAddressOfOperand) { }
1118
1119  /// \brief Retrieve the name that this expression refers to.
1120  DeclarationName getDeclName() const { return Name; }
1121
1122  /// \brief Retrieve the location of the name within the expression.
1123  SourceLocation getLocation() const { return Loc; }
1124
1125  /// \brief Retrieve the source range of the nested-name-specifier.
1126  SourceRange getQualifierRange() const { return QualifierRange; }
1127
1128  /// \brief Retrieve the nested-name-specifier that qualifies this
1129  /// declaration.
1130  NestedNameSpecifier *getQualifier() const { return NNS; }
1131
1132  /// \brief Retrieve whether this is an address of (&) operand.
1133
1134  bool isAddressOfOperand() const { return IsAddressOfOperand; }
1135  virtual SourceRange getSourceRange() const {
1136    return SourceRange(QualifierRange.getBegin(), getLocation());
1137  }
1138
1139  static bool classof(const Stmt *T) {
1140    return T->getStmtClass() == UnresolvedDeclRefExprClass;
1141  }
1142  static bool classof(const UnresolvedDeclRefExpr *) { return true; }
1143
1144  virtual StmtIterator child_begin();
1145  virtual StmtIterator child_end();
1146};
1147
1148/// \brief An expression that refers to a C++ template-id, such as
1149/// @c isa<FunctionDecl>.
1150class TemplateIdRefExpr : public Expr {
1151  /// \brief If this template-id was qualified-id, e.g., @c std::sort<int>,
1152  /// this nested name specifier contains the @c std::.
1153  NestedNameSpecifier *Qualifier;
1154
1155  /// \brief If this template-id was a qualified-id, e.g., @c std::sort<int>,
1156  /// this covers the source code range of the @c std::.
1157  SourceRange QualifierRange;
1158
1159  /// \brief The actual template to which this template-id refers.
1160  TemplateName Template;
1161
1162  /// \brief The source location of the template name.
1163  SourceLocation TemplateNameLoc;
1164
1165  /// \brief The source location of the left angle bracket ('<');
1166  SourceLocation LAngleLoc;
1167
1168  /// \brief The source location of the right angle bracket ('>');
1169  SourceLocation RAngleLoc;
1170
1171  /// \brief The number of template arguments in TemplateArgs.
1172  unsigned NumTemplateArgs;
1173
1174  TemplateIdRefExpr(QualType T,
1175                    NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
1176                    TemplateName Template, SourceLocation TemplateNameLoc,
1177                    SourceLocation LAngleLoc,
1178                    const TemplateArgument *TemplateArgs,
1179                    unsigned NumTemplateArgs,
1180                    SourceLocation RAngleLoc);
1181
1182  virtual void DoDestroy(ASTContext &Context);
1183
1184public:
1185  static TemplateIdRefExpr *
1186  Create(ASTContext &Context, QualType T,
1187         NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
1188         TemplateName Template, SourceLocation TemplateNameLoc,
1189         SourceLocation LAngleLoc, const TemplateArgument *TemplateArgs,
1190         unsigned NumTemplateArgs, SourceLocation RAngleLoc);
1191
1192  /// \brief Retrieve the nested name specifier used to qualify the name of
1193  /// this template-id, e.g., the "std::sort" in @c std::sort<int>, or NULL
1194  /// if this template-id was an unqualified-id.
1195  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1196
1197  /// \brief Retrieve the source range describing the nested name specifier
1198  /// used to qualified the name of this template-id, if the name was qualified.
1199  SourceRange getQualifierRange() const { return QualifierRange; }
1200
1201  /// \brief Retrieve the name of the template referenced, e.g., "sort" in
1202  /// @c std::sort<int>;
1203  TemplateName getTemplateName() const { return Template; }
1204
1205  /// \brief Retrieve the location of the name of the template referenced, e.g.,
1206  /// the location of "sort" in @c std::sort<int>.
1207  SourceLocation getTemplateNameLoc() const { return TemplateNameLoc; }
1208
1209  /// \brief Retrieve the location of the left angle bracket following the
1210  /// template name ('<').
1211  SourceLocation getLAngleLoc() const { return LAngleLoc; }
1212
1213  /// \brief Retrieve the template arguments provided as part of this
1214  /// template-id.
1215  const TemplateArgument *getTemplateArgs() const {
1216    return reinterpret_cast<const TemplateArgument *>(this + 1);
1217  }
1218
1219  /// \brief Retrieve the number of template arguments provided as part of this
1220  /// template-id.
1221  unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
1222
1223  /// \brief Retrieve the location of the right angle bracket following the
1224  /// template arguments ('>').
1225  SourceLocation getRAngleLoc() const { return RAngleLoc; }
1226
1227  virtual SourceRange getSourceRange() const {
1228    return SourceRange(Qualifier? QualifierRange.getBegin() : TemplateNameLoc,
1229                       RAngleLoc);
1230  }
1231
1232  // Iterators
1233  virtual child_iterator child_begin();
1234  virtual child_iterator child_end();
1235
1236  static bool classof(const Stmt *T) {
1237    return T->getStmtClass() == TemplateIdRefExprClass;
1238  }
1239  static bool classof(const TemplateIdRefExpr *) { return true; }
1240};
1241
1242class CXXExprWithTemporaries : public Expr {
1243  Stmt *SubExpr;
1244
1245  CXXTemporary **Temps;
1246  unsigned NumTemps;
1247
1248  bool ShouldDestroyTemps;
1249
1250  CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps,
1251                         unsigned NumTemps, bool ShouldDestroyTemps);
1252  ~CXXExprWithTemporaries();
1253
1254protected:
1255  virtual void DoDestroy(ASTContext &C);
1256
1257public:
1258  static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
1259                                        CXXTemporary **Temps, unsigned NumTemps,
1260                                        bool ShouldDestroyTemporaries);
1261
1262  unsigned getNumTemporaries() const { return NumTemps; }
1263  CXXTemporary *getTemporary(unsigned i) {
1264    assert(i < NumTemps && "Index out of range");
1265    return Temps[i];
1266  }
1267  const CXXTemporary *getTemporary(unsigned i) const {
1268    assert(i < NumTemps && "Index out of range");
1269    return Temps[i];
1270  }
1271
1272  bool shouldDestroyTemporaries() const { return ShouldDestroyTemps; }
1273
1274  void removeLastTemporary() { NumTemps--; }
1275
1276  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1277  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1278  void setSubExpr(Expr *E) { SubExpr = E; }
1279
1280  virtual SourceRange getSourceRange() const { return SourceRange(); }
1281
1282  // Implement isa/cast/dyncast/etc.
1283  static bool classof(const Stmt *T) {
1284    return T->getStmtClass() == CXXExprWithTemporariesClass;
1285  }
1286  static bool classof(const CXXExprWithTemporaries *) { return true; }
1287
1288  // Iterators
1289  virtual child_iterator child_begin();
1290  virtual child_iterator child_end();
1291};
1292
1293/// \brief Describes an explicit type conversion that uses functional
1294/// notion but could not be resolved because one or more arguments are
1295/// type-dependent.
1296///
1297/// The explicit type conversions expressed by
1298/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1299/// where \c T is some type and \c a1, a2, ..., aN are values, and
1300/// either \C T is a dependent type or one or more of the \c a's is
1301/// type-dependent. For example, this would occur in a template such
1302/// as:
1303///
1304/// \code
1305///   template<typename T, typename A1>
1306///   inline T make_a(const A1& a1) {
1307///     return T(a1);
1308///   }
1309/// \endcode
1310///
1311/// When the returned expression is instantiated, it may resolve to a
1312/// constructor call, conversion function call, or some kind of type
1313/// conversion.
1314class CXXUnresolvedConstructExpr : public Expr {
1315  /// \brief The starting location of the type
1316  SourceLocation TyBeginLoc;
1317
1318  /// \brief The type being constructed.
1319  QualType Type;
1320
1321  /// \brief The location of the left parentheses ('(').
1322  SourceLocation LParenLoc;
1323
1324  /// \brief The location of the right parentheses (')').
1325  SourceLocation RParenLoc;
1326
1327  /// \brief The number of arguments used to construct the type.
1328  unsigned NumArgs;
1329
1330  CXXUnresolvedConstructExpr(SourceLocation TyBegin,
1331                             QualType T,
1332                             SourceLocation LParenLoc,
1333                             Expr **Args,
1334                             unsigned NumArgs,
1335                             SourceLocation RParenLoc);
1336
1337public:
1338  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1339                                            SourceLocation TyBegin,
1340                                            QualType T,
1341                                            SourceLocation LParenLoc,
1342                                            Expr **Args,
1343                                            unsigned NumArgs,
1344                                            SourceLocation RParenLoc);
1345
1346  /// \brief Retrieve the source location where the type begins.
1347  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1348  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1349
1350  /// \brief Retrieve the type that is being constructed, as specified
1351  /// in the source code.
1352  QualType getTypeAsWritten() const { return Type; }
1353  void setTypeAsWritten(QualType T) { Type = T; }
1354
1355  /// \brief Retrieve the location of the left parentheses ('(') that
1356  /// precedes the argument list.
1357  SourceLocation getLParenLoc() const { return LParenLoc; }
1358  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1359
1360  /// \brief Retrieve the location of the right parentheses (')') that
1361  /// follows the argument list.
1362  SourceLocation getRParenLoc() const { return RParenLoc; }
1363  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1364
1365  /// \brief Retrieve the number of arguments.
1366  unsigned arg_size() const { return NumArgs; }
1367
1368  typedef Expr** arg_iterator;
1369  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1370  arg_iterator arg_end() { return arg_begin() + NumArgs; }
1371
1372  Expr *getArg(unsigned I) {
1373    assert(I < NumArgs && "Argument index out-of-range");
1374    return *(arg_begin() + I);
1375  }
1376
1377  virtual SourceRange getSourceRange() const {
1378    return SourceRange(TyBeginLoc, RParenLoc);
1379  }
1380  static bool classof(const Stmt *T) {
1381    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1382  }
1383  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
1384
1385  // Iterators
1386  virtual child_iterator child_begin();
1387  virtual child_iterator child_end();
1388};
1389
1390/// \brief Represents a C++ member access expression where the actual member
1391/// referenced could not be resolved, e.g., because the base expression or the
1392/// member name was dependent.
1393class CXXUnresolvedMemberExpr : public Expr {
1394  /// \brief The expression for the base pointer or class reference,
1395  /// e.g., the \c x in x.f.
1396  Stmt *Base;
1397
1398  /// \brief Whether this member expression used the '->' operator or
1399  /// the '.' operator.
1400  bool IsArrow;
1401
1402  /// \brief The location of the '->' or '.' operator.
1403  SourceLocation OperatorLoc;
1404
1405  /// \brief The nested-name-specifier that precedes the member name, if any.
1406  NestedNameSpecifier *Qualifier;
1407
1408  /// \brief The source range covering the nested name specifier.
1409  SourceRange QualifierRange;
1410
1411  /// \brief In a qualified member access expression such as t->Base::f, this
1412  /// member stores the resolves of name lookup in the context of the member
1413  /// access expression, to be used at instantiation time.
1414  ///
1415  /// FIXME: This member, along with the Qualifier and QualifierRange, could
1416  /// be stuck into a structure that is optionally allocated at the end of
1417  /// the CXXUnresolvedMemberExpr, to save space in the common case.
1418  NamedDecl *FirstQualifierFoundInScope;
1419
1420  /// \brief The member to which this member expression refers, which
1421  /// can be name, overloaded operator, or destructor.
1422  /// FIXME: could also be a template-id
1423  DeclarationName Member;
1424
1425  /// \brief The location of the member name.
1426  SourceLocation MemberLoc;
1427
1428public:
1429  CXXUnresolvedMemberExpr(ASTContext &C,
1430                          Expr *Base, bool IsArrow,
1431                          SourceLocation OperatorLoc,
1432                          NestedNameSpecifier *Qualifier,
1433                          SourceRange QualifierRange,
1434                          NamedDecl *FirstQualifierFoundInScope,
1435                          DeclarationName Member,
1436                          SourceLocation MemberLoc)
1437    : Expr(CXXUnresolvedMemberExprClass, C.DependentTy, true, true),
1438      Base(Base), IsArrow(IsArrow), OperatorLoc(OperatorLoc),
1439      Qualifier(Qualifier), QualifierRange(QualifierRange),
1440      FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1441      Member(Member), MemberLoc(MemberLoc) { }
1442
1443  /// \brief Retrieve the base object of this member expressions,
1444  /// e.g., the \c x in \c x.m.
1445  Expr *getBase() { return cast<Expr>(Base); }
1446  void setBase(Expr *E) { Base = E; }
1447
1448  /// \brief Determine whether this member expression used the '->'
1449  /// operator; otherwise, it used the '.' operator.
1450  bool isArrow() const { return IsArrow; }
1451  void setArrow(bool A) { IsArrow = A; }
1452
1453  /// \brief Retrieve the location of the '->' or '.' operator.
1454  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1455  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1456
1457  /// \brief Retrieve the nested-name-specifier that qualifies the member
1458  /// name.
1459  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1460
1461  /// \brief Retrieve the source range covering the nested-name-specifier
1462  /// that qualifies the member name.
1463  SourceRange getQualifierRange() const { return QualifierRange; }
1464
1465  /// \brief Retrieve the first part of the nested-name-specifier that was
1466  /// found in the scope of the member access expression when the member access
1467  /// was initially parsed.
1468  ///
1469  /// This function only returns a useful result when member access expression
1470  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
1471  /// returned by this function describes what was found by unqualified name
1472  /// lookup for the identifier "Base" within the scope of the member access
1473  /// expression itself. At template instantiation time, this information is
1474  /// combined with the results of name lookup into the type of the object
1475  /// expression itself (the class type of x).
1476  NamedDecl *getFirstQualifierFoundInScope() const {
1477    return FirstQualifierFoundInScope;
1478  }
1479
1480  /// \brief Retrieve the name of the member that this expression
1481  /// refers to.
1482  DeclarationName getMember() const { return Member; }
1483  void setMember(DeclarationName N) { Member = N; }
1484
1485  // \brief Retrieve the location of the name of the member that this
1486  // expression refers to.
1487  SourceLocation getMemberLoc() const { return MemberLoc; }
1488  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
1489
1490  virtual SourceRange getSourceRange() const {
1491    return SourceRange(Base->getSourceRange().getBegin(),
1492                       MemberLoc);
1493  }
1494  static bool classof(const Stmt *T) {
1495    return T->getStmtClass() == CXXUnresolvedMemberExprClass;
1496  }
1497  static bool classof(const CXXUnresolvedMemberExpr *) { return true; }
1498
1499  // Iterators
1500  virtual child_iterator child_begin();
1501  virtual child_iterator child_end();
1502};
1503
1504}  // end namespace clang
1505
1506#endif
1507