ExprCXX.h revision 88a3514f36de96b19cdf50141c640df1a5f13f6c
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/AST/Expr.h"
18#include "clang/AST/Decl.h"
19
20namespace clang {
21
22  class CXXConstructorDecl;
23
24//===--------------------------------------------------------------------===//
25// C++ Expressions.
26//===--------------------------------------------------------------------===//
27
28/// CXXOperatorCallExpr - Represents a call to an overloaded operator
29/// written using operator syntax, e.g., "x + y" or "*p". While
30/// semantically equivalent to a normal call, this AST node provides
31/// better information about the syntactic representation of the call.
32class CXXOperatorCallExpr : public CallExpr {
33public:
34  CXXOperatorCallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
35                      SourceLocation operatorloc)
36    : CallExpr(CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc) { }
37
38  /// getOperator - Returns the kind of overloaded operator that this
39  /// expression refers to.
40  OverloadedOperatorKind getOperator() const;
41
42  /// getOperatorLoc - Returns the location of the operator symbol in
43  /// the expression. When @c getOperator()==OO_Call, this is the
44  /// location of the right parentheses; when @c
45  /// getOperator()==OO_Subscript, this is the location of the right
46  /// bracket.
47  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
48
49  virtual SourceRange getSourceRange() const;
50
51  static bool classof(const Stmt *T) {
52    return T->getStmtClass() == CXXOperatorCallExprClass;
53  }
54  static bool classof(const CXXOperatorCallExpr *) { return true; }
55};
56
57/// CXXMemberCallExpr - Represents a call to a member function that
58/// may be written either with member call syntax (e.g., "obj.func()"
59/// or "objptr->func()") or with normal function-call syntax
60/// ("func()") within a member function that ends up calling a member
61/// function. The callee in either case is a MemberExpr that contains
62/// both the object argument and the member function, while the
63/// arguments are the arguments within the parentheses (not including
64/// the object argument).
65class CXXMemberCallExpr : public CallExpr {
66public:
67  CXXMemberCallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
68                      SourceLocation rparenloc)
69    : CallExpr(CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) { }
70
71  /// getImplicitObjectArgument - Retrieves the implicit object
72  /// argument for the member call. For example, in "x.f(5)", this
73  /// operation would return "x".
74  Expr *getImplicitObjectArgument();
75
76  static bool classof(const Stmt *T) {
77    return T->getStmtClass() == CXXMemberCallExprClass;
78  }
79  static bool classof(const CXXMemberCallExpr *) { return true; }
80};
81
82/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
83/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
84/// const_cast.
85///
86/// This abstract class is inherited by all of the classes
87/// representing "named" casts, e.g., CXXStaticCastExpr,
88/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
89class CXXNamedCastExpr : public ExplicitCastExpr {
90private:
91  SourceLocation Loc; // the location of the casting op
92
93protected:
94  CXXNamedCastExpr(StmtClass SC, QualType ty, Expr *op, QualType writtenTy,
95                   SourceLocation l)
96    : ExplicitCastExpr(SC, ty, op, writtenTy), Loc(l) {}
97
98public:
99  const char *getCastName() const;
100
101  virtual SourceRange getSourceRange() const {
102    return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
103  }
104  static bool classof(const Stmt *T) {
105    switch (T->getStmtClass()) {
106    case CXXNamedCastExprClass:
107    case CXXStaticCastExprClass:
108    case CXXDynamicCastExprClass:
109    case CXXReinterpretCastExprClass:
110    case CXXConstCastExprClass:
111      return true;
112    default:
113      return false;
114    }
115  }
116  static bool classof(const CXXNamedCastExpr *) { return true; }
117
118  virtual void EmitImpl(llvm::Serializer& S) const;
119  static CXXNamedCastExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C,
120                                      StmtClass SC);
121};
122
123/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
124///
125/// This expression node represents a C++ static cast, e.g.,
126/// @c static_cast<int>(1.0).
127class CXXStaticCastExpr : public CXXNamedCastExpr {
128public:
129  CXXStaticCastExpr(QualType ty, Expr *op, QualType writtenTy, SourceLocation l)
130    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, op, writtenTy, l) {}
131
132  static bool classof(const Stmt *T) {
133    return T->getStmtClass() == CXXStaticCastExprClass;
134  }
135  static bool classof(const CXXStaticCastExpr *) { return true; }
136};
137
138/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
139/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
140/// determine how to perform the type cast.
141///
142/// This expression node represents a dynamic cast, e.g.,
143/// @c dynamic_cast<Derived*>(BasePtr).
144class CXXDynamicCastExpr : public CXXNamedCastExpr {
145public:
146  CXXDynamicCastExpr(QualType ty, Expr *op, QualType writtenTy, SourceLocation l)
147    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, op, writtenTy, l) {}
148
149  static bool classof(const Stmt *T) {
150    return T->getStmtClass() == CXXDynamicCastExprClass;
151  }
152  static bool classof(const CXXDynamicCastExpr *) { return true; }
153};
154
155/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
156/// [expr.reinterpret.cast]), which provides a differently-typed view
157/// of a value but performs no actual work at run time.
158///
159/// This expression node represents a reinterpret cast, e.g.,
160/// @c reinterpret_cast<int>(VoidPtr).
161class CXXReinterpretCastExpr : public CXXNamedCastExpr {
162public:
163  CXXReinterpretCastExpr(QualType ty, Expr *op, QualType writtenTy,
164                         SourceLocation l)
165    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, op, writtenTy, l) {}
166
167  static bool classof(const Stmt *T) {
168    return T->getStmtClass() == CXXReinterpretCastExprClass;
169  }
170  static bool classof(const CXXReinterpretCastExpr *) { return true; }
171};
172
173/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
174/// which can remove type qualifiers but does not change the underlying value.
175///
176/// This expression node represents a const cast, e.g.,
177/// @c const_cast<char*>(PtrToConstChar).
178class CXXConstCastExpr : public CXXNamedCastExpr {
179public:
180  CXXConstCastExpr(QualType ty, Expr *op, QualType writtenTy,
181                   SourceLocation l)
182    : CXXNamedCastExpr(CXXConstCastExprClass, ty, op, writtenTy, l) {}
183
184  static bool classof(const Stmt *T) {
185    return T->getStmtClass() == CXXConstCastExprClass;
186  }
187  static bool classof(const CXXConstCastExpr *) { return true; }
188};
189
190/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
191///
192class CXXBoolLiteralExpr : public Expr {
193  bool Value;
194  SourceLocation Loc;
195public:
196  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
197    Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {}
198
199  bool getValue() const { return Value; }
200
201  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
202
203  static bool classof(const Stmt *T) {
204    return T->getStmtClass() == CXXBoolLiteralExprClass;
205  }
206  static bool classof(const CXXBoolLiteralExpr *) { return true; }
207
208  // Iterators
209  virtual child_iterator child_begin();
210  virtual child_iterator child_end();
211};
212
213/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
214/// the type_info that corresponds to the supplied type, or the (possibly
215/// dynamic) type of the supplied expression.
216///
217/// This represents code like @c typeid(int) or @c typeid(*objPtr)
218class CXXTypeidExpr : public Expr {
219private:
220  bool isTypeOp : 1;
221  union {
222    void *Ty;
223    Stmt *Ex;
224  } Operand;
225  SourceRange Range;
226
227public:
228  CXXTypeidExpr(bool isTypeOp, void *op, QualType Ty, const SourceRange r) :
229      Expr(CXXTypeidExprClass, Ty), isTypeOp(isTypeOp), Range(r) {
230    if (isTypeOp)
231      Operand.Ty = op;
232    else
233      // op was an Expr*, so cast it back to that to be safe
234      Operand.Ex = static_cast<Stmt*>(op);
235  }
236
237  bool isTypeOperand() const { return isTypeOp; }
238  QualType getTypeOperand() const {
239    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
240    return QualType::getFromOpaquePtr(Operand.Ty);
241  }
242  Expr* getExprOperand() const {
243    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
244    return static_cast<Expr*>(Operand.Ex);
245  }
246
247  virtual SourceRange getSourceRange() const {
248    return Range;
249  }
250  static bool classof(const Stmt *T) {
251    return T->getStmtClass() == CXXTypeidExprClass;
252  }
253  static bool classof(const CXXTypeidExpr *) { return true; }
254
255  // Iterators
256  virtual child_iterator child_begin();
257  virtual child_iterator child_end();
258
259  virtual void EmitImpl(llvm::Serializer& S) const;
260  static CXXTypeidExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
261};
262
263/// CXXThisExpr - Represents the "this" expression in C++, which is a
264/// pointer to the object on which the current member function is
265/// executing (C++ [expr.prim]p3). Example:
266///
267/// @code
268/// class Foo {
269/// public:
270///   void bar();
271///   void test() { this->bar(); }
272/// };
273/// @endcode
274class CXXThisExpr : public Expr {
275  SourceLocation Loc;
276
277public:
278  CXXThisExpr(SourceLocation L, QualType Type)
279    : Expr(CXXThisExprClass, Type), Loc(L) { }
280
281  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
282
283  static bool classof(const Stmt *T) {
284    return T->getStmtClass() == CXXThisExprClass;
285  }
286  static bool classof(const CXXThisExpr *) { return true; }
287
288  // Iterators
289  virtual child_iterator child_begin();
290  virtual child_iterator child_end();
291
292  virtual void EmitImpl(llvm::Serializer& S) const;
293  static CXXThisExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
294};
295
296///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
297///  'throw' and 'throw' assignment-expression.  When
298///  assignment-expression isn't present, Op will be null.
299///
300class CXXThrowExpr : public Expr {
301  Stmt *Op;
302  SourceLocation ThrowLoc;
303public:
304  // Ty is the void type which is used as the result type of the
305  // exepression.  The l is the location of the throw keyword.  expr
306  // can by null, if the optional expression to throw isn't present.
307  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
308    Expr(CXXThrowExprClass, Ty), Op(expr), ThrowLoc(l) {}
309  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
310  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
311
312  virtual SourceRange getSourceRange() const {
313    if (getSubExpr() == 0)
314      return SourceRange(ThrowLoc, ThrowLoc);
315    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
316  }
317
318  static bool classof(const Stmt *T) {
319    return T->getStmtClass() == CXXThrowExprClass;
320  }
321  static bool classof(const CXXThrowExpr *) { return true; }
322
323  // Iterators
324  virtual child_iterator child_begin();
325  virtual child_iterator child_end();
326};
327
328/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
329/// function call argument that was created from the corresponding
330/// parameter's default argument, when the call did not explicitly
331/// supply arguments for all of the parameters.
332class CXXDefaultArgExpr : public Expr {
333  ParmVarDecl *Param;
334public:
335  // Param is the parameter whose default argument is used by this
336  // expression.
337  explicit CXXDefaultArgExpr(ParmVarDecl *param)
338    : Expr(CXXDefaultArgExprClass, param->getDefaultArg()->getType()),
339      Param(param) { }
340
341  // Retrieve the parameter that the argument was created from.
342  const ParmVarDecl *getParam() const { return Param; }
343  ParmVarDecl *getParam() { return Param; }
344
345  // Retrieve the actual argument to the function call.
346  const Expr *getExpr() const { return Param->getDefaultArg(); }
347  Expr *getExpr() { return Param->getDefaultArg(); }
348
349  virtual SourceRange getSourceRange() const {
350    // Default argument expressions have no representation in the
351    // source, so they have an empty source range.
352    return SourceRange();
353  }
354
355  static bool classof(const Stmt *T) {
356    return T->getStmtClass() == CXXDefaultArgExprClass;
357  }
358  static bool classof(const CXXDefaultArgExpr *) { return true; }
359
360  // Iterators
361  virtual child_iterator child_begin();
362  virtual child_iterator child_end();
363
364  // Serialization
365  virtual void EmitImpl(llvm::Serializer& S) const;
366  static CXXDefaultArgExpr* CreateImpl(llvm::Deserializer& D,
367                                       ASTContext& C);
368};
369
370/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
371/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
372/// x = int(0.5);
373class CXXFunctionalCastExpr : public ExplicitCastExpr {
374  SourceLocation TyBeginLoc;
375  SourceLocation RParenLoc;
376public:
377  CXXFunctionalCastExpr(QualType ty, QualType writtenTy,
378                        SourceLocation tyBeginLoc, Expr *castExpr,
379                        SourceLocation rParenLoc) :
380    ExplicitCastExpr(CXXFunctionalCastExprClass, ty, castExpr, writtenTy),
381    TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
382
383  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
384  SourceLocation getRParenLoc() const { return RParenLoc; }
385
386  virtual SourceRange getSourceRange() const {
387    return SourceRange(TyBeginLoc, RParenLoc);
388  }
389  static bool classof(const Stmt *T) {
390    return T->getStmtClass() == CXXFunctionalCastExprClass;
391  }
392  static bool classof(const CXXFunctionalCastExpr *) { return true; }
393
394  virtual void EmitImpl(llvm::Serializer& S) const;
395  static CXXFunctionalCastExpr *
396      CreateImpl(llvm::Deserializer& D, ASTContext& C);
397};
398
399/// CXXZeroInitValueExpr - [C++ 5.2.3p2]
400/// Expression "T()" which creates a value-initialized Rvalue of non-class
401/// type T.
402///
403class CXXZeroInitValueExpr : public Expr {
404  SourceLocation TyBeginLoc;
405  SourceLocation RParenLoc;
406
407public:
408  CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc,
409                       SourceLocation rParenLoc ) :
410    Expr(CXXZeroInitValueExprClass, ty),
411    TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
412
413  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
414  SourceLocation getRParenLoc() const { return RParenLoc; }
415
416  virtual SourceRange getSourceRange() const {
417    return SourceRange(TyBeginLoc, RParenLoc);
418  }
419
420  static bool classof(const Stmt *T) {
421    return T->getStmtClass() == CXXZeroInitValueExprClass;
422  }
423  static bool classof(const CXXZeroInitValueExpr *) { return true; }
424
425  // Iterators
426  virtual child_iterator child_begin();
427  virtual child_iterator child_end();
428
429  virtual void EmitImpl(llvm::Serializer& S) const;
430  static CXXZeroInitValueExpr *
431      CreateImpl(llvm::Deserializer& D, ASTContext& C);
432};
433
434/// CXXConditionDeclExpr - Condition declaration of a if/switch/while/for
435/// statement, e.g: "if (int x = f()) {...}".
436/// The main difference with DeclRefExpr is that CXXConditionDeclExpr owns the
437/// decl that it references.
438///
439class CXXConditionDeclExpr : public DeclRefExpr {
440public:
441  CXXConditionDeclExpr(SourceLocation startLoc,
442                       SourceLocation eqLoc, VarDecl *var)
443    : DeclRefExpr(CXXConditionDeclExprClass, var,
444                  var->getType().getNonReferenceType(), startLoc) {}
445
446  virtual void Destroy(ASTContext& Ctx);
447
448  SourceLocation getStartLoc() const { return getLocation(); }
449
450  VarDecl *getVarDecl() { return cast<VarDecl>(getDecl()); }
451  const VarDecl *getVarDecl() const { return cast<VarDecl>(getDecl()); }
452
453  virtual SourceRange getSourceRange() const {
454    return SourceRange(getStartLoc(), getVarDecl()->getInit()->getLocEnd());
455  }
456
457  static bool classof(const Stmt *T) {
458    return T->getStmtClass() == CXXConditionDeclExprClass;
459  }
460  static bool classof(const CXXConditionDeclExpr *) { return true; }
461
462  // Iterators
463  virtual child_iterator child_begin();
464  virtual child_iterator child_end();
465
466  // FIXME: Implement these.
467  //virtual void EmitImpl(llvm::Serializer& S) const;
468  //static CXXConditionDeclExpr *
469  //    CreateImpl(llvm::Deserializer& D, ASTContext& C);
470};
471
472/// CXXNewExpr - A new expression for memory allocation and constructor calls,
473/// e.g: "new CXXNewExpr(foo)".
474class CXXNewExpr : public Expr {
475  // Was the usage ::new, i.e. is the global new to be used?
476  bool GlobalNew : 1;
477  // Was the form (type-id) used? Otherwise, it was new-type-id.
478  bool ParenTypeId : 1;
479  // Is there an initializer? If not, built-ins are uninitialized, else they're
480  // value-initialized.
481  bool Initializer : 1;
482  // Do we allocate an array? If so, the first SubExpr is the size expression.
483  bool Array : 1;
484  // The number of placement new arguments.
485  unsigned NumPlacementArgs : 14;
486  // The number of constructor arguments. This may be 1 even for non-class
487  // types; use the pseudo copy constructor.
488  unsigned NumConstructorArgs : 14;
489  // Contains an optional array size expression, any number of optional
490  // placement arguments, and any number of optional constructor arguments,
491  // in that order.
492  Stmt **SubExprs;
493  // Points to the allocation function used.
494  FunctionDecl *OperatorNew;
495  // Points to the deallocation function used in case of error. May be null.
496  FunctionDecl *OperatorDelete;
497  // Points to the constructor used. Cannot be null if AllocType is a record;
498  // it would still point at the default constructor (even an implicit one).
499  // Must be null for all other types.
500  CXXConstructorDecl *Constructor;
501
502  SourceLocation StartLoc;
503  SourceLocation EndLoc;
504
505  // Deserialization constructor
506  CXXNewExpr(QualType ty, bool globalNew, bool parenTypeId, bool initializer,
507             bool array, unsigned numPlaceArgs, unsigned numConsArgs,
508             Stmt **subExprs, FunctionDecl *operatorNew,
509             FunctionDecl *operatorDelete, CXXConstructorDecl *constructor,
510             SourceLocation startLoc, SourceLocation endLoc)
511    : Expr(CXXNewExprClass, ty), GlobalNew(globalNew), ParenTypeId(parenTypeId),
512      Initializer(initializer), Array(array), NumPlacementArgs(numPlaceArgs),
513      NumConstructorArgs(numConsArgs), SubExprs(subExprs),
514      OperatorNew(operatorNew), OperatorDelete(operatorDelete),
515      Constructor(constructor), StartLoc(startLoc), EndLoc(endLoc)
516  { }
517public:
518  CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, Expr **placementArgs,
519             unsigned numPlaceArgs, bool ParenTypeId, Expr *arraySize,
520             CXXConstructorDecl *constructor, bool initializer,
521             Expr **constructorArgs, unsigned numConsArgs,
522             FunctionDecl *operatorDelete, QualType ty,
523             SourceLocation startLoc, SourceLocation endLoc);
524  ~CXXNewExpr() {
525    delete[] SubExprs;
526  }
527
528  QualType getAllocatedType() const {
529    assert(getType()->isPointerType());
530    return getType()->getAsPointerType()->getPointeeType();
531  }
532
533  FunctionDecl *getOperatorNew() const { return OperatorNew; }
534  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
535  CXXConstructorDecl *getConstructor() const { return Constructor; }
536
537  bool isArray() const { return Array; }
538  Expr *getArraySize() {
539    return Array ? cast<Expr>(SubExprs[0]) : 0;
540  }
541  const Expr *getArraySize() const {
542    return Array ? cast<Expr>(SubExprs[0]) : 0;
543  }
544
545  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
546  Expr *getPlacementArg(unsigned i) {
547    assert(i < NumPlacementArgs && "Index out of range");
548    return cast<Expr>(SubExprs[Array + i]);
549  }
550  const Expr *getPlacementArg(unsigned i) const {
551    assert(i < NumPlacementArgs && "Index out of range");
552    return cast<Expr>(SubExprs[Array + i]);
553  }
554
555  bool isGlobalNew() const { return GlobalNew; }
556  bool isParenTypeId() const { return ParenTypeId; }
557  bool hasInitializer() const { return Initializer; }
558
559  unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
560  Expr *getConstructorArg(unsigned i) {
561    assert(i < NumConstructorArgs && "Index out of range");
562    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
563  }
564  const Expr *getConstructorArg(unsigned i) const {
565    assert(i < NumConstructorArgs && "Index out of range");
566    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
567  }
568
569  typedef ExprIterator arg_iterator;
570  typedef ConstExprIterator const_arg_iterator;
571
572  arg_iterator placement_arg_begin() {
573    return SubExprs + Array;
574  }
575  arg_iterator placement_arg_end() {
576    return SubExprs + Array + getNumPlacementArgs();
577  }
578  const_arg_iterator placement_arg_begin() const {
579    return SubExprs + Array;
580  }
581  const_arg_iterator placement_arg_end() const {
582    return SubExprs + Array + getNumPlacementArgs();
583  }
584
585  arg_iterator constructor_arg_begin() {
586    return SubExprs + Array + getNumPlacementArgs();
587  }
588  arg_iterator constructor_arg_end() {
589    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
590  }
591  const_arg_iterator constructor_arg_begin() const {
592    return SubExprs + Array + getNumPlacementArgs();
593  }
594  const_arg_iterator constructor_arg_end() const {
595    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
596  }
597
598  virtual SourceRange getSourceRange() const {
599    return SourceRange(StartLoc, EndLoc);
600  }
601
602  static bool classof(const Stmt *T) {
603    return T->getStmtClass() == CXXNewExprClass;
604  }
605  static bool classof(const CXXNewExpr *) { return true; }
606
607  // Iterators
608  virtual child_iterator child_begin();
609  virtual child_iterator child_end();
610
611  virtual void EmitImpl(llvm::Serializer& S) const;
612  static CXXNewExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
613};
614
615/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
616/// calls, e.g. "delete[] pArray".
617class CXXDeleteExpr : public Expr {
618  // Is this a forced global delete, i.e. "::delete"?
619  bool GlobalDelete : 1;
620  // Is this the array form of delete, i.e. "delete[]"?
621  bool ArrayForm : 1;
622  // Points to the operator delete overload that is used. Could be a member.
623  FunctionDecl *OperatorDelete;
624  // The pointer expression to be deleted.
625  Stmt *Argument;
626  // Location of the expression.
627  SourceLocation Loc;
628public:
629  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
630                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
631    : Expr(CXXDeleteExprClass, ty), GlobalDelete(globalDelete),
632      ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg),
633      Loc(loc) { }
634
635  bool isGlobalDelete() const { return GlobalDelete; }
636  bool isArrayForm() const { return ArrayForm; }
637
638  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
639
640  Expr *getArgument() { return cast<Expr>(Argument); }
641  const Expr *getArgument() const { return cast<Expr>(Argument); }
642
643  virtual SourceRange getSourceRange() const {
644    return SourceRange(Loc, Argument->getLocEnd());
645  }
646
647  static bool classof(const Stmt *T) {
648    return T->getStmtClass() == CXXDeleteExprClass;
649  }
650  static bool classof(const CXXDeleteExpr *) { return true; }
651
652  // Iterators
653  virtual child_iterator child_begin();
654  virtual child_iterator child_end();
655
656  virtual void EmitImpl(llvm::Serializer& S) const;
657  static CXXDeleteExpr * CreateImpl(llvm::Deserializer& D, ASTContext& C);
658};
659
660/// CXXDependentNameExpr - Represents a dependent name in C++ for
661/// which we could not locate any definition. These names can only
662/// occur as in the example below, with an unqualified call to a
663/// function name whose arguments are dependent.
664/// @code
665/// template<typename T> void f(T x) {
666///   g(x); // g is a dependent name.
667/// }
668/// @endcode
669class CXXDependentNameExpr : public Expr {
670  /// Name - The name that was present in the source code.
671  IdentifierInfo *Name;
672
673  /// Loc - The location
674  SourceLocation Loc;
675
676public:
677  CXXDependentNameExpr(IdentifierInfo *N, QualType T, SourceLocation L)
678    : Expr(CXXDependentNameExprClass, T, true, true), Name(N), Loc(L) { }
679
680  /// getName - Retrieves the name that occurred in the source code.
681  IdentifierInfo *getName() const { return Name; }
682
683  /// getLocation - Retrieves the location in the source code where
684  /// the name occurred.
685  SourceLocation getLocation() const { return Loc; }
686
687  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
688
689  static bool classof(const Stmt *T) {
690    return T->getStmtClass() == CXXDependentNameExprClass;
691  }
692  static bool classof(const CXXDependentNameExpr *) { return true; }
693
694  // Iterators
695  virtual child_iterator child_begin();
696  virtual child_iterator child_end();
697
698  virtual void EmitImpl(llvm::Serializer& S) const;
699  static CXXDependentNameExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C);
700};
701
702}  // end namespace clang
703
704#endif
705