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