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