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