ExprCXX.h revision bd4c4aebe6035e7a7125470cc9f0f92511230ee3
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 the name of a function that has not been
855/// resolved to any declaration.
856///
857/// Unresolved function names occur when a function name is
858/// encountered prior to an open parentheses ('(') in a C++ function
859/// call, and the function name itself did not resolve to a
860/// declaration. These function names can only be resolved when they
861/// form the postfix-expression of a function call, so that
862/// argument-dependent lookup finds declarations corresponding to
863/// these functions.
864
865/// @code
866/// template<typename T> void f(T x) {
867///   g(x); // g is an unresolved function name (that is also a dependent name)
868/// }
869/// @endcode
870class UnresolvedFunctionNameExpr : public Expr {
871  /// The name that was present in the source
872  DeclarationName Name;
873
874  /// The location of this name in the source code
875  SourceLocation Loc;
876
877public:
878  UnresolvedFunctionNameExpr(DeclarationName N, QualType T, SourceLocation L)
879    : Expr(UnresolvedFunctionNameExprClass, T, false, false), Name(N), Loc(L) { }
880
881  /// \brief Retrieves the name that occurred in the source code.
882  DeclarationName getName() const { return Name; }
883
884  /// getLocation - Retrieves the location in the source code where
885  /// the name occurred.
886  SourceLocation getLocation() const { return Loc; }
887
888  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
889
890  static bool classof(const Stmt *T) {
891    return T->getStmtClass() == UnresolvedFunctionNameExprClass;
892  }
893  static bool classof(const UnresolvedFunctionNameExpr *) { return true; }
894
895  // Iterators
896  virtual child_iterator child_begin();
897  virtual child_iterator child_end();
898};
899
900/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
901/// implementation of TR1/C++0x type trait templates.
902/// Example:
903/// __is_pod(int) == true
904/// __is_enum(std::string) == false
905class UnaryTypeTraitExpr : public Expr {
906  /// UTT - The trait.
907  UnaryTypeTrait UTT;
908
909  /// Loc - The location of the type trait keyword.
910  SourceLocation Loc;
911
912  /// RParen - The location of the closing paren.
913  SourceLocation RParen;
914
915  /// QueriedType - The type we're testing.
916  QualType QueriedType;
917
918public:
919  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried,
920                     SourceLocation rparen, QualType ty)
921    : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
922      UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
923
924  virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
925
926  UnaryTypeTrait getTrait() const { return UTT; }
927
928  QualType getQueriedType() const { return QueriedType; }
929
930  bool EvaluateTrait(ASTContext&) const;
931
932  static bool classof(const Stmt *T) {
933    return T->getStmtClass() == UnaryTypeTraitExprClass;
934  }
935  static bool classof(const UnaryTypeTraitExpr *) { return true; }
936
937  // Iterators
938  virtual child_iterator child_begin();
939  virtual child_iterator child_end();
940};
941
942/// QualifiedDeclRefExpr - A reference to a declared variable,
943/// function, enum, etc., that includes a qualification, e.g.,
944/// "N::foo".
945class QualifiedDeclRefExpr : public DeclRefExpr {
946  /// QualifierRange - The source range that covers the
947  /// nested-name-specifier.
948  SourceRange QualifierRange;
949
950  /// \brief The nested-name-specifier that qualifies this declaration
951  /// name.
952  NestedNameSpecifier *NNS;
953
954public:
955  QualifiedDeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD,
956                       bool VD, SourceRange R, NestedNameSpecifier *NNS)
957    : DeclRefExpr(QualifiedDeclRefExprClass, d, t, l, TD, VD),
958      QualifierRange(R), NNS(NNS) { }
959
960  /// \brief Retrieve the source range of the nested-name-specifier.
961  SourceRange getQualifierRange() const { return QualifierRange; }
962
963  /// \brief Retrieve the nested-name-specifier that qualifies this
964  /// declaration.
965  NestedNameSpecifier *getQualifier() const { return NNS; }
966
967  virtual SourceRange getSourceRange() const {
968    return SourceRange(QualifierRange.getBegin(), getLocation());
969  }
970
971  static bool classof(const Stmt *T) {
972    return T->getStmtClass() == QualifiedDeclRefExprClass;
973  }
974  static bool classof(const QualifiedDeclRefExpr *) { return true; }
975};
976
977/// \brief A qualified reference to a name whose declaration cannot
978/// yet be resolved.
979///
980/// UnresolvedDeclRefExpr is similar to QualifiedDeclRefExpr in that
981/// it expresses a qualified reference to a declaration such as
982/// X<T>::value. The difference, however, is that an
983/// UnresolvedDeclRefExpr node is used only within C++ templates when
984/// the qualification (e.g., X<T>::) refers to a dependent type. In
985/// this case, X<T>::value cannot resolve to a declaration because the
986/// declaration will differ from on instantiation of X<T> to the
987/// next. Therefore, UnresolvedDeclRefExpr keeps track of the
988/// qualifier (X<T>::) and the name of the entity being referenced
989/// ("value"). Such expressions will instantiate to
990/// QualifiedDeclRefExprs.
991class UnresolvedDeclRefExpr : public Expr {
992  /// The name of the entity we will be referencing.
993  DeclarationName Name;
994
995  /// Location of the name of the declaration we're referencing.
996  SourceLocation Loc;
997
998  /// QualifierRange - The source range that covers the
999  /// nested-name-specifier.
1000  SourceRange QualifierRange;
1001
1002  /// \brief The nested-name-specifier that qualifies this unresolved
1003  /// declaration name.
1004  NestedNameSpecifier *NNS;
1005
1006  /// \brief Whether this expr is an address of (&) operand.
1007  bool IsAddressOfOperand;
1008
1009public:
1010  UnresolvedDeclRefExpr(DeclarationName N, QualType T, SourceLocation L,
1011                        SourceRange R, NestedNameSpecifier *NNS,
1012                        bool IsAddressOfOperand)
1013    : Expr(UnresolvedDeclRefExprClass, T, true, true),
1014      Name(N), Loc(L), QualifierRange(R), NNS(NNS),
1015      IsAddressOfOperand(IsAddressOfOperand) { }
1016
1017  /// \brief Retrieve the name that this expression refers to.
1018  DeclarationName getDeclName() const { return Name; }
1019
1020  /// \brief Retrieve the location of the name within the expression.
1021  SourceLocation getLocation() const { return Loc; }
1022
1023  /// \brief Retrieve the source range of the nested-name-specifier.
1024  SourceRange getQualifierRange() const { return QualifierRange; }
1025
1026  /// \brief Retrieve the nested-name-specifier that qualifies this
1027  /// declaration.
1028  NestedNameSpecifier *getQualifier() const { return NNS; }
1029
1030  /// \brief Retrieve whether this is an address of (&) operand.
1031
1032  bool isAddressOfOperand() const { return IsAddressOfOperand; }
1033  virtual SourceRange getSourceRange() const {
1034    return SourceRange(QualifierRange.getBegin(), getLocation());
1035  }
1036
1037  static bool classof(const Stmt *T) {
1038    return T->getStmtClass() == UnresolvedDeclRefExprClass;
1039  }
1040  static bool classof(const UnresolvedDeclRefExpr *) { return true; }
1041
1042  virtual StmtIterator child_begin();
1043  virtual StmtIterator child_end();
1044};
1045
1046/// \brief An expression that refers to a C++ template-id, such as
1047/// @c isa<FunctionDecl>.
1048class TemplateIdRefExpr : public Expr {
1049  /// \brief If this template-id was qualified-id, e.g., @c std::sort<int>,
1050  /// this nested name specifier contains the @c std::.
1051  NestedNameSpecifier *Qualifier;
1052
1053  /// \brief If this template-id was a qualified-id, e.g., @c std::sort<int>,
1054  /// this covers the source code range of the @c std::.
1055  SourceRange QualifierRange;
1056
1057  /// \brief The actual template to which this template-id refers.
1058  TemplateName Template;
1059
1060  /// \brief The source location of the template name.
1061  SourceLocation TemplateNameLoc;
1062
1063  /// \brief The source location of the left angle bracket ('<');
1064  SourceLocation LAngleLoc;
1065
1066  /// \brief The source location of the right angle bracket ('>');
1067  SourceLocation RAngleLoc;
1068
1069  /// \brief The number of template arguments in TemplateArgs.
1070  unsigned NumTemplateArgs;
1071
1072  TemplateIdRefExpr(QualType T,
1073                    NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
1074                    TemplateName Template, SourceLocation TemplateNameLoc,
1075                    SourceLocation LAngleLoc,
1076                    const TemplateArgument *TemplateArgs,
1077                    unsigned NumTemplateArgs,
1078                    SourceLocation RAngleLoc);
1079
1080  virtual void DoDestroy(ASTContext &Context);
1081
1082public:
1083  static TemplateIdRefExpr *
1084  Create(ASTContext &Context, QualType T,
1085         NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
1086         TemplateName Template, SourceLocation TemplateNameLoc,
1087         SourceLocation LAngleLoc, const TemplateArgument *TemplateArgs,
1088         unsigned NumTemplateArgs, SourceLocation RAngleLoc);
1089
1090  /// \brief Retrieve the nested name specifier used to qualify the name of
1091  /// this template-id, e.g., the "std::sort" in @c std::sort<int>, or NULL
1092  /// if this template-id was an unqualified-id.
1093  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1094
1095  /// \brief Retrieve the source range describing the nested name specifier
1096  /// used to qualified the name of this template-id, if the name was qualified.
1097  SourceRange getQualifierRange() const { return QualifierRange; }
1098
1099  /// \brief Retrieve the name of the template referenced, e.g., "sort" in
1100  /// @c std::sort<int>;
1101  TemplateName getTemplateName() const { return Template; }
1102
1103  /// \brief Retrieve the location of the name of the template referenced, e.g.,
1104  /// the location of "sort" in @c std::sort<int>.
1105  SourceLocation getTemplateNameLoc() const { return TemplateNameLoc; }
1106
1107  /// \brief Retrieve the location of the left angle bracket following the
1108  /// template name ('<').
1109  SourceLocation getLAngleLoc() const { return LAngleLoc; }
1110
1111  /// \brief Retrieve the template arguments provided as part of this
1112  /// template-id.
1113  const TemplateArgument *getTemplateArgs() const {
1114    return reinterpret_cast<const TemplateArgument *>(this + 1);
1115  }
1116
1117  /// \brief Retrieve the number of template arguments provided as part of this
1118  /// template-id.
1119  unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
1120
1121  /// \brief Retrieve the location of the right angle bracket following the
1122  /// template arguments ('>').
1123  SourceLocation getRAngleLoc() const { return RAngleLoc; }
1124
1125  virtual SourceRange getSourceRange() const {
1126    return SourceRange(Qualifier? QualifierRange.getBegin() : TemplateNameLoc,
1127                       RAngleLoc);
1128  }
1129
1130  // Iterators
1131  virtual child_iterator child_begin();
1132  virtual child_iterator child_end();
1133
1134  static bool classof(const Stmt *T) {
1135    return T->getStmtClass() == TemplateIdRefExprClass;
1136  }
1137  static bool classof(const TemplateIdRefExpr *) { return true; }
1138};
1139
1140class CXXExprWithTemporaries : public Expr {
1141  Stmt *SubExpr;
1142
1143  CXXTemporary **Temps;
1144  unsigned NumTemps;
1145
1146  bool ShouldDestroyTemps;
1147
1148  CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps,
1149                         unsigned NumTemps, bool ShouldDestroyTemps);
1150  ~CXXExprWithTemporaries();
1151
1152protected:
1153  virtual void DoDestroy(ASTContext &C);
1154
1155public:
1156  static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
1157                                        CXXTemporary **Temps, unsigned NumTemps,
1158                                        bool ShouldDestroyTemporaries);
1159
1160  unsigned getNumTemporaries() const { return NumTemps; }
1161  CXXTemporary *getTemporary(unsigned i) {
1162    assert(i < NumTemps && "Index out of range");
1163    return Temps[i];
1164  }
1165  const CXXTemporary *getTemporary(unsigned i) const {
1166    assert(i < NumTemps && "Index out of range");
1167    return Temps[i];
1168  }
1169
1170  bool shouldDestroyTemporaries() const { return ShouldDestroyTemps; }
1171
1172  void removeLastTemporary() { NumTemps--; }
1173
1174  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1175  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1176  void setSubExpr(Expr *E) { SubExpr = E; }
1177
1178  virtual SourceRange getSourceRange() const { return SourceRange(); }
1179
1180  // Implement isa/cast/dyncast/etc.
1181  static bool classof(const Stmt *T) {
1182    return T->getStmtClass() == CXXExprWithTemporariesClass;
1183  }
1184  static bool classof(const CXXExprWithTemporaries *) { return true; }
1185
1186  // Iterators
1187  virtual child_iterator child_begin();
1188  virtual child_iterator child_end();
1189};
1190
1191/// \brief Describes an explicit type conversion that uses functional
1192/// notion but could not be resolved because one or more arguments are
1193/// type-dependent.
1194///
1195/// The explicit type conversions expressed by
1196/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1197/// where \c T is some type and \c a1, a2, ..., aN are values, and
1198/// either \C T is a dependent type or one or more of the \c a's is
1199/// type-dependent. For example, this would occur in a template such
1200/// as:
1201///
1202/// \code
1203///   template<typename T, typename A1>
1204///   inline T make_a(const A1& a1) {
1205///     return T(a1);
1206///   }
1207/// \endcode
1208///
1209/// When the returned expression is instantiated, it may resolve to a
1210/// constructor call, conversion function call, or some kind of type
1211/// conversion.
1212class CXXUnresolvedConstructExpr : public Expr {
1213  /// \brief The starting location of the type
1214  SourceLocation TyBeginLoc;
1215
1216  /// \brief The type being constructed.
1217  QualType Type;
1218
1219  /// \brief The location of the left parentheses ('(').
1220  SourceLocation LParenLoc;
1221
1222  /// \brief The location of the right parentheses (')').
1223  SourceLocation RParenLoc;
1224
1225  /// \brief The number of arguments used to construct the type.
1226  unsigned NumArgs;
1227
1228  CXXUnresolvedConstructExpr(SourceLocation TyBegin,
1229                             QualType T,
1230                             SourceLocation LParenLoc,
1231                             Expr **Args,
1232                             unsigned NumArgs,
1233                             SourceLocation RParenLoc);
1234
1235public:
1236  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1237                                            SourceLocation TyBegin,
1238                                            QualType T,
1239                                            SourceLocation LParenLoc,
1240                                            Expr **Args,
1241                                            unsigned NumArgs,
1242                                            SourceLocation RParenLoc);
1243
1244  /// \brief Retrieve the source location where the type begins.
1245  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1246  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1247
1248  /// \brief Retrieve the type that is being constructed, as specified
1249  /// in the source code.
1250  QualType getTypeAsWritten() const { return Type; }
1251  void setTypeAsWritten(QualType T) { Type = T; }
1252
1253  /// \brief Retrieve the location of the left parentheses ('(') that
1254  /// precedes the argument list.
1255  SourceLocation getLParenLoc() const { return LParenLoc; }
1256  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1257
1258  /// \brief Retrieve the location of the right parentheses (')') that
1259  /// follows the argument list.
1260  SourceLocation getRParenLoc() const { return RParenLoc; }
1261  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1262
1263  /// \brief Retrieve the number of arguments.
1264  unsigned arg_size() const { return NumArgs; }
1265
1266  typedef Expr** arg_iterator;
1267  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1268  arg_iterator arg_end() { return arg_begin() + NumArgs; }
1269
1270  Expr *getArg(unsigned I) {
1271    assert(I < NumArgs && "Argument index out-of-range");
1272    return *(arg_begin() + I);
1273  }
1274
1275  virtual SourceRange getSourceRange() const {
1276    return SourceRange(TyBeginLoc, RParenLoc);
1277  }
1278  static bool classof(const Stmt *T) {
1279    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1280  }
1281  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
1282
1283  // Iterators
1284  virtual child_iterator child_begin();
1285  virtual child_iterator child_end();
1286};
1287
1288/// \brief Represents a C++ member access expression that was written using
1289/// a qualified name, e.g., "x->Base::f()".
1290class CXXQualifiedMemberExpr : public MemberExpr {
1291  /// QualifierRange - The source range that covers the
1292  /// nested-name-specifier.
1293  SourceRange QualifierRange;
1294
1295  /// \brief The nested-name-specifier that qualifies this declaration
1296  /// name.
1297  NestedNameSpecifier *Qualifier;
1298
1299public:
1300  CXXQualifiedMemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *Qual,
1301                         SourceRange QualRange, NamedDecl *memberdecl,
1302                         SourceLocation l, QualType ty)
1303    : MemberExpr(CXXQualifiedMemberExprClass, base, isarrow, memberdecl, l, ty),
1304      QualifierRange(QualRange), Qualifier(Qual) { }
1305
1306  /// \brief Retrieve the source range of the nested-name-specifier that
1307  /// qualifies the member name.
1308  SourceRange getQualifierRange() const { return QualifierRange; }
1309
1310  /// \brief Retrieve the nested-name-specifier that qualifies the
1311  /// member reference expression.
1312  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1313
1314  static bool classof(const Stmt *T) {
1315    return T->getStmtClass() == CXXQualifiedMemberExprClass;
1316  }
1317  static bool classof(const CXXQualifiedMemberExpr *) { return true; }
1318};
1319
1320/// \brief Represents a C++ member access expression where the actual member
1321/// referenced could not be resolved, e.g., because the base expression or the
1322/// member name was dependent.
1323class CXXUnresolvedMemberExpr : public Expr {
1324  /// \brief The expression for the base pointer or class reference,
1325  /// e.g., the \c x in x.f.
1326  Stmt *Base;
1327
1328  /// \brief Whether this member expression used the '->' operator or
1329  /// the '.' operator.
1330  bool IsArrow;
1331
1332  /// \brief The location of the '->' or '.' operator.
1333  SourceLocation OperatorLoc;
1334
1335  /// \brief The member to which this member expression refers, which
1336  /// can be name, overloaded operator, or destructor.
1337  /// FIXME: could also be a template-id, and we might have a
1338  /// nested-name-specifier as well.
1339  DeclarationName Member;
1340
1341  /// \brief The location of the member name.
1342  SourceLocation MemberLoc;
1343
1344public:
1345  CXXUnresolvedMemberExpr(ASTContext &C,
1346                          Expr *Base, bool IsArrow,
1347                          SourceLocation OperatorLoc,
1348                          DeclarationName Member,
1349                          SourceLocation MemberLoc)
1350    : Expr(CXXUnresolvedMemberExprClass, C.DependentTy, true, true),
1351      Base(Base), IsArrow(IsArrow), OperatorLoc(OperatorLoc),
1352      Member(Member), MemberLoc(MemberLoc) { }
1353
1354  /// \brief Retrieve the base object of this member expressions,
1355  /// e.g., the \c x in \c x.m.
1356  Expr *getBase() { return cast<Expr>(Base); }
1357  void setBase(Expr *E) { Base = E; }
1358
1359  /// \brief Determine whether this member expression used the '->'
1360  /// operator; otherwise, it used the '.' operator.
1361  bool isArrow() const { return IsArrow; }
1362  void setArrow(bool A) { IsArrow = A; }
1363
1364  /// \brief Retrieve the location of the '->' or '.' operator.
1365  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1366  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1367
1368  /// \brief Retrieve the name of the member that this expression
1369  /// refers to.
1370  DeclarationName getMember() const { return Member; }
1371  void setMember(DeclarationName N) { Member = N; }
1372
1373  // \brief Retrieve the location of the name of the member that this
1374  // expression refers to.
1375  SourceLocation getMemberLoc() const { return MemberLoc; }
1376  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
1377
1378  virtual SourceRange getSourceRange() const {
1379    return SourceRange(Base->getSourceRange().getBegin(),
1380                       MemberLoc);
1381  }
1382  static bool classof(const Stmt *T) {
1383    return T->getStmtClass() == CXXUnresolvedMemberExprClass;
1384  }
1385  static bool classof(const CXXUnresolvedMemberExpr *) { return true; }
1386
1387  // Iterators
1388  virtual child_iterator child_begin();
1389  virtual child_iterator child_end();
1390};
1391
1392}  // end namespace clang
1393
1394#endif
1395