ExprCXX.h revision bcb11d01c034f967503bd98f28bdf458c1ab8001
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, const CastInfo &info, Expr *op,
117                   QualType writtenTy, SourceLocation l)
118    : ExplicitCastExpr(SC, ty, info, 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, const CastInfo &info, Expr *op,
153                    QualType writtenTy, SourceLocation l)
154    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, info, 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, Expr *op, QualType writtenTy,
189                         SourceLocation l)
190    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, CK_BitCast, 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 { return SourceRange(); }
470
471  // Implement isa/cast/dyncast/etc.
472  static bool classof(const Stmt *T) {
473    return T->getStmtClass() == CXXBindTemporaryExprClass;
474  }
475  static bool classof(const CXXBindTemporaryExpr *) { return true; }
476
477  // Iterators
478  virtual child_iterator child_begin();
479  virtual child_iterator child_end();
480};
481
482/// CXXConstructExpr - Represents a call to a C++ constructor.
483class CXXConstructExpr : public Expr {
484  CXXConstructorDecl *Constructor;
485
486  bool Elidable;
487
488  Stmt **Args;
489  unsigned NumArgs;
490
491protected:
492  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
493                   CXXConstructorDecl *d, bool elidable,
494                   Expr **args, unsigned numargs);
495  ~CXXConstructExpr() { }
496
497  virtual void DoDestroy(ASTContext &C);
498
499public:
500  static CXXConstructExpr *Create(ASTContext &C, QualType T,
501                                  CXXConstructorDecl *D, bool Elidable,
502                                  Expr **Args, unsigned NumArgs);
503
504
505  CXXConstructorDecl* getConstructor() const { return Constructor; }
506
507  /// \brief Whether this construction is elidable.
508  bool isElidable() const { return Elidable; }
509
510  typedef ExprIterator arg_iterator;
511  typedef ConstExprIterator const_arg_iterator;
512
513  arg_iterator arg_begin() { return Args; }
514  arg_iterator arg_end() { return Args + NumArgs; }
515  const_arg_iterator arg_begin() const { return Args; }
516  const_arg_iterator arg_end() const { return Args + NumArgs; }
517
518  unsigned getNumArgs() const { return NumArgs; }
519
520  /// getArg - Return the specified argument.
521  Expr *getArg(unsigned Arg) {
522    assert(Arg < NumArgs && "Arg access out of range!");
523    return cast<Expr>(Args[Arg]);
524  }
525  const Expr *getArg(unsigned Arg) const {
526    assert(Arg < NumArgs && "Arg access out of range!");
527    return cast<Expr>(Args[Arg]);
528  }
529
530  /// setArg - Set the specified argument.
531  void setArg(unsigned Arg, Expr *ArgExpr) {
532    assert(Arg < NumArgs && "Arg access out of range!");
533    Args[Arg] = ArgExpr;
534  }
535
536  virtual SourceRange getSourceRange() const { return SourceRange(); }
537
538  static bool classof(const Stmt *T) {
539    return T->getStmtClass() == CXXConstructExprClass ||
540      T->getStmtClass() == CXXTemporaryObjectExprClass;
541  }
542  static bool classof(const CXXConstructExpr *) { return true; }
543
544  // Iterators
545  virtual child_iterator child_begin();
546  virtual child_iterator child_end();
547};
548
549/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
550/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
551/// x = int(0.5);
552class CXXFunctionalCastExpr : public ExplicitCastExpr {
553  CXXMethodDecl *TypeConversionMethod;
554  SourceLocation TyBeginLoc;
555  SourceLocation RParenLoc;
556public:
557  CXXFunctionalCastExpr(QualType ty, QualType writtenTy,
558                        SourceLocation tyBeginLoc, CastKind kind,
559                        Expr *castExpr, CXXMethodDecl *typeConversionMethod,
560                        SourceLocation rParenLoc) :
561    ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr, writtenTy),
562    TypeConversionMethod(typeConversionMethod),
563    TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
564
565  CXXMethodDecl *getTypeConversionMethod() const
566  { return TypeConversionMethod; }
567  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
568  SourceLocation getRParenLoc() const { return RParenLoc; }
569
570  virtual SourceRange getSourceRange() const {
571    return SourceRange(TyBeginLoc, RParenLoc);
572  }
573  static bool classof(const Stmt *T) {
574    return T->getStmtClass() == CXXFunctionalCastExprClass;
575  }
576  static bool classof(const CXXFunctionalCastExpr *) { return true; }
577};
578
579/// @brief Represents a C++ functional cast expression that builds a
580/// temporary object.
581///
582/// This expression type represents a C++ "functional" cast
583/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
584/// constructor to build a temporary object. If N == 0 but no
585/// constructor will be called (because the functional cast is
586/// performing a value-initialized an object whose class type has no
587/// user-declared constructors), CXXZeroInitValueExpr will represent
588/// the functional cast. Finally, with N == 1 arguments the functional
589/// cast expression will be represented by CXXFunctionalCastExpr.
590/// Example:
591/// @code
592/// struct X { X(int, float); }
593///
594/// X create_X() {
595///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
596/// };
597/// @endcode
598class CXXTemporaryObjectExpr : public CXXConstructExpr {
599  SourceLocation TyBeginLoc;
600  SourceLocation RParenLoc;
601
602public:
603  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
604                         QualType writtenTy, SourceLocation tyBeginLoc,
605                         Expr **Args,unsigned NumArgs,
606                         SourceLocation rParenLoc);
607
608  ~CXXTemporaryObjectExpr() { }
609
610  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
611  SourceLocation getRParenLoc() const { return RParenLoc; }
612
613  virtual SourceRange getSourceRange() const {
614    return SourceRange(TyBeginLoc, RParenLoc);
615  }
616  static bool classof(const Stmt *T) {
617    return T->getStmtClass() == CXXTemporaryObjectExprClass;
618  }
619  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
620};
621
622/// CXXZeroInitValueExpr - [C++ 5.2.3p2]
623/// Expression "T()" which creates a value-initialized rvalue of type
624/// T, which is either a non-class type or a class type without any
625/// user-defined constructors.
626///
627class CXXZeroInitValueExpr : public Expr {
628  SourceLocation TyBeginLoc;
629  SourceLocation RParenLoc;
630
631public:
632  CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc,
633                       SourceLocation rParenLoc ) :
634    Expr(CXXZeroInitValueExprClass, ty, false, false),
635    TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
636
637  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
638  SourceLocation getRParenLoc() const { return RParenLoc; }
639
640  /// @brief Whether this initialization expression was
641  /// implicitly-generated.
642  bool isImplicit() const {
643    return TyBeginLoc.isInvalid() && RParenLoc.isInvalid();
644  }
645
646  virtual SourceRange getSourceRange() const {
647    return SourceRange(TyBeginLoc, RParenLoc);
648  }
649
650  static bool classof(const Stmt *T) {
651    return T->getStmtClass() == CXXZeroInitValueExprClass;
652  }
653  static bool classof(const CXXZeroInitValueExpr *) { return true; }
654
655  // Iterators
656  virtual child_iterator child_begin();
657  virtual child_iterator child_end();
658};
659
660/// CXXConditionDeclExpr - Condition declaration of a if/switch/while/for
661/// statement, e.g: "if (int x = f()) {...}".
662/// The main difference with DeclRefExpr is that CXXConditionDeclExpr owns the
663/// decl that it references.
664///
665class CXXConditionDeclExpr : public DeclRefExpr {
666public:
667  CXXConditionDeclExpr(SourceLocation startLoc,
668                       SourceLocation eqLoc, VarDecl *var)
669    : DeclRefExpr(CXXConditionDeclExprClass, var,
670                  var->getType().getNonReferenceType(), startLoc,
671                  var->getType()->isDependentType(),
672                  /*FIXME:integral constant?*/
673                    var->getType()->isDependentType()) {}
674
675  SourceLocation getStartLoc() const { return getLocation(); }
676
677  VarDecl *getVarDecl() { return cast<VarDecl>(getDecl()); }
678  const VarDecl *getVarDecl() const { return cast<VarDecl>(getDecl()); }
679
680  virtual SourceRange getSourceRange() const {
681    return SourceRange(getStartLoc(), getVarDecl()->getInit()->getLocEnd());
682  }
683
684  static bool classof(const Stmt *T) {
685    return T->getStmtClass() == CXXConditionDeclExprClass;
686  }
687  static bool classof(const CXXConditionDeclExpr *) { return true; }
688
689  // Iterators
690  virtual child_iterator child_begin();
691  virtual child_iterator child_end();
692};
693
694/// CXXNewExpr - A new expression for memory allocation and constructor calls,
695/// e.g: "new CXXNewExpr(foo)".
696class CXXNewExpr : public Expr {
697  // Was the usage ::new, i.e. is the global new to be used?
698  bool GlobalNew : 1;
699  // Was the form (type-id) used? Otherwise, it was new-type-id.
700  bool ParenTypeId : 1;
701  // Is there an initializer? If not, built-ins are uninitialized, else they're
702  // value-initialized.
703  bool Initializer : 1;
704  // Do we allocate an array? If so, the first SubExpr is the size expression.
705  bool Array : 1;
706  // The number of placement new arguments.
707  unsigned NumPlacementArgs : 14;
708  // The number of constructor arguments. This may be 1 even for non-class
709  // types; use the pseudo copy constructor.
710  unsigned NumConstructorArgs : 14;
711  // Contains an optional array size expression, any number of optional
712  // placement arguments, and any number of optional constructor arguments,
713  // in that order.
714  Stmt **SubExprs;
715  // Points to the allocation function used.
716  FunctionDecl *OperatorNew;
717  // Points to the deallocation function used in case of error. May be null.
718  FunctionDecl *OperatorDelete;
719  // Points to the constructor used. Cannot be null if AllocType is a record;
720  // it would still point at the default constructor (even an implicit one).
721  // Must be null for all other types.
722  CXXConstructorDecl *Constructor;
723
724  SourceLocation StartLoc;
725  SourceLocation EndLoc;
726
727public:
728  CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, Expr **placementArgs,
729             unsigned numPlaceArgs, bool ParenTypeId, Expr *arraySize,
730             CXXConstructorDecl *constructor, bool initializer,
731             Expr **constructorArgs, unsigned numConsArgs,
732             FunctionDecl *operatorDelete, QualType ty,
733             SourceLocation startLoc, SourceLocation endLoc);
734  ~CXXNewExpr() {
735    delete[] SubExprs;
736  }
737
738  QualType getAllocatedType() const {
739    assert(getType()->isPointerType());
740    return getType()->getAs<PointerType>()->getPointeeType();
741  }
742
743  FunctionDecl *getOperatorNew() const { return OperatorNew; }
744  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
745  CXXConstructorDecl *getConstructor() const { return Constructor; }
746
747  bool isArray() const { return Array; }
748  Expr *getArraySize() {
749    return Array ? cast<Expr>(SubExprs[0]) : 0;
750  }
751  const Expr *getArraySize() const {
752    return Array ? cast<Expr>(SubExprs[0]) : 0;
753  }
754
755  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
756  Expr *getPlacementArg(unsigned i) {
757    assert(i < NumPlacementArgs && "Index out of range");
758    return cast<Expr>(SubExprs[Array + i]);
759  }
760  const Expr *getPlacementArg(unsigned i) const {
761    assert(i < NumPlacementArgs && "Index out of range");
762    return cast<Expr>(SubExprs[Array + i]);
763  }
764
765  bool isGlobalNew() const { return GlobalNew; }
766  bool isParenTypeId() const { return ParenTypeId; }
767  bool hasInitializer() const { return Initializer; }
768
769  unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
770  Expr *getConstructorArg(unsigned i) {
771    assert(i < NumConstructorArgs && "Index out of range");
772    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
773  }
774  const Expr *getConstructorArg(unsigned i) const {
775    assert(i < NumConstructorArgs && "Index out of range");
776    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
777  }
778
779  typedef ExprIterator arg_iterator;
780  typedef ConstExprIterator const_arg_iterator;
781
782  arg_iterator placement_arg_begin() {
783    return SubExprs + Array;
784  }
785  arg_iterator placement_arg_end() {
786    return SubExprs + Array + getNumPlacementArgs();
787  }
788  const_arg_iterator placement_arg_begin() const {
789    return SubExprs + Array;
790  }
791  const_arg_iterator placement_arg_end() const {
792    return SubExprs + Array + getNumPlacementArgs();
793  }
794
795  arg_iterator constructor_arg_begin() {
796    return SubExprs + Array + getNumPlacementArgs();
797  }
798  arg_iterator constructor_arg_end() {
799    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
800  }
801  const_arg_iterator constructor_arg_begin() const {
802    return SubExprs + Array + getNumPlacementArgs();
803  }
804  const_arg_iterator constructor_arg_end() const {
805    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
806  }
807
808  virtual SourceRange getSourceRange() const {
809    return SourceRange(StartLoc, EndLoc);
810  }
811
812  static bool classof(const Stmt *T) {
813    return T->getStmtClass() == CXXNewExprClass;
814  }
815  static bool classof(const CXXNewExpr *) { return true; }
816
817  // Iterators
818  virtual child_iterator child_begin();
819  virtual child_iterator child_end();
820};
821
822/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
823/// calls, e.g. "delete[] pArray".
824class CXXDeleteExpr : public Expr {
825  // Is this a forced global delete, i.e. "::delete"?
826  bool GlobalDelete : 1;
827  // Is this the array form of delete, i.e. "delete[]"?
828  bool ArrayForm : 1;
829  // Points to the operator delete overload that is used. Could be a member.
830  FunctionDecl *OperatorDelete;
831  // The pointer expression to be deleted.
832  Stmt *Argument;
833  // Location of the expression.
834  SourceLocation Loc;
835public:
836  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
837                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
838    : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete),
839      ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg),
840      Loc(loc) { }
841
842  bool isGlobalDelete() const { return GlobalDelete; }
843  bool isArrayForm() const { return ArrayForm; }
844
845  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
846
847  Expr *getArgument() { return cast<Expr>(Argument); }
848  const Expr *getArgument() const { return cast<Expr>(Argument); }
849
850  virtual SourceRange getSourceRange() const {
851    return SourceRange(Loc, Argument->getLocEnd());
852  }
853
854  static bool classof(const Stmt *T) {
855    return T->getStmtClass() == CXXDeleteExprClass;
856  }
857  static bool classof(const CXXDeleteExpr *) { return true; }
858
859  // Iterators
860  virtual child_iterator child_begin();
861  virtual child_iterator child_end();
862};
863
864/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
865///
866/// Example:
867///
868/// \code
869/// template<typename T>
870/// void destroy(T* ptr) {
871///   ptr->~T();
872/// }
873/// \endcode
874///
875/// When the template is parsed, the expression \c ptr->~T will be stored as
876/// a member reference expression. If it then instantiated with a scalar type
877/// as a template argument for T, the resulting expression will be a
878/// pseudo-destructor expression.
879class CXXPseudoDestructorExpr : public Expr {
880  /// \brief The base expression (that is being destroyed).
881  Stmt *Base;
882
883  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
884  /// period ('.').
885  bool IsArrow : 1;
886
887  /// \brief The location of the '.' or '->' operator.
888  SourceLocation OperatorLoc;
889
890  /// \brief The nested-name-specifier that follows the operator, if present.
891  NestedNameSpecifier *Qualifier;
892
893  /// \brief The source range that covers the nested-name-specifier, if
894  /// present.
895  SourceRange QualifierRange;
896
897  /// \brief The type being destroyed.
898  QualType DestroyedType;
899
900  /// \brief The location of the type after the '~'.
901  SourceLocation DestroyedTypeLoc;
902
903public:
904  CXXPseudoDestructorExpr(ASTContext &Context,
905                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
906                          NestedNameSpecifier *Qualifier,
907                          SourceRange QualifierRange,
908                          QualType DestroyedType,
909                          SourceLocation DestroyedTypeLoc)
910    : Expr(CXXPseudoDestructorExprClass,
911           Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
912                                                          false, 0)),
913           /*isTypeDependent=*/false,
914           /*isValueDependent=*/Base->isValueDependent()),
915      Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
916      OperatorLoc(OperatorLoc), Qualifier(Qualifier),
917      QualifierRange(QualifierRange), DestroyedType(DestroyedType),
918      DestroyedTypeLoc(DestroyedTypeLoc) { }
919
920  void setBase(Expr *E) { Base = E; }
921  Expr *getBase() const { return cast<Expr>(Base); }
922
923  /// \brief Determines whether this member expression actually had
924  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
925  /// x->Base::foo.
926  bool hasQualifier() const { return Qualifier != 0; }
927
928  /// \brief If the member name was qualified, retrieves the source range of
929  /// the nested-name-specifier that precedes the member name. Otherwise,
930  /// returns an empty source range.
931  SourceRange getQualifierRange() const { return QualifierRange; }
932
933  /// \brief If the member name was qualified, retrieves the
934  /// nested-name-specifier that precedes the member name. Otherwise, returns
935  /// NULL.
936  NestedNameSpecifier *getQualifier() const { return Qualifier; }
937
938  /// \brief Determine whether this pseudo-destructor expression was written
939  /// using an '->' (otherwise, it used a '.').
940  bool isArrow() const { return IsArrow; }
941  void setArrow(bool A) { IsArrow = A; }
942
943  /// \brief Retrieve the location of the '.' or '->' operator.
944  SourceLocation getOperatorLoc() const { return OperatorLoc; }
945
946  /// \brief Retrieve the type that is being destroyed.
947  QualType getDestroyedType() const { return DestroyedType; }
948
949  /// \brief Retrieve the location of the type being destroyed.
950  SourceLocation getDestroyedTypeLoc() const { return DestroyedTypeLoc; }
951
952  virtual SourceRange getSourceRange() const {
953    return SourceRange(Base->getLocStart(), DestroyedTypeLoc);
954  }
955
956  static bool classof(const Stmt *T) {
957    return T->getStmtClass() == CXXPseudoDestructorExprClass;
958  }
959  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
960
961  // Iterators
962  virtual child_iterator child_begin();
963  virtual child_iterator child_end();
964};
965
966/// \brief Represents the name of a function that has not been
967/// resolved to any declaration.
968///
969/// Unresolved function names occur when a function name is
970/// encountered prior to an open parentheses ('(') in a C++ function
971/// call, and the function name itself did not resolve to a
972/// declaration. These function names can only be resolved when they
973/// form the postfix-expression of a function call, so that
974/// argument-dependent lookup finds declarations corresponding to
975/// these functions.
976
977/// @code
978/// template<typename T> void f(T x) {
979///   g(x); // g is an unresolved function name (that is also a dependent name)
980/// }
981/// @endcode
982class UnresolvedFunctionNameExpr : public Expr {
983  /// The name that was present in the source
984  DeclarationName Name;
985
986  /// The location of this name in the source code
987  SourceLocation Loc;
988
989public:
990  UnresolvedFunctionNameExpr(DeclarationName N, QualType T, SourceLocation L)
991    : Expr(UnresolvedFunctionNameExprClass, T, false, false), Name(N), Loc(L) { }
992
993  /// \brief Retrieves the name that occurred in the source code.
994  DeclarationName getName() const { return Name; }
995
996  /// getLocation - Retrieves the location in the source code where
997  /// the name occurred.
998  SourceLocation getLocation() const { return Loc; }
999
1000  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
1001
1002  static bool classof(const Stmt *T) {
1003    return T->getStmtClass() == UnresolvedFunctionNameExprClass;
1004  }
1005  static bool classof(const UnresolvedFunctionNameExpr *) { return true; }
1006
1007  // Iterators
1008  virtual child_iterator child_begin();
1009  virtual child_iterator child_end();
1010};
1011
1012/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1013/// implementation of TR1/C++0x type trait templates.
1014/// Example:
1015/// __is_pod(int) == true
1016/// __is_enum(std::string) == false
1017class UnaryTypeTraitExpr : public Expr {
1018  /// UTT - The trait.
1019  UnaryTypeTrait UTT;
1020
1021  /// Loc - The location of the type trait keyword.
1022  SourceLocation Loc;
1023
1024  /// RParen - The location of the closing paren.
1025  SourceLocation RParen;
1026
1027  /// QueriedType - The type we're testing.
1028  QualType QueriedType;
1029
1030public:
1031  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried,
1032                     SourceLocation rparen, QualType ty)
1033    : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
1034      UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
1035
1036  virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1037
1038  UnaryTypeTrait getTrait() const { return UTT; }
1039
1040  QualType getQueriedType() const { return QueriedType; }
1041
1042  bool EvaluateTrait(ASTContext&) const;
1043
1044  static bool classof(const Stmt *T) {
1045    return T->getStmtClass() == UnaryTypeTraitExprClass;
1046  }
1047  static bool classof(const UnaryTypeTraitExpr *) { return true; }
1048
1049  // Iterators
1050  virtual child_iterator child_begin();
1051  virtual child_iterator child_end();
1052};
1053
1054/// QualifiedDeclRefExpr - A reference to a declared variable,
1055/// function, enum, etc., that includes a qualification, e.g.,
1056/// "N::foo".
1057class QualifiedDeclRefExpr : public DeclRefExpr {
1058  /// QualifierRange - The source range that covers the
1059  /// nested-name-specifier.
1060  SourceRange QualifierRange;
1061
1062  /// \brief The nested-name-specifier that qualifies this declaration
1063  /// name.
1064  NestedNameSpecifier *NNS;
1065
1066public:
1067  QualifiedDeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD,
1068                       bool VD, SourceRange R, NestedNameSpecifier *NNS)
1069    : DeclRefExpr(QualifiedDeclRefExprClass, d, t, l, TD, VD),
1070      QualifierRange(R), NNS(NNS) { }
1071
1072  /// \brief Retrieve the source range of the nested-name-specifier.
1073  SourceRange getQualifierRange() const { return QualifierRange; }
1074
1075  /// \brief Retrieve the nested-name-specifier that qualifies this
1076  /// declaration.
1077  NestedNameSpecifier *getQualifier() const { return NNS; }
1078
1079  virtual SourceRange getSourceRange() const {
1080    return SourceRange(QualifierRange.getBegin(), getLocation());
1081  }
1082
1083  static bool classof(const Stmt *T) {
1084    return T->getStmtClass() == QualifiedDeclRefExprClass;
1085  }
1086  static bool classof(const QualifiedDeclRefExpr *) { return true; }
1087};
1088
1089/// \brief A qualified reference to a name whose declaration cannot
1090/// yet be resolved.
1091///
1092/// UnresolvedDeclRefExpr is similar to QualifiedDeclRefExpr in that
1093/// it expresses a qualified reference to a declaration such as
1094/// X<T>::value. The difference, however, is that an
1095/// UnresolvedDeclRefExpr node is used only within C++ templates when
1096/// the qualification (e.g., X<T>::) refers to a dependent type. In
1097/// this case, X<T>::value cannot resolve to a declaration because the
1098/// declaration will differ from on instantiation of X<T> to the
1099/// next. Therefore, UnresolvedDeclRefExpr keeps track of the
1100/// qualifier (X<T>::) and the name of the entity being referenced
1101/// ("value"). Such expressions will instantiate to
1102/// QualifiedDeclRefExprs.
1103class UnresolvedDeclRefExpr : public Expr {
1104  /// The name of the entity we will be referencing.
1105  DeclarationName Name;
1106
1107  /// Location of the name of the declaration we're referencing.
1108  SourceLocation Loc;
1109
1110  /// QualifierRange - The source range that covers the
1111  /// nested-name-specifier.
1112  SourceRange QualifierRange;
1113
1114  /// \brief The nested-name-specifier that qualifies this unresolved
1115  /// declaration name.
1116  NestedNameSpecifier *NNS;
1117
1118  /// \brief Whether this expr is an address of (&) operand.
1119  bool IsAddressOfOperand;
1120
1121public:
1122  UnresolvedDeclRefExpr(DeclarationName N, QualType T, SourceLocation L,
1123                        SourceRange R, NestedNameSpecifier *NNS,
1124                        bool IsAddressOfOperand)
1125    : Expr(UnresolvedDeclRefExprClass, T, true, true),
1126      Name(N), Loc(L), QualifierRange(R), NNS(NNS),
1127      IsAddressOfOperand(IsAddressOfOperand) { }
1128
1129  /// \brief Retrieve the name that this expression refers to.
1130  DeclarationName getDeclName() const { return Name; }
1131
1132  /// \brief Retrieve the location of the name within the expression.
1133  SourceLocation getLocation() const { return Loc; }
1134
1135  /// \brief Retrieve the source range of the nested-name-specifier.
1136  SourceRange getQualifierRange() const { return QualifierRange; }
1137
1138  /// \brief Retrieve the nested-name-specifier that qualifies this
1139  /// declaration.
1140  NestedNameSpecifier *getQualifier() const { return NNS; }
1141
1142  /// \brief Retrieve whether this is an address of (&) operand.
1143
1144  bool isAddressOfOperand() const { return IsAddressOfOperand; }
1145  virtual SourceRange getSourceRange() const {
1146    return SourceRange(QualifierRange.getBegin(), getLocation());
1147  }
1148
1149  static bool classof(const Stmt *T) {
1150    return T->getStmtClass() == UnresolvedDeclRefExprClass;
1151  }
1152  static bool classof(const UnresolvedDeclRefExpr *) { return true; }
1153
1154  virtual StmtIterator child_begin();
1155  virtual StmtIterator child_end();
1156};
1157
1158/// \brief An expression that refers to a C++ template-id, such as
1159/// @c isa<FunctionDecl>.
1160class TemplateIdRefExpr : public Expr {
1161  /// \brief If this template-id was qualified-id, e.g., @c std::sort<int>,
1162  /// this nested name specifier contains the @c std::.
1163  NestedNameSpecifier *Qualifier;
1164
1165  /// \brief If this template-id was a qualified-id, e.g., @c std::sort<int>,
1166  /// this covers the source code range of the @c std::.
1167  SourceRange QualifierRange;
1168
1169  /// \brief The actual template to which this template-id refers.
1170  TemplateName Template;
1171
1172  /// \brief The source location of the template name.
1173  SourceLocation TemplateNameLoc;
1174
1175  /// \brief The source location of the left angle bracket ('<');
1176  SourceLocation LAngleLoc;
1177
1178  /// \brief The source location of the right angle bracket ('>');
1179  SourceLocation RAngleLoc;
1180
1181  /// \brief The number of template arguments in TemplateArgs.
1182  unsigned NumTemplateArgs;
1183
1184  TemplateIdRefExpr(QualType T,
1185                    NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
1186                    TemplateName Template, SourceLocation TemplateNameLoc,
1187                    SourceLocation LAngleLoc,
1188                    const TemplateArgument *TemplateArgs,
1189                    unsigned NumTemplateArgs,
1190                    SourceLocation RAngleLoc);
1191
1192  virtual void DoDestroy(ASTContext &Context);
1193
1194public:
1195  static TemplateIdRefExpr *
1196  Create(ASTContext &Context, QualType T,
1197         NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
1198         TemplateName Template, SourceLocation TemplateNameLoc,
1199         SourceLocation LAngleLoc, const TemplateArgument *TemplateArgs,
1200         unsigned NumTemplateArgs, SourceLocation RAngleLoc);
1201
1202  /// \brief Retrieve the nested name specifier used to qualify the name of
1203  /// this template-id, e.g., the "std::sort" in @c std::sort<int>, or NULL
1204  /// if this template-id was an unqualified-id.
1205  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1206
1207  /// \brief Retrieve the source range describing the nested name specifier
1208  /// used to qualified the name of this template-id, if the name was qualified.
1209  SourceRange getQualifierRange() const { return QualifierRange; }
1210
1211  /// \brief Retrieve the name of the template referenced, e.g., "sort" in
1212  /// @c std::sort<int>;
1213  TemplateName getTemplateName() const { return Template; }
1214
1215  /// \brief Retrieve the location of the name of the template referenced, e.g.,
1216  /// the location of "sort" in @c std::sort<int>.
1217  SourceLocation getTemplateNameLoc() const { return TemplateNameLoc; }
1218
1219  /// \brief Retrieve the location of the left angle bracket following the
1220  /// template name ('<').
1221  SourceLocation getLAngleLoc() const { return LAngleLoc; }
1222
1223  /// \brief Retrieve the template arguments provided as part of this
1224  /// template-id.
1225  const TemplateArgument *getTemplateArgs() const {
1226    return reinterpret_cast<const TemplateArgument *>(this + 1);
1227  }
1228
1229  /// \brief Retrieve the number of template arguments provided as part of this
1230  /// template-id.
1231  unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
1232
1233  /// \brief Retrieve the location of the right angle bracket following the
1234  /// template arguments ('>').
1235  SourceLocation getRAngleLoc() const { return RAngleLoc; }
1236
1237  virtual SourceRange getSourceRange() const {
1238    return SourceRange(Qualifier? QualifierRange.getBegin() : TemplateNameLoc,
1239                       RAngleLoc);
1240  }
1241
1242  // Iterators
1243  virtual child_iterator child_begin();
1244  virtual child_iterator child_end();
1245
1246  static bool classof(const Stmt *T) {
1247    return T->getStmtClass() == TemplateIdRefExprClass;
1248  }
1249  static bool classof(const TemplateIdRefExpr *) { return true; }
1250};
1251
1252class CXXExprWithTemporaries : public Expr {
1253  Stmt *SubExpr;
1254
1255  CXXTemporary **Temps;
1256  unsigned NumTemps;
1257
1258  bool ShouldDestroyTemps;
1259
1260  CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps,
1261                         unsigned NumTemps, bool ShouldDestroyTemps);
1262  ~CXXExprWithTemporaries();
1263
1264protected:
1265  virtual void DoDestroy(ASTContext &C);
1266
1267public:
1268  static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
1269                                        CXXTemporary **Temps, unsigned NumTemps,
1270                                        bool ShouldDestroyTemporaries);
1271
1272  unsigned getNumTemporaries() const { return NumTemps; }
1273  CXXTemporary *getTemporary(unsigned i) {
1274    assert(i < NumTemps && "Index out of range");
1275    return Temps[i];
1276  }
1277  const CXXTemporary *getTemporary(unsigned i) const {
1278    assert(i < NumTemps && "Index out of range");
1279    return Temps[i];
1280  }
1281
1282  bool shouldDestroyTemporaries() const { return ShouldDestroyTemps; }
1283
1284  void removeLastTemporary() { NumTemps--; }
1285
1286  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1287  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1288  void setSubExpr(Expr *E) { SubExpr = E; }
1289
1290  virtual SourceRange getSourceRange() const { return SourceRange(); }
1291
1292  // Implement isa/cast/dyncast/etc.
1293  static bool classof(const Stmt *T) {
1294    return T->getStmtClass() == CXXExprWithTemporariesClass;
1295  }
1296  static bool classof(const CXXExprWithTemporaries *) { return true; }
1297
1298  // Iterators
1299  virtual child_iterator child_begin();
1300  virtual child_iterator child_end();
1301};
1302
1303/// \brief Describes an explicit type conversion that uses functional
1304/// notion but could not be resolved because one or more arguments are
1305/// type-dependent.
1306///
1307/// The explicit type conversions expressed by
1308/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1309/// where \c T is some type and \c a1, a2, ..., aN are values, and
1310/// either \C T is a dependent type or one or more of the \c a's is
1311/// type-dependent. For example, this would occur in a template such
1312/// as:
1313///
1314/// \code
1315///   template<typename T, typename A1>
1316///   inline T make_a(const A1& a1) {
1317///     return T(a1);
1318///   }
1319/// \endcode
1320///
1321/// When the returned expression is instantiated, it may resolve to a
1322/// constructor call, conversion function call, or some kind of type
1323/// conversion.
1324class CXXUnresolvedConstructExpr : public Expr {
1325  /// \brief The starting location of the type
1326  SourceLocation TyBeginLoc;
1327
1328  /// \brief The type being constructed.
1329  QualType Type;
1330
1331  /// \brief The location of the left parentheses ('(').
1332  SourceLocation LParenLoc;
1333
1334  /// \brief The location of the right parentheses (')').
1335  SourceLocation RParenLoc;
1336
1337  /// \brief The number of arguments used to construct the type.
1338  unsigned NumArgs;
1339
1340  CXXUnresolvedConstructExpr(SourceLocation TyBegin,
1341                             QualType T,
1342                             SourceLocation LParenLoc,
1343                             Expr **Args,
1344                             unsigned NumArgs,
1345                             SourceLocation RParenLoc);
1346
1347public:
1348  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1349                                            SourceLocation TyBegin,
1350                                            QualType T,
1351                                            SourceLocation LParenLoc,
1352                                            Expr **Args,
1353                                            unsigned NumArgs,
1354                                            SourceLocation RParenLoc);
1355
1356  /// \brief Retrieve the source location where the type begins.
1357  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1358  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1359
1360  /// \brief Retrieve the type that is being constructed, as specified
1361  /// in the source code.
1362  QualType getTypeAsWritten() const { return Type; }
1363  void setTypeAsWritten(QualType T) { Type = T; }
1364
1365  /// \brief Retrieve the location of the left parentheses ('(') that
1366  /// precedes the argument list.
1367  SourceLocation getLParenLoc() const { return LParenLoc; }
1368  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1369
1370  /// \brief Retrieve the location of the right parentheses (')') that
1371  /// follows the argument list.
1372  SourceLocation getRParenLoc() const { return RParenLoc; }
1373  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1374
1375  /// \brief Retrieve the number of arguments.
1376  unsigned arg_size() const { return NumArgs; }
1377
1378  typedef Expr** arg_iterator;
1379  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1380  arg_iterator arg_end() { return arg_begin() + NumArgs; }
1381
1382  Expr *getArg(unsigned I) {
1383    assert(I < NumArgs && "Argument index out-of-range");
1384    return *(arg_begin() + I);
1385  }
1386
1387  virtual SourceRange getSourceRange() const {
1388    return SourceRange(TyBeginLoc, RParenLoc);
1389  }
1390  static bool classof(const Stmt *T) {
1391    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1392  }
1393  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
1394
1395  // Iterators
1396  virtual child_iterator child_begin();
1397  virtual child_iterator child_end();
1398};
1399
1400/// \brief Represents a C++ member access expression where the actual member
1401/// referenced could not be resolved, e.g., because the base expression or the
1402/// member name was dependent.
1403class CXXUnresolvedMemberExpr : public Expr {
1404  /// \brief The expression for the base pointer or class reference,
1405  /// e.g., the \c x in x.f.
1406  Stmt *Base;
1407
1408  /// \brief Whether this member expression used the '->' operator or
1409  /// the '.' operator.
1410  bool IsArrow;
1411
1412  /// \brief The location of the '->' or '.' operator.
1413  SourceLocation OperatorLoc;
1414
1415  /// \brief The nested-name-specifier that precedes the member name, if any.
1416  NestedNameSpecifier *Qualifier;
1417
1418  /// \brief The source range covering the nested name specifier.
1419  SourceRange QualifierRange;
1420
1421  /// \brief In a qualified member access expression such as t->Base::f, this
1422  /// member stores the resolves of name lookup in the context of the member
1423  /// access expression, to be used at instantiation time.
1424  ///
1425  /// FIXME: This member, along with the Qualifier and QualifierRange, could
1426  /// be stuck into a structure that is optionally allocated at the end of
1427  /// the CXXUnresolvedMemberExpr, to save space in the common case.
1428  NamedDecl *FirstQualifierFoundInScope;
1429
1430  /// \brief The member to which this member expression refers, which
1431  /// can be name, overloaded operator, or destructor.
1432  /// FIXME: could also be a template-id
1433  DeclarationName Member;
1434
1435  /// \brief The location of the member name.
1436  SourceLocation MemberLoc;
1437
1438public:
1439  CXXUnresolvedMemberExpr(ASTContext &C,
1440                          Expr *Base, bool IsArrow,
1441                          SourceLocation OperatorLoc,
1442                          NestedNameSpecifier *Qualifier,
1443                          SourceRange QualifierRange,
1444                          NamedDecl *FirstQualifierFoundInScope,
1445                          DeclarationName Member,
1446                          SourceLocation MemberLoc)
1447    : Expr(CXXUnresolvedMemberExprClass, C.DependentTy, true, true),
1448      Base(Base), IsArrow(IsArrow), OperatorLoc(OperatorLoc),
1449      Qualifier(Qualifier), QualifierRange(QualifierRange),
1450      FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1451      Member(Member), MemberLoc(MemberLoc) { }
1452
1453  /// \brief Retrieve the base object of this member expressions,
1454  /// e.g., the \c x in \c x.m.
1455  Expr *getBase() { return cast<Expr>(Base); }
1456  void setBase(Expr *E) { Base = E; }
1457
1458  /// \brief Determine whether this member expression used the '->'
1459  /// operator; otherwise, it used the '.' operator.
1460  bool isArrow() const { return IsArrow; }
1461  void setArrow(bool A) { IsArrow = A; }
1462
1463  /// \brief Retrieve the location of the '->' or '.' operator.
1464  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1465  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1466
1467  /// \brief Retrieve the nested-name-specifier that qualifies the member
1468  /// name.
1469  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1470
1471  /// \brief Retrieve the source range covering the nested-name-specifier
1472  /// that qualifies the member name.
1473  SourceRange getQualifierRange() const { return QualifierRange; }
1474
1475  /// \brief Retrieve the first part of the nested-name-specifier that was
1476  /// found in the scope of the member access expression when the member access
1477  /// was initially parsed.
1478  ///
1479  /// This function only returns a useful result when member access expression
1480  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
1481  /// returned by this function describes what was found by unqualified name
1482  /// lookup for the identifier "Base" within the scope of the member access
1483  /// expression itself. At template instantiation time, this information is
1484  /// combined with the results of name lookup into the type of the object
1485  /// expression itself (the class type of x).
1486  NamedDecl *getFirstQualifierFoundInScope() const {
1487    return FirstQualifierFoundInScope;
1488  }
1489
1490  /// \brief Retrieve the name of the member that this expression
1491  /// refers to.
1492  DeclarationName getMember() const { return Member; }
1493  void setMember(DeclarationName N) { Member = N; }
1494
1495  // \brief Retrieve the location of the name of the member that this
1496  // expression refers to.
1497  SourceLocation getMemberLoc() const { return MemberLoc; }
1498  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
1499
1500  virtual SourceRange getSourceRange() const {
1501    return SourceRange(Base->getSourceRange().getBegin(),
1502                       MemberLoc);
1503  }
1504  static bool classof(const Stmt *T) {
1505    return T->getStmtClass() == CXXUnresolvedMemberExprClass;
1506  }
1507  static bool classof(const CXXUnresolvedMemberExpr *) { return true; }
1508
1509  // Iterators
1510  virtual child_iterator child_begin();
1511  virtual child_iterator child_end();
1512};
1513
1514}  // end namespace clang
1515
1516#endif
1517