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