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