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