clang API Documentation

ExprCXX.h

Go to the documentation of this file.
00001 //===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the Expr interface and subclasses for C++ expressions.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_AST_EXPRCXX_H
00015 #define LLVM_CLANG_AST_EXPRCXX_H
00016 
00017 #include "clang/Basic/TypeTraits.h"
00018 #include "clang/AST/Expr.h"
00019 #include "clang/AST/UnresolvedSet.h"
00020 #include "clang/AST/TemplateBase.h"
00021 
00022 namespace clang {
00023 
00024   class CXXConstructorDecl;
00025   class CXXDestructorDecl;
00026   class CXXMethodDecl;
00027   class CXXTemporary;
00028   class TemplateArgumentListInfo;
00029 
00030 //===--------------------------------------------------------------------===//
00031 // C++ Expressions.
00032 //===--------------------------------------------------------------------===//
00033 
00034 /// \brief A call to an overloaded operator written using operator
00035 /// syntax.
00036 ///
00037 /// Represents a call to an overloaded operator written using operator
00038 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
00039 /// normal call, this AST node provides better information about the
00040 /// syntactic representation of the call.
00041 ///
00042 /// In a C++ template, this expression node kind will be used whenever
00043 /// any of the arguments are type-dependent. In this case, the
00044 /// function itself will be a (possibly empty) set of functions and
00045 /// function templates that were found by name lookup at template
00046 /// definition time.
00047 class CXXOperatorCallExpr : public CallExpr {
00048   /// \brief The overloaded operator.
00049   OverloadedOperatorKind Operator;
00050 
00051 public:
00052   CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
00053                       Expr **args, unsigned numargs, QualType t,
00054                       SourceLocation operatorloc)
00055     : CallExpr(C, CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc),
00056       Operator(Op) {}
00057   explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
00058     CallExpr(C, CXXOperatorCallExprClass, Empty) { }
00059 
00060 
00061   /// getOperator - Returns the kind of overloaded operator that this
00062   /// expression refers to.
00063   OverloadedOperatorKind getOperator() const { return Operator; }
00064   void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
00065 
00066   /// getOperatorLoc - Returns the location of the operator symbol in
00067   /// the expression. When @c getOperator()==OO_Call, this is the
00068   /// location of the right parentheses; when @c
00069   /// getOperator()==OO_Subscript, this is the location of the right
00070   /// bracket.
00071   SourceLocation getOperatorLoc() const { return getRParenLoc(); }
00072 
00073   virtual SourceRange getSourceRange() const;
00074 
00075   static bool classof(const Stmt *T) {
00076     return T->getStmtClass() == CXXOperatorCallExprClass;
00077   }
00078   static bool classof(const CXXOperatorCallExpr *) { return true; }
00079 };
00080 
00081 /// CXXMemberCallExpr - Represents a call to a member function that
00082 /// may be written either with member call syntax (e.g., "obj.func()"
00083 /// or "objptr->func()") or with normal function-call syntax
00084 /// ("func()") within a member function that ends up calling a member
00085 /// function. The callee in either case is a MemberExpr that contains
00086 /// both the object argument and the member function, while the
00087 /// arguments are the arguments within the parentheses (not including
00088 /// the object argument).
00089 class CXXMemberCallExpr : public CallExpr {
00090 public:
00091   CXXMemberCallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs,
00092                     QualType t, SourceLocation rparenloc)
00093     : CallExpr(C, CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) {}
00094 
00095   /// getImplicitObjectArgument - Retrieves the implicit object
00096   /// argument for the member call. For example, in "x.f(5)", this
00097   /// operation would return "x".
00098   Expr *getImplicitObjectArgument();
00099 
00100   virtual SourceRange getSourceRange() const;
00101   
00102   static bool classof(const Stmt *T) {
00103     return T->getStmtClass() == CXXMemberCallExprClass;
00104   }
00105   static bool classof(const CXXMemberCallExpr *) { return true; }
00106 };
00107 
00108 /// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
00109 /// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
00110 /// const_cast.
00111 ///
00112 /// This abstract class is inherited by all of the classes
00113 /// representing "named" casts, e.g., CXXStaticCastExpr,
00114 /// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
00115 class CXXNamedCastExpr : public ExplicitCastExpr {
00116 private:
00117   SourceLocation Loc; // the location of the casting op
00118 
00119 protected:
00120   CXXNamedCastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op,
00121                    CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
00122                    SourceLocation l)
00123     : ExplicitCastExpr(SC, ty, kind, op, BasePath, writtenTy), Loc(l) {}
00124 
00125   explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell)
00126     : ExplicitCastExpr(SC, Shell) { }
00127 
00128 public:
00129   const char *getCastName() const;
00130 
00131   /// \brief Retrieve the location of the cast operator keyword, e.g.,
00132   /// "static_cast".
00133   SourceLocation getOperatorLoc() const { return Loc; }
00134   void setOperatorLoc(SourceLocation L) { Loc = L; }
00135 
00136   virtual SourceRange getSourceRange() const {
00137     return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
00138   }
00139   static bool classof(const Stmt *T) {
00140     switch (T->getStmtClass()) {
00141     case CXXStaticCastExprClass:
00142     case CXXDynamicCastExprClass:
00143     case CXXReinterpretCastExprClass:
00144     case CXXConstCastExprClass:
00145       return true;
00146     default:
00147       return false;
00148     }
00149   }
00150   static bool classof(const CXXNamedCastExpr *) { return true; }
00151 };
00152 
00153 /// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
00154 ///
00155 /// This expression node represents a C++ static cast, e.g.,
00156 /// @c static_cast<int>(1.0).
00157 class CXXStaticCastExpr : public CXXNamedCastExpr {
00158 public:
00159   CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op, 
00160                     CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
00161                     SourceLocation l)
00162     : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, BasePath, writtenTy, l) {}
00163 
00164   explicit CXXStaticCastExpr(EmptyShell Empty)
00165     : CXXNamedCastExpr(CXXStaticCastExprClass, Empty) { }
00166 
00167   static bool classof(const Stmt *T) {
00168     return T->getStmtClass() == CXXStaticCastExprClass;
00169   }
00170   static bool classof(const CXXStaticCastExpr *) { return true; }
00171 };
00172 
00173 /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
00174 /// (C++ [expr.dynamic.cast]), which may perform a run-time check to
00175 /// determine how to perform the type cast.
00176 ///
00177 /// This expression node represents a dynamic cast, e.g.,
00178 /// @c dynamic_cast<Derived*>(BasePtr).
00179 class CXXDynamicCastExpr : public CXXNamedCastExpr {
00180 public:
00181   CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op, 
00182                      CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
00183                      SourceLocation l)
00184     : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, BasePath,
00185                        writtenTy, l) {}
00186 
00187   explicit CXXDynamicCastExpr(EmptyShell Empty)
00188     : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty) { }
00189 
00190   static bool classof(const Stmt *T) {
00191     return T->getStmtClass() == CXXDynamicCastExprClass;
00192   }
00193   static bool classof(const CXXDynamicCastExpr *) { return true; }
00194 };
00195 
00196 /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
00197 /// [expr.reinterpret.cast]), which provides a differently-typed view
00198 /// of a value but performs no actual work at run time.
00199 ///
00200 /// This expression node represents a reinterpret cast, e.g.,
00201 /// @c reinterpret_cast<int>(VoidPtr).
00202 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
00203 public:
00204   CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op, 
00205                          CXXBaseSpecifierArray BasePath,
00206                          TypeSourceInfo *writtenTy, SourceLocation l)
00207     : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op, BasePath,
00208                        writtenTy, l) {}
00209 
00210   explicit CXXReinterpretCastExpr(EmptyShell Empty)
00211     : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty) { }
00212 
00213   static bool classof(const Stmt *T) {
00214     return T->getStmtClass() == CXXReinterpretCastExprClass;
00215   }
00216   static bool classof(const CXXReinterpretCastExpr *) { return true; }
00217 };
00218 
00219 /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
00220 /// which can remove type qualifiers but does not change the underlying value.
00221 ///
00222 /// This expression node represents a const cast, e.g.,
00223 /// @c const_cast<char*>(PtrToConstChar).
00224 class CXXConstCastExpr : public CXXNamedCastExpr {
00225 public:
00226   CXXConstCastExpr(QualType ty, Expr *op, TypeSourceInfo *writtenTy,
00227                    SourceLocation l)
00228     : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op, 
00229                        CXXBaseSpecifierArray(), writtenTy, l) {}
00230 
00231   explicit CXXConstCastExpr(EmptyShell Empty)
00232     : CXXNamedCastExpr(CXXConstCastExprClass, Empty) { }
00233 
00234   static bool classof(const Stmt *T) {
00235     return T->getStmtClass() == CXXConstCastExprClass;
00236   }
00237   static bool classof(const CXXConstCastExpr *) { return true; }
00238 };
00239 
00240 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
00241 ///
00242 class CXXBoolLiteralExpr : public Expr {
00243   bool Value;
00244   SourceLocation Loc;
00245 public:
00246   CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
00247     Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {}
00248 
00249   explicit CXXBoolLiteralExpr(EmptyShell Empty)
00250     : Expr(CXXBoolLiteralExprClass, Empty) { }
00251 
00252   bool getValue() const { return Value; }
00253   void setValue(bool V) { Value = V; }
00254 
00255   virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
00256 
00257   SourceLocation getLocation() const { return Loc; }
00258   void setLocation(SourceLocation L) { Loc = L; }
00259 
00260   static bool classof(const Stmt *T) {
00261     return T->getStmtClass() == CXXBoolLiteralExprClass;
00262   }
00263   static bool classof(const CXXBoolLiteralExpr *) { return true; }
00264 
00265   // Iterators
00266   virtual child_iterator child_begin();
00267   virtual child_iterator child_end();
00268 };
00269 
00270 /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
00271 class CXXNullPtrLiteralExpr : public Expr {
00272   SourceLocation Loc;
00273 public:
00274   CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
00275     Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {}
00276 
00277   explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
00278     : Expr(CXXNullPtrLiteralExprClass, Empty) { }
00279 
00280   virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
00281 
00282   SourceLocation getLocation() const { return Loc; }
00283   void setLocation(SourceLocation L) { Loc = L; }
00284 
00285   static bool classof(const Stmt *T) {
00286     return T->getStmtClass() == CXXNullPtrLiteralExprClass;
00287   }
00288   static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
00289 
00290   virtual child_iterator child_begin();
00291   virtual child_iterator child_end();
00292 };
00293 
00294 /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
00295 /// the type_info that corresponds to the supplied type, or the (possibly
00296 /// dynamic) type of the supplied expression.
00297 ///
00298 /// This represents code like @c typeid(int) or @c typeid(*objPtr)
00299 class CXXTypeidExpr : public Expr {
00300 private:
00301   llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
00302   SourceRange Range;
00303 
00304 public:
00305   CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
00306     : Expr(CXXTypeidExprClass, Ty, 
00307            // typeid is never type-dependent (C++ [temp.dep.expr]p4)
00308            false,
00309            // typeid is value-dependent if the type or expression are dependent
00310            Operand->getType()->isDependentType()),
00311       Operand(Operand), Range(R) { }
00312   
00313   CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
00314     : Expr(CXXTypeidExprClass, Ty,
00315         // typeid is never type-dependent (C++ [temp.dep.expr]p4)
00316         false,
00317         // typeid is value-dependent if the type or expression are dependent
00318         Operand->isTypeDependent() || Operand->isValueDependent()),
00319       Operand(Operand), Range(R) { }
00320 
00321   bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
00322   
00323   /// \brief Retrieves the type operand of this typeid() expression after
00324   /// various required adjustments (removing reference types, cv-qualifiers).
00325   QualType getTypeOperand() const;
00326 
00327   /// \brief Retrieve source information for the type operand.
00328   TypeSourceInfo *getTypeOperandSourceInfo() const {
00329     assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
00330     return Operand.get<TypeSourceInfo *>();
00331   }
00332   
00333   Expr* getExprOperand() const {
00334     assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
00335     return static_cast<Expr*>(Operand.get<Stmt *>());
00336   }
00337 
00338   virtual SourceRange getSourceRange() const {
00339     return Range;
00340   }
00341   static bool classof(const Stmt *T) {
00342     return T->getStmtClass() == CXXTypeidExprClass;
00343   }
00344   static bool classof(const CXXTypeidExpr *) { return true; }
00345 
00346   // Iterators
00347   virtual child_iterator child_begin();
00348   virtual child_iterator child_end();
00349 };
00350 
00351 /// CXXThisExpr - Represents the "this" expression in C++, which is a
00352 /// pointer to the object on which the current member function is
00353 /// executing (C++ [expr.prim]p3). Example:
00354 ///
00355 /// @code
00356 /// class Foo {
00357 /// public:
00358 ///   void bar();
00359 ///   void test() { this->bar(); }
00360 /// };
00361 /// @endcode
00362 class CXXThisExpr : public Expr {
00363   SourceLocation Loc;
00364   bool Implicit : 1;
00365   
00366 public:
00367   CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
00368     : Expr(CXXThisExprClass, Type,
00369            // 'this' is type-dependent if the class type of the enclosing
00370            // member function is dependent (C++ [temp.dep.expr]p2)
00371            Type->isDependentType(), Type->isDependentType()),
00372       Loc(L), Implicit(isImplicit) { }
00373 
00374   virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
00375 
00376   bool isImplicit() const { return Implicit; }
00377   void setImplicit(bool I) { Implicit = I; }
00378   
00379   static bool classof(const Stmt *T) {
00380     return T->getStmtClass() == CXXThisExprClass;
00381   }
00382   static bool classof(const CXXThisExpr *) { return true; }
00383 
00384   // Iterators
00385   virtual child_iterator child_begin();
00386   virtual child_iterator child_end();
00387 };
00388 
00389 ///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
00390 ///  'throw' and 'throw' assignment-expression.  When
00391 ///  assignment-expression isn't present, Op will be null.
00392 ///
00393 class CXXThrowExpr : public Expr {
00394   Stmt *Op;
00395   SourceLocation ThrowLoc;
00396 public:
00397   // Ty is the void type which is used as the result type of the
00398   // exepression.  The l is the location of the throw keyword.  expr
00399   // can by null, if the optional expression to throw isn't present.
00400   CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
00401     Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {}
00402   const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
00403   Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
00404   void setSubExpr(Expr *E) { Op = E; }
00405 
00406   SourceLocation getThrowLoc() const { return ThrowLoc; }
00407   void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
00408 
00409   virtual SourceRange getSourceRange() const {
00410     if (getSubExpr() == 0)
00411       return SourceRange(ThrowLoc, ThrowLoc);
00412     return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
00413   }
00414 
00415   static bool classof(const Stmt *T) {
00416     return T->getStmtClass() == CXXThrowExprClass;
00417   }
00418   static bool classof(const CXXThrowExpr *) { return true; }
00419 
00420   // Iterators
00421   virtual child_iterator child_begin();
00422   virtual child_iterator child_end();
00423 };
00424 
00425 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
00426 /// function call argument that was created from the corresponding
00427 /// parameter's default argument, when the call did not explicitly
00428 /// supply arguments for all of the parameters.
00429 class CXXDefaultArgExpr : public Expr {
00430   /// \brief The parameter whose default is being used.
00431   ///
00432   /// When the bit is set, the subexpression is stored after the 
00433   /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
00434   /// actual default expression is the subexpression.
00435   llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
00436 
00437   /// \brief The location where the default argument expression was used.
00438   SourceLocation Loc;
00439   
00440 protected:
00441   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
00442     : Expr(SC, 
00443            param->hasUnparsedDefaultArg()
00444              ? param->getType().getNonReferenceType()
00445              : param->getDefaultArg()->getType(),
00446            false, false),
00447       Param(param, false), Loc(Loc) { }
00448 
00449   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 
00450                     Expr *SubExpr)
00451     : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc)
00452   {
00453     *reinterpret_cast<Expr **>(this + 1) = SubExpr;
00454   }
00455   
00456 protected:
00457   virtual void DoDestroy(ASTContext &C);
00458   
00459 public:
00460   // Param is the parameter whose default argument is used by this
00461   // expression.
00462   static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
00463                                    ParmVarDecl *Param) {
00464     return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
00465   }
00466 
00467   // Param is the parameter whose default argument is used by this
00468   // expression, and SubExpr is the expression that will actually be used.
00469   static CXXDefaultArgExpr *Create(ASTContext &C, 
00470                                    SourceLocation Loc,
00471                                    ParmVarDecl *Param, 
00472                                    Expr *SubExpr);
00473   
00474   // Retrieve the parameter that the argument was created from.
00475   const ParmVarDecl *getParam() const { return Param.getPointer(); }
00476   ParmVarDecl *getParam() { return Param.getPointer(); }
00477 
00478   // Retrieve the actual argument to the function call.
00479   const Expr *getExpr() const { 
00480     if (Param.getInt())
00481       return *reinterpret_cast<Expr const * const*> (this + 1);
00482     return getParam()->getDefaultArg(); 
00483   }
00484   Expr *getExpr() { 
00485     if (Param.getInt())
00486       return *reinterpret_cast<Expr **> (this + 1);
00487     return getParam()->getDefaultArg(); 
00488   }
00489 
00490   /// \brief Retrieve the location where this default argument was actually 
00491   /// used.
00492   SourceLocation getUsedLocation() const { return Loc; }
00493   
00494   virtual SourceRange getSourceRange() const {
00495     // Default argument expressions have no representation in the
00496     // source, so they have an empty source range.
00497     return SourceRange();
00498   }
00499 
00500   static bool classof(const Stmt *T) {
00501     return T->getStmtClass() == CXXDefaultArgExprClass;
00502   }
00503   static bool classof(const CXXDefaultArgExpr *) { return true; }
00504 
00505   // Iterators
00506   virtual child_iterator child_begin();
00507   virtual child_iterator child_end();
00508 };
00509 
00510 /// CXXTemporary - Represents a C++ temporary.
00511 class CXXTemporary {
00512   /// Destructor - The destructor that needs to be called.
00513   const CXXDestructorDecl *Destructor;
00514 
00515   CXXTemporary(const CXXDestructorDecl *destructor)
00516     : Destructor(destructor) { }
00517   ~CXXTemporary() { }
00518 
00519 public:
00520   static CXXTemporary *Create(ASTContext &C,
00521                               const CXXDestructorDecl *Destructor);
00522 
00523   void Destroy(ASTContext &Ctx);
00524 
00525   const CXXDestructorDecl *getDestructor() const { return Destructor; }
00526 };
00527 
00528 /// CXXBindTemporaryExpr - Represents binding an expression to a temporary,
00529 /// so its destructor can be called later.
00530 class CXXBindTemporaryExpr : public Expr {
00531   CXXTemporary *Temp;
00532 
00533   Stmt *SubExpr;
00534 
00535   CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr)
00536    : Expr(CXXBindTemporaryExprClass, subexpr->getType(), false, false),
00537      Temp(temp), SubExpr(subexpr) { }
00538   ~CXXBindTemporaryExpr() { }
00539 
00540 protected:
00541   virtual void DoDestroy(ASTContext &C);
00542 
00543 public:
00544   static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
00545                                       Expr* SubExpr);
00546 
00547   CXXTemporary *getTemporary() { return Temp; }
00548   const CXXTemporary *getTemporary() const { return Temp; }
00549 
00550   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
00551   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
00552   void setSubExpr(Expr *E) { SubExpr = E; }
00553 
00554   virtual SourceRange getSourceRange() const { 
00555     return SubExpr->getSourceRange();
00556   }
00557 
00558   // Implement isa/cast/dyncast/etc.
00559   static bool classof(const Stmt *T) {
00560     return T->getStmtClass() == CXXBindTemporaryExprClass;
00561   }
00562   static bool classof(const CXXBindTemporaryExpr *) { return true; }
00563 
00564   // Iterators
00565   virtual child_iterator child_begin();
00566   virtual child_iterator child_end();
00567 };
00568 
00569 /// CXXBindReferenceExpr - Represents binding an expression to a reference.
00570 /// In the example:
00571 ///
00572 /// const int &i = 10;
00573 ///
00574 /// a bind reference expression is inserted to indicate that 10 is bound to
00575 /// a reference. (Ans also that a temporary needs to be created to hold the
00576 /// value).
00577 class CXXBindReferenceExpr : public Expr {
00578   // SubExpr - The expression being bound.
00579   Stmt *SubExpr;
00580   
00581   // ExtendsLifetime - Whether binding this reference extends the lifetime of
00582   // the expression being bound. FIXME: Add C++ reference.
00583   bool ExtendsLifetime;
00584 
00585   /// RequiresTemporaryCopy - Whether binding the subexpression requires a
00586   /// temporary copy.
00587   bool RequiresTemporaryCopy;
00588   
00589   CXXBindReferenceExpr(Expr *subexpr, bool ExtendsLifetime, 
00590                        bool RequiresTemporaryCopy)
00591   : Expr(CXXBindReferenceExprClass, subexpr->getType(), false, false),
00592     SubExpr(subexpr), ExtendsLifetime(ExtendsLifetime), 
00593     RequiresTemporaryCopy(RequiresTemporaryCopy) { }
00594   ~CXXBindReferenceExpr() { }
00595 
00596 protected:
00597   virtual void DoDestroy(ASTContext &C);
00598 
00599 public:
00600   static CXXBindReferenceExpr *Create(ASTContext &C, Expr *SubExpr,
00601                                       bool ExtendsLifetime, 
00602                                       bool RequiresTemporaryCopy);
00603 
00604   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
00605   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
00606   void setSubExpr(Expr *E) { SubExpr = E; }
00607 
00608   virtual SourceRange getSourceRange() const { 
00609     return SubExpr->getSourceRange();
00610   }
00611 
00612   /// requiresTemporaryCopy - Whether binding the subexpression requires a
00613   /// temporary copy.
00614   bool requiresTemporaryCopy() const { return RequiresTemporaryCopy; }
00615 
00616   // extendsLifetime - Whether binding this reference extends the lifetime of
00617   // the expression being bound. FIXME: Add C++ reference.
00618   bool extendsLifetime() { return ExtendsLifetime; }
00619     
00620   // Implement isa/cast/dyncast/etc.
00621   static bool classof(const Stmt *T) {
00622     return T->getStmtClass() == CXXBindReferenceExprClass;
00623   }
00624   static bool classof(const CXXBindReferenceExpr *) { return true; }
00625 
00626   // Iterators
00627   virtual child_iterator child_begin();
00628   virtual child_iterator child_end();
00629 };
00630 
00631 /// CXXConstructExpr - Represents a call to a C++ constructor.
00632 class CXXConstructExpr : public Expr {
00633 public:
00634   enum ConstructionKind {
00635     CK_Complete,
00636     CK_NonVirtualBase,
00637     CK_VirtualBase
00638   };
00639     
00640 private:
00641   CXXConstructorDecl *Constructor;
00642 
00643   SourceLocation Loc;
00644   bool Elidable : 1;
00645   bool ZeroInitialization : 1;
00646   unsigned ConstructKind : 2;
00647   Stmt **Args;
00648   unsigned NumArgs;
00649 
00650 protected:
00651   CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
00652                    SourceLocation Loc,
00653                    CXXConstructorDecl *d, bool elidable,
00654                    Expr **args, unsigned numargs,
00655                    bool ZeroInitialization = false,
00656                    ConstructionKind ConstructKind = CK_Complete);
00657   ~CXXConstructExpr() { }
00658 
00659   virtual void DoDestroy(ASTContext &C);
00660 
00661 public:
00662   /// \brief Construct an empty C++ construction expression that will store
00663   /// \p numargs arguments.
00664   CXXConstructExpr(EmptyShell Empty, ASTContext &C, unsigned numargs);
00665   
00666   static CXXConstructExpr *Create(ASTContext &C, QualType T,
00667                                   SourceLocation Loc,
00668                                   CXXConstructorDecl *D, bool Elidable,
00669                                   Expr **Args, unsigned NumArgs,
00670                                   bool ZeroInitialization = false,
00671                                   ConstructionKind ConstructKind = CK_Complete);
00672 
00673 
00674   CXXConstructorDecl* getConstructor() const { return Constructor; }
00675   void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
00676   
00677   SourceLocation getLocation() const { return Loc; }
00678   void setLocation(SourceLocation Loc) { this->Loc = Loc; }
00679   
00680   /// \brief Whether this construction is elidable.
00681   bool isElidable() const { return Elidable; }
00682   void setElidable(bool E) { Elidable = E; }
00683   
00684   /// \brief Whether this construction first requires
00685   /// zero-initialization before the initializer is called.
00686   bool requiresZeroInitialization() const { return ZeroInitialization; }
00687   void setRequiresZeroInitialization(bool ZeroInit) {
00688     ZeroInitialization = ZeroInit;
00689   }
00690   
00691   /// \brief Determines whether this constructor is actually constructing
00692   /// a base class (rather than a complete object).
00693   ConstructionKind getConstructionKind() const {
00694     return (ConstructionKind)ConstructKind;
00695   }
00696   void setConstructionKind(ConstructionKind CK) { 
00697     ConstructKind = CK;
00698   }
00699   
00700   typedef ExprIterator arg_iterator;
00701   typedef ConstExprIterator const_arg_iterator;
00702 
00703   arg_iterator arg_begin() { return Args; }
00704   arg_iterator arg_end() { return Args + NumArgs; }
00705   const_arg_iterator arg_begin() const { return Args; }
00706   const_arg_iterator arg_end() const { return Args + NumArgs; }
00707 
00708   Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
00709   unsigned getNumArgs() const { return NumArgs; }
00710 
00711   /// getArg - Return the specified argument.
00712   Expr *getArg(unsigned Arg) {
00713     assert(Arg < NumArgs && "Arg access out of range!");
00714     return cast<Expr>(Args[Arg]);
00715   }
00716   const Expr *getArg(unsigned Arg) const {
00717     assert(Arg < NumArgs && "Arg access out of range!");
00718     return cast<Expr>(Args[Arg]);
00719   }
00720 
00721   /// setArg - Set the specified argument.
00722   void setArg(unsigned Arg, Expr *ArgExpr) {
00723     assert(Arg < NumArgs && "Arg access out of range!");
00724     Args[Arg] = ArgExpr;
00725   }
00726 
00727   virtual SourceRange getSourceRange() const;
00728 
00729   static bool classof(const Stmt *T) {
00730     return T->getStmtClass() == CXXConstructExprClass ||
00731       T->getStmtClass() == CXXTemporaryObjectExprClass;
00732   }
00733   static bool classof(const CXXConstructExpr *) { return true; }
00734 
00735   // Iterators
00736   virtual child_iterator child_begin();
00737   virtual child_iterator child_end();
00738 };
00739 
00740 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
00741 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
00742 /// x = int(0.5);
00743 class CXXFunctionalCastExpr : public ExplicitCastExpr {
00744   SourceLocation TyBeginLoc;
00745   SourceLocation RParenLoc;
00746 public:
00747   CXXFunctionalCastExpr(QualType ty, TypeSourceInfo *writtenTy,
00748                         SourceLocation tyBeginLoc, CastKind kind,
00749                         Expr *castExpr, CXXBaseSpecifierArray BasePath,
00750                         SourceLocation rParenLoc) 
00751     : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr, 
00752                        BasePath, writtenTy),
00753       TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
00754 
00755   explicit CXXFunctionalCastExpr(EmptyShell Shell)
00756     : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell) { }
00757 
00758   SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
00759   void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
00760   SourceLocation getRParenLoc() const { return RParenLoc; }
00761   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
00762 
00763   virtual SourceRange getSourceRange() const {
00764     return SourceRange(TyBeginLoc, RParenLoc);
00765   }
00766   static bool classof(const Stmt *T) {
00767     return T->getStmtClass() == CXXFunctionalCastExprClass;
00768   }
00769   static bool classof(const CXXFunctionalCastExpr *) { return true; }
00770 };
00771 
00772 /// @brief Represents a C++ functional cast expression that builds a
00773 /// temporary object.
00774 ///
00775 /// This expression type represents a C++ "functional" cast
00776 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
00777 /// constructor to build a temporary object. If N == 0 but no
00778 /// constructor will be called (because the functional cast is
00779 /// performing a value-initialized an object whose class type has no
00780 /// user-declared constructors), CXXZeroInitValueExpr will represent
00781 /// the functional cast. Finally, with N == 1 arguments the functional
00782 /// cast expression will be represented by CXXFunctionalCastExpr.
00783 /// Example:
00784 /// @code
00785 /// struct X { X(int, float); }
00786 ///
00787 /// X create_X() {
00788 ///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
00789 /// };
00790 /// @endcode
00791 class CXXTemporaryObjectExpr : public CXXConstructExpr {
00792   SourceLocation TyBeginLoc;
00793   SourceLocation RParenLoc;
00794 
00795 public:
00796   CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
00797                          QualType writtenTy, SourceLocation tyBeginLoc,
00798                          Expr **Args,unsigned NumArgs,
00799                          SourceLocation rParenLoc,
00800                          bool ZeroInitialization = false);
00801 
00802   ~CXXTemporaryObjectExpr() { }
00803 
00804   SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
00805   SourceLocation getRParenLoc() const { return RParenLoc; }
00806 
00807   virtual SourceRange getSourceRange() const {
00808     return SourceRange(TyBeginLoc, RParenLoc);
00809   }
00810   static bool classof(const Stmt *T) {
00811     return T->getStmtClass() == CXXTemporaryObjectExprClass;
00812   }
00813   static bool classof(const CXXTemporaryObjectExpr *) { return true; }
00814 };
00815 
00816 /// CXXZeroInitValueExpr - [C++ 5.2.3p2]
00817 /// Expression "T()" which creates a value-initialized rvalue of type
00818 /// T, which is either a non-class type or a class type without any
00819 /// user-defined constructors.
00820 ///
00821 class CXXZeroInitValueExpr : public Expr {
00822   SourceLocation TyBeginLoc;
00823   SourceLocation RParenLoc;
00824 
00825 public:
00826   CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc,
00827                        SourceLocation rParenLoc ) :
00828     Expr(CXXZeroInitValueExprClass, ty, false, false),
00829     TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
00830 
00831   SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
00832   SourceLocation getRParenLoc() const { return RParenLoc; }
00833 
00834   /// @brief Whether this initialization expression was
00835   /// implicitly-generated.
00836   bool isImplicit() const {
00837     return TyBeginLoc.isInvalid() && RParenLoc.isInvalid();
00838   }
00839 
00840   virtual SourceRange getSourceRange() const {
00841     return SourceRange(TyBeginLoc, RParenLoc);
00842   }
00843 
00844   static bool classof(const Stmt *T) {
00845     return T->getStmtClass() == CXXZeroInitValueExprClass;
00846   }
00847   static bool classof(const CXXZeroInitValueExpr *) { return true; }
00848 
00849   // Iterators
00850   virtual child_iterator child_begin();
00851   virtual child_iterator child_end();
00852 };
00853 
00854 /// CXXNewExpr - A new expression for memory allocation and constructor calls,
00855 /// e.g: "new CXXNewExpr(foo)".
00856 class CXXNewExpr : public Expr {
00857   // Was the usage ::new, i.e. is the global new to be used?
00858   bool GlobalNew : 1;
00859   // Was the form (type-id) used? Otherwise, it was new-type-id.
00860   bool ParenTypeId : 1;
00861   // Is there an initializer? If not, built-ins are uninitialized, else they're
00862   // value-initialized.
00863   bool Initializer : 1;
00864   // Do we allocate an array? If so, the first SubExpr is the size expression.
00865   bool Array : 1;
00866   // The number of placement new arguments.
00867   unsigned NumPlacementArgs : 14;
00868   // The number of constructor arguments. This may be 1 even for non-class
00869   // types; use the pseudo copy constructor.
00870   unsigned NumConstructorArgs : 14;
00871   // Contains an optional array size expression, any number of optional
00872   // placement arguments, and any number of optional constructor arguments,
00873   // in that order.
00874   Stmt **SubExprs;
00875   // Points to the allocation function used.
00876   FunctionDecl *OperatorNew;
00877   // Points to the deallocation function used in case of error. May be null.
00878   FunctionDecl *OperatorDelete;
00879   // Points to the constructor used. Cannot be null if AllocType is a record;
00880   // it would still point at the default constructor (even an implicit one).
00881   // Must be null for all other types.
00882   CXXConstructorDecl *Constructor;
00883 
00884   SourceLocation StartLoc;
00885   SourceLocation EndLoc;
00886 
00887 public:
00888   CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
00889              Expr **placementArgs, unsigned numPlaceArgs, bool ParenTypeId,
00890              Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
00891              Expr **constructorArgs, unsigned numConsArgs,
00892              FunctionDecl *operatorDelete, QualType ty,
00893              SourceLocation startLoc, SourceLocation endLoc);
00894   
00895   virtual void DoDestroy(ASTContext &C);
00896 
00897   QualType getAllocatedType() const {
00898     assert(getType()->isPointerType());
00899     return getType()->getAs<PointerType>()->getPointeeType();
00900   }
00901 
00902   FunctionDecl *getOperatorNew() const { return OperatorNew; }
00903   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
00904   CXXConstructorDecl *getConstructor() const { return Constructor; }
00905 
00906   bool isArray() const { return Array; }
00907   Expr *getArraySize() {
00908     return Array ? cast<Expr>(SubExprs[0]) : 0;
00909   }
00910   const Expr *getArraySize() const {
00911     return Array ? cast<Expr>(SubExprs[0]) : 0;
00912   }
00913 
00914   unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
00915   Expr *getPlacementArg(unsigned i) {
00916     assert(i < NumPlacementArgs && "Index out of range");
00917     return cast<Expr>(SubExprs[Array + i]);
00918   }
00919   const Expr *getPlacementArg(unsigned i) const {
00920     assert(i < NumPlacementArgs && "Index out of range");
00921     return cast<Expr>(SubExprs[Array + i]);
00922   }
00923 
00924   bool isGlobalNew() const { return GlobalNew; }
00925   bool isParenTypeId() const { return ParenTypeId; }
00926   bool hasInitializer() const { return Initializer; }
00927 
00928   unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
00929   Expr *getConstructorArg(unsigned i) {
00930     assert(i < NumConstructorArgs && "Index out of range");
00931     return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
00932   }
00933   const Expr *getConstructorArg(unsigned i) const {
00934     assert(i < NumConstructorArgs && "Index out of range");
00935     return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
00936   }
00937 
00938   typedef ExprIterator arg_iterator;
00939   typedef ConstExprIterator const_arg_iterator;
00940 
00941   arg_iterator placement_arg_begin() {
00942     return SubExprs + Array;
00943   }
00944   arg_iterator placement_arg_end() {
00945     return SubExprs + Array + getNumPlacementArgs();
00946   }
00947   const_arg_iterator placement_arg_begin() const {
00948     return SubExprs + Array;
00949   }
00950   const_arg_iterator placement_arg_end() const {
00951     return SubExprs + Array + getNumPlacementArgs();
00952   }
00953 
00954   arg_iterator constructor_arg_begin() {
00955     return SubExprs + Array + getNumPlacementArgs();
00956   }
00957   arg_iterator constructor_arg_end() {
00958     return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
00959   }
00960   const_arg_iterator constructor_arg_begin() const {
00961     return SubExprs + Array + getNumPlacementArgs();
00962   }
00963   const_arg_iterator constructor_arg_end() const {
00964     return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
00965   }
00966 
00967   virtual SourceRange getSourceRange() const {
00968     return SourceRange(StartLoc, EndLoc);
00969   }
00970 
00971   static bool classof(const Stmt *T) {
00972     return T->getStmtClass() == CXXNewExprClass;
00973   }
00974   static bool classof(const CXXNewExpr *) { return true; }
00975 
00976   // Iterators
00977   virtual child_iterator child_begin();
00978   virtual child_iterator child_end();
00979 };
00980 
00981 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
00982 /// calls, e.g. "delete[] pArray".
00983 class CXXDeleteExpr : public Expr {
00984   // Is this a forced global delete, i.e. "::delete"?
00985   bool GlobalDelete : 1;
00986   // Is this the array form of delete, i.e. "delete[]"?
00987   bool ArrayForm : 1;
00988   // Points to the operator delete overload that is used. Could be a member.
00989   FunctionDecl *OperatorDelete;
00990   // The pointer expression to be deleted.
00991   Stmt *Argument;
00992   // Location of the expression.
00993   SourceLocation Loc;
00994 public:
00995   CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
00996                 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
00997     : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete),
00998       ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg),
00999       Loc(loc) { }
01000 
01001   bool isGlobalDelete() const { return GlobalDelete; }
01002   bool isArrayForm() const { return ArrayForm; }
01003 
01004   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
01005 
01006   Expr *getArgument() { return cast<Expr>(Argument); }
01007   const Expr *getArgument() const { return cast<Expr>(Argument); }
01008 
01009   virtual SourceRange getSourceRange() const {
01010     return SourceRange(Loc, Argument->getLocEnd());
01011   }
01012 
01013   static bool classof(const Stmt *T) {
01014     return T->getStmtClass() == CXXDeleteExprClass;
01015   }
01016   static bool classof(const CXXDeleteExpr *) { return true; }
01017 
01018   // Iterators
01019   virtual child_iterator child_begin();
01020   virtual child_iterator child_end();
01021 };
01022 
01023 /// \brief Structure used to store the type being destroyed by a 
01024 /// pseudo-destructor expression.
01025 class PseudoDestructorTypeStorage {
01026   /// \brief Either the type source information or the name of the type, if 
01027   /// it couldn't be resolved due to type-dependence.
01028   llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
01029   
01030   /// \brief The starting source location of the pseudo-destructor type.
01031   SourceLocation Location;
01032   
01033 public:
01034   PseudoDestructorTypeStorage() { }
01035   
01036   PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
01037     : Type(II), Location(Loc) { }
01038   
01039   PseudoDestructorTypeStorage(TypeSourceInfo *Info);
01040   
01041   TypeSourceInfo *getTypeSourceInfo() const { 
01042     return Type.dyn_cast<TypeSourceInfo *>(); 
01043   }
01044   
01045   IdentifierInfo *getIdentifier() const {
01046     return Type.dyn_cast<IdentifierInfo *>();
01047   }
01048   
01049   SourceLocation getLocation() const { return Location; }
01050 };
01051   
01052 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
01053 ///
01054 /// A pseudo-destructor is an expression that looks like a member access to a
01055 /// destructor of a scalar type, except that scalar types don't have 
01056 /// destructors. For example:
01057 ///
01058 /// \code
01059 /// typedef int T;
01060 /// void f(int *p) {
01061 ///   p->T::~T();
01062 /// }
01063 /// \endcode
01064 ///
01065 /// Pseudo-destructors typically occur when instantiating templates such as:
01066 /// 
01067 /// \code
01068 /// template<typename T>
01069 /// void destroy(T* ptr) {
01070 ///   ptr->T::~T();
01071 /// }
01072 /// \endcode
01073 ///
01074 /// for scalar types. A pseudo-destructor expression has no run-time semantics
01075 /// beyond evaluating the base expression.
01076 class CXXPseudoDestructorExpr : public Expr {
01077   /// \brief The base expression (that is being destroyed).
01078   Stmt *Base;
01079 
01080   /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
01081   /// period ('.').
01082   bool IsArrow : 1;
01083 
01084   /// \brief The location of the '.' or '->' operator.
01085   SourceLocation OperatorLoc;
01086 
01087   /// \brief The nested-name-specifier that follows the operator, if present.
01088   NestedNameSpecifier *Qualifier;
01089 
01090   /// \brief The source range that covers the nested-name-specifier, if
01091   /// present.
01092   SourceRange QualifierRange;
01093 
01094   /// \brief The type that precedes the '::' in a qualified pseudo-destructor
01095   /// expression.
01096   TypeSourceInfo *ScopeType;
01097   
01098   /// \brief The location of the '::' in a qualified pseudo-destructor 
01099   /// expression.
01100   SourceLocation ColonColonLoc;
01101   
01102   /// \brief The location of the '~'.
01103   SourceLocation TildeLoc;
01104   
01105   /// \brief The type being destroyed, or its name if we were unable to 
01106   /// resolve the name.
01107   PseudoDestructorTypeStorage DestroyedType;
01108 
01109 public:
01110   CXXPseudoDestructorExpr(ASTContext &Context,
01111                           Expr *Base, bool isArrow, SourceLocation OperatorLoc,
01112                           NestedNameSpecifier *Qualifier,
01113                           SourceRange QualifierRange,
01114                           TypeSourceInfo *ScopeType,
01115                           SourceLocation ColonColonLoc,
01116                           SourceLocation TildeLoc,
01117                           PseudoDestructorTypeStorage DestroyedType)
01118     : Expr(CXXPseudoDestructorExprClass,
01119            Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
01120                                                           false, 0, false, 
01121                                                           false, 0, 0,
01122                                                       FunctionType::ExtInfo())),
01123            /*isTypeDependent=*/(Base->isTypeDependent() ||
01124             (DestroyedType.getTypeSourceInfo() &&
01125               DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
01126            /*isValueDependent=*/Base->isValueDependent()),
01127       Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
01128       OperatorLoc(OperatorLoc), Qualifier(Qualifier),
01129       QualifierRange(QualifierRange), 
01130       ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
01131       DestroyedType(DestroyedType) { }
01132 
01133   void setBase(Expr *E) { Base = E; }
01134   Expr *getBase() const { return cast<Expr>(Base); }
01135 
01136   /// \brief Determines whether this member expression actually had
01137   /// a C++ nested-name-specifier prior to the name of the member, e.g.,
01138   /// x->Base::foo.
01139   bool hasQualifier() const { return Qualifier != 0; }
01140 
01141   /// \brief If the member name was qualified, retrieves the source range of
01142   /// the nested-name-specifier that precedes the member name. Otherwise,
01143   /// returns an empty source range.
01144   SourceRange getQualifierRange() const { return QualifierRange; }
01145 
01146   /// \brief If the member name was qualified, retrieves the
01147   /// nested-name-specifier that precedes the member name. Otherwise, returns
01148   /// NULL.
01149   NestedNameSpecifier *getQualifier() const { return Qualifier; }
01150 
01151   /// \brief Determine whether this pseudo-destructor expression was written
01152   /// using an '->' (otherwise, it used a '.').
01153   bool isArrow() const { return IsArrow; }
01154   void setArrow(bool A) { IsArrow = A; }
01155 
01156   /// \brief Retrieve the location of the '.' or '->' operator.
01157   SourceLocation getOperatorLoc() const { return OperatorLoc; }
01158 
01159   /// \brief Retrieve the scope type in a qualified pseudo-destructor 
01160   /// expression.
01161   ///
01162   /// Pseudo-destructor expressions can have extra qualification within them
01163   /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
01164   /// Here, if the object type of the expression is (or may be) a scalar type,
01165   /// \p T may also be a scalar type and, therefore, cannot be part of a 
01166   /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
01167   /// destructor expression.
01168   TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
01169   
01170   /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
01171   /// expression.
01172   SourceLocation getColonColonLoc() const { return ColonColonLoc; }
01173   
01174   /// \brief Retrieve the location of the '~'.
01175   SourceLocation getTildeLoc() const { return TildeLoc; }
01176   
01177   /// \brief Retrieve the source location information for the type
01178   /// being destroyed.
01179   ///
01180   /// This type-source information is available for non-dependent 
01181   /// pseudo-destructor expressions and some dependent pseudo-destructor
01182   /// expressions. Returns NULL if we only have the identifier for a
01183   /// dependent pseudo-destructor expression.
01184   TypeSourceInfo *getDestroyedTypeInfo() const { 
01185     return DestroyedType.getTypeSourceInfo(); 
01186   }
01187   
01188   /// \brief In a dependent pseudo-destructor expression for which we do not
01189   /// have full type information on the destroyed type, provides the name
01190   /// of the destroyed type.
01191   IdentifierInfo *getDestroyedTypeIdentifier() const {
01192     return DestroyedType.getIdentifier();
01193   }
01194   
01195   /// \brief Retrieve the type being destroyed.
01196   QualType getDestroyedType() const;
01197   
01198   /// \brief Retrieve the starting location of the type being destroyed.
01199   SourceLocation getDestroyedTypeLoc() const { 
01200     return DestroyedType.getLocation(); 
01201   }
01202 
01203   virtual SourceRange getSourceRange() const;
01204 
01205   static bool classof(const Stmt *T) {
01206     return T->getStmtClass() == CXXPseudoDestructorExprClass;
01207   }
01208   static bool classof(const CXXPseudoDestructorExpr *) { return true; }
01209 
01210   // Iterators
01211   virtual child_iterator child_begin();
01212   virtual child_iterator child_end();
01213 };
01214 
01215 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
01216 /// implementation of TR1/C++0x type trait templates.
01217 /// Example:
01218 /// __is_pod(int) == true
01219 /// __is_enum(std::string) == false
01220 class UnaryTypeTraitExpr : public Expr {
01221   /// UTT - The trait.
01222   UnaryTypeTrait UTT;
01223 
01224   /// Loc - The location of the type trait keyword.
01225   SourceLocation Loc;
01226 
01227   /// RParen - The location of the closing paren.
01228   SourceLocation RParen;
01229 
01230   /// QueriedType - The type we're testing.
01231   QualType QueriedType;
01232 
01233 public:
01234   UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried,
01235                      SourceLocation rparen, QualType ty)
01236     : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
01237       UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
01238 
01239   virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
01240 
01241   UnaryTypeTrait getTrait() const { return UTT; }
01242 
01243   QualType getQueriedType() const { return QueriedType; }
01244 
01245   bool EvaluateTrait(ASTContext&) const;
01246 
01247   static bool classof(const Stmt *T) {
01248     return T->getStmtClass() == UnaryTypeTraitExprClass;
01249   }
01250   static bool classof(const UnaryTypeTraitExpr *) { return true; }
01251 
01252   // Iterators
01253   virtual child_iterator child_begin();
01254   virtual child_iterator child_end();
01255 };
01256 
01257 /// \brief A reference to an overloaded function set, either an
01258 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
01259 class OverloadExpr : public Expr {
01260   /// The results.  These are undesugared, which is to say, they may
01261   /// include UsingShadowDecls.  Access is relative to the naming
01262   /// class.
01263   UnresolvedSet<4> Results;
01264 
01265   /// The common name of these declarations.
01266   DeclarationName Name;
01267 
01268   /// The scope specifier, if any.
01269   NestedNameSpecifier *Qualifier;
01270   
01271   /// The source range of the scope specifier.
01272   SourceRange QualifierRange;
01273 
01274   /// The location of the name.
01275   SourceLocation NameLoc;
01276 
01277   /// True if the name was a template-id.
01278   bool HasExplicitTemplateArgs;
01279 
01280 protected:
01281   OverloadExpr(StmtClass K, QualType T, bool Dependent,
01282                NestedNameSpecifier *Qualifier, SourceRange QRange,
01283                DeclarationName Name, SourceLocation NameLoc,
01284                bool HasTemplateArgs)
01285     : Expr(K, T, Dependent, Dependent),
01286       Name(Name), Qualifier(Qualifier), QualifierRange(QRange),
01287       NameLoc(NameLoc), HasExplicitTemplateArgs(HasTemplateArgs)
01288   {}
01289 
01290 public:
01291   /// Computes whether an unresolved lookup on the given declarations
01292   /// and optional template arguments is type- and value-dependent.
01293   static bool ComputeDependence(UnresolvedSetIterator Begin,
01294                                 UnresolvedSetIterator End,
01295                                 const TemplateArgumentListInfo *Args);
01296 
01297   /// Finds the overloaded expression in the given expression of
01298   /// OverloadTy.
01299   ///
01300   /// \return the expression (which must be there) and true if it is
01301   /// within an address-of operator.
01302   static llvm::PointerIntPair<OverloadExpr*,1> find(Expr *E) {
01303     assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
01304 
01305     bool op = false;
01306     E = E->IgnoreParens();
01307     if (isa<UnaryOperator>(E))
01308       op = true, E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
01309     return llvm::PointerIntPair<OverloadExpr*,1>(cast<OverloadExpr>(E), op);
01310   }
01311 
01312   void addDecls(UnresolvedSetIterator Begin, UnresolvedSetIterator End) {
01313     Results.append(Begin, End);
01314   }
01315 
01316   /// Gets the naming class of this lookup, if any.
01317   CXXRecordDecl *getNamingClass() const;
01318 
01319   typedef UnresolvedSetImpl::iterator decls_iterator;
01320   decls_iterator decls_begin() const { return Results.begin(); }
01321   decls_iterator decls_end() const { return Results.end(); }
01322 
01323   /// Gets the decls as an unresolved set.
01324   const UnresolvedSetImpl &getDecls() { return Results; }
01325 
01326   /// Gets the number of declarations in the unresolved set.
01327   unsigned getNumDecls() const { return Results.size(); }
01328 
01329   /// Gets the name looked up.
01330   DeclarationName getName() const { return Name; }
01331   void setName(DeclarationName N) { Name = N; }
01332 
01333   /// Gets the location of the name.
01334   SourceLocation getNameLoc() const { return NameLoc; }
01335   void setNameLoc(SourceLocation Loc) { NameLoc = Loc; }
01336 
01337   /// Fetches the nested-name qualifier, if one was given.
01338   NestedNameSpecifier *getQualifier() const { return Qualifier; }
01339 
01340   /// Fetches the range of the nested-name qualifier.
01341   SourceRange getQualifierRange() const { return QualifierRange; }
01342 
01343   /// \brief Determines whether this expression had an explicit
01344   /// template argument list, e.g. f<int>.
01345   bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
01346 
01347   ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
01348 
01349   const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
01350     return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
01351   }
01352 
01353   ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
01354     if (hasExplicitTemplateArgs())
01355       return &getExplicitTemplateArgs();
01356     return 0;
01357   }
01358 
01359   static bool classof(const Stmt *T) {
01360     return T->getStmtClass() == UnresolvedLookupExprClass ||
01361            T->getStmtClass() == UnresolvedMemberExprClass;
01362   }
01363   static bool classof(const OverloadExpr *) { return true; }
01364 };
01365 
01366 /// \brief A reference to a name which we were able to look up during
01367 /// parsing but could not resolve to a specific declaration.  This
01368 /// arises in several ways:
01369 ///   * we might be waiting for argument-dependent lookup
01370 ///   * the name might resolve to an overloaded function
01371 /// and eventually:
01372 ///   * the lookup might have included a function template
01373 /// These never include UnresolvedUsingValueDecls, which are always
01374 /// class members and therefore appear only in
01375 /// UnresolvedMemberLookupExprs.
01376 class UnresolvedLookupExpr : public OverloadExpr {
01377   /// True if these lookup results should be extended by
01378   /// argument-dependent lookup if this is the operand of a function
01379   /// call.
01380   bool RequiresADL;
01381 
01382   /// True if these lookup results are overloaded.  This is pretty
01383   /// trivially rederivable if we urgently need to kill this field.
01384   bool Overloaded;
01385 
01386   /// The naming class (C++ [class.access.base]p5) of the lookup, if
01387   /// any.  This can generally be recalculated from the context chain,
01388   /// but that can be fairly expensive for unqualified lookups.  If we
01389   /// want to improve memory use here, this could go in a union
01390   /// against the qualified-lookup bits.
01391   CXXRecordDecl *NamingClass;
01392 
01393   UnresolvedLookupExpr(QualType T, bool Dependent, CXXRecordDecl *NamingClass,
01394                        NestedNameSpecifier *Qualifier, SourceRange QRange,
01395                        DeclarationName Name, SourceLocation NameLoc,
01396                        bool RequiresADL, bool Overloaded, bool HasTemplateArgs)
01397     : OverloadExpr(UnresolvedLookupExprClass, T, Dependent, Qualifier, QRange,
01398                    Name, NameLoc, HasTemplateArgs),
01399       RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
01400   {}
01401 
01402 public:
01403   static UnresolvedLookupExpr *Create(ASTContext &C,
01404                                       bool Dependent,
01405                                       CXXRecordDecl *NamingClass,
01406                                       NestedNameSpecifier *Qualifier,
01407                                       SourceRange QualifierRange,
01408                                       DeclarationName Name,
01409                                       SourceLocation NameLoc,
01410                                       bool ADL, bool Overloaded) {
01411     return new(C) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy,
01412                                        Dependent, NamingClass,
01413                                        Qualifier, QualifierRange,
01414                                        Name, NameLoc, ADL, Overloaded, false);
01415   }
01416 
01417   static UnresolvedLookupExpr *Create(ASTContext &C,
01418                                       bool Dependent,
01419                                       CXXRecordDecl *NamingClass,
01420                                       NestedNameSpecifier *Qualifier,
01421                                       SourceRange QualifierRange,
01422                                       DeclarationName Name,
01423                                       SourceLocation NameLoc,
01424                                       bool ADL,
01425                                       const TemplateArgumentListInfo &Args);
01426 
01427   /// True if this declaration should be extended by
01428   /// argument-dependent lookup.
01429   bool requiresADL() const { return RequiresADL; }
01430 
01431   /// True if this lookup is overloaded.
01432   bool isOverloaded() const { return Overloaded; }
01433 
01434   /// Gets the 'naming class' (in the sense of C++0x
01435   /// [class.access.base]p5) of the lookup.  This is the scope
01436   /// that was looked in to find these results.
01437   CXXRecordDecl *getNamingClass() const { return NamingClass; }
01438 
01439   // Note that, inconsistently with the explicit-template-argument AST
01440   // nodes, users are *forbidden* from calling these methods on objects
01441   // without explicit template arguments.
01442 
01443   ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
01444     assert(hasExplicitTemplateArgs());
01445     return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
01446   }
01447 
01448   /// Gets a reference to the explicit template argument list.
01449   const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
01450     assert(hasExplicitTemplateArgs());
01451     return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
01452   }
01453 
01454   /// \brief Copies the template arguments (if present) into the given
01455   /// structure.
01456   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
01457     getExplicitTemplateArgs().copyInto(List);
01458   }
01459   
01460   SourceLocation getLAngleLoc() const {
01461     return getExplicitTemplateArgs().LAngleLoc;
01462   }
01463 
01464   SourceLocation getRAngleLoc() const {
01465     return getExplicitTemplateArgs().RAngleLoc;
01466   }
01467 
01468   TemplateArgumentLoc const *getTemplateArgs() const {
01469     return getExplicitTemplateArgs().getTemplateArgs();
01470   }
01471 
01472   unsigned getNumTemplateArgs() const {
01473     return getExplicitTemplateArgs().NumTemplateArgs;
01474   }
01475 
01476   virtual SourceRange getSourceRange() const {
01477     SourceRange Range(getNameLoc());
01478     if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
01479     if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
01480     return Range;
01481   }
01482 
01483   virtual StmtIterator child_begin();
01484   virtual StmtIterator child_end();
01485 
01486   static bool classof(const Stmt *T) {
01487     return T->getStmtClass() == UnresolvedLookupExprClass;
01488   }
01489   static bool classof(const UnresolvedLookupExpr *) { return true; }
01490 };
01491 
01492 /// \brief A qualified reference to a name whose declaration cannot
01493 /// yet be resolved.
01494 ///
01495 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
01496 /// it expresses a reference to a declaration such as
01497 /// X<T>::value. The difference, however, is that an
01498 /// DependentScopeDeclRefExpr node is used only within C++ templates when
01499 /// the qualification (e.g., X<T>::) refers to a dependent type. In
01500 /// this case, X<T>::value cannot resolve to a declaration because the
01501 /// declaration will differ from on instantiation of X<T> to the
01502 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
01503 /// qualifier (X<T>::) and the name of the entity being referenced
01504 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
01505 /// declaration can be found.
01506 class DependentScopeDeclRefExpr : public Expr {
01507   /// The name of the entity we will be referencing.
01508   DeclarationName Name;
01509 
01510   /// Location of the name of the declaration we're referencing.
01511   SourceLocation Loc;
01512 
01513   /// QualifierRange - The source range that covers the
01514   /// nested-name-specifier.
01515   SourceRange QualifierRange;
01516 
01517   /// \brief The nested-name-specifier that qualifies this unresolved
01518   /// declaration name.
01519   NestedNameSpecifier *Qualifier;
01520 
01521   /// \brief Whether the name includes explicit template arguments.
01522   bool HasExplicitTemplateArgs;
01523 
01524   DependentScopeDeclRefExpr(QualType T,
01525                             NestedNameSpecifier *Qualifier,
01526                             SourceRange QualifierRange,
01527                             DeclarationName Name,
01528                             SourceLocation NameLoc,
01529                             bool HasExplicitTemplateArgs)
01530     : Expr(DependentScopeDeclRefExprClass, T, true, true),
01531       Name(Name), Loc(NameLoc),
01532       QualifierRange(QualifierRange), Qualifier(Qualifier),
01533       HasExplicitTemplateArgs(HasExplicitTemplateArgs)
01534   {}
01535 
01536 public:
01537   static DependentScopeDeclRefExpr *Create(ASTContext &C,
01538                                            NestedNameSpecifier *Qualifier,
01539                                            SourceRange QualifierRange,
01540                                            DeclarationName Name,
01541                                            SourceLocation NameLoc,
01542                               const TemplateArgumentListInfo *TemplateArgs = 0);
01543 
01544   /// \brief Retrieve the name that this expression refers to.
01545   DeclarationName getDeclName() const { return Name; }
01546 
01547   /// \brief Retrieve the location of the name within the expression.
01548   SourceLocation getLocation() const { return Loc; }
01549 
01550   /// \brief Retrieve the source range of the nested-name-specifier.
01551   SourceRange getQualifierRange() const { return QualifierRange; }
01552 
01553   /// \brief Retrieve the nested-name-specifier that qualifies this
01554   /// declaration.
01555   NestedNameSpecifier *getQualifier() const { return Qualifier; }
01556 
01557   /// Determines whether this lookup had explicit template arguments.
01558   bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
01559 
01560   // Note that, inconsistently with the explicit-template-argument AST
01561   // nodes, users are *forbidden* from calling these methods on objects
01562   // without explicit template arguments.
01563 
01564   /// Gets a reference to the explicit template argument list.
01565   const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
01566     assert(hasExplicitTemplateArgs());
01567     return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
01568   }
01569 
01570   /// \brief Copies the template arguments (if present) into the given
01571   /// structure.
01572   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
01573     getExplicitTemplateArgs().copyInto(List);
01574   }
01575   
01576   SourceLocation getLAngleLoc() const {
01577     return getExplicitTemplateArgs().LAngleLoc;
01578   }
01579 
01580   SourceLocation getRAngleLoc() const {
01581     return getExplicitTemplateArgs().RAngleLoc;
01582   }
01583 
01584   TemplateArgumentLoc const *getTemplateArgs() const {
01585     return getExplicitTemplateArgs().getTemplateArgs();
01586   }
01587 
01588   unsigned getNumTemplateArgs() const {
01589     return getExplicitTemplateArgs().NumTemplateArgs;
01590   }
01591 
01592   virtual SourceRange getSourceRange() const {
01593     SourceRange Range(QualifierRange.getBegin(), getLocation());
01594     if (hasExplicitTemplateArgs())
01595       Range.setEnd(getRAngleLoc());
01596     return Range;
01597   }
01598 
01599   static bool classof(const Stmt *T) {
01600     return T->getStmtClass() == DependentScopeDeclRefExprClass;
01601   }
01602   static bool classof(const DependentScopeDeclRefExpr *) { return true; }
01603 
01604   virtual StmtIterator child_begin();
01605   virtual StmtIterator child_end();
01606 };
01607 
01608 class CXXExprWithTemporaries : public Expr {
01609   Stmt *SubExpr;
01610 
01611   CXXTemporary **Temps;
01612   unsigned NumTemps;
01613 
01614   CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps,
01615                          unsigned NumTemps);
01616   ~CXXExprWithTemporaries();
01617 
01618 protected:
01619   virtual void DoDestroy(ASTContext &C);
01620 
01621 public:
01622   static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
01623                                         CXXTemporary **Temps, 
01624                                         unsigned NumTemps);
01625 
01626   unsigned getNumTemporaries() const { return NumTemps; }
01627   CXXTemporary *getTemporary(unsigned i) {
01628     assert(i < NumTemps && "Index out of range");
01629     return Temps[i];
01630   }
01631   const CXXTemporary *getTemporary(unsigned i) const {
01632     return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i);
01633   }
01634 
01635   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
01636   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
01637   void setSubExpr(Expr *E) { SubExpr = E; }
01638 
01639   virtual SourceRange getSourceRange() const { 
01640     return SubExpr->getSourceRange();
01641   }
01642 
01643   // Implement isa/cast/dyncast/etc.
01644   static bool classof(const Stmt *T) {
01645     return T->getStmtClass() == CXXExprWithTemporariesClass;
01646   }
01647   static bool classof(const CXXExprWithTemporaries *) { return true; }
01648 
01649   // Iterators
01650   virtual child_iterator child_begin();
01651   virtual child_iterator child_end();
01652 };
01653 
01654 /// \brief Describes an explicit type conversion that uses functional
01655 /// notion but could not be resolved because one or more arguments are
01656 /// type-dependent.
01657 ///
01658 /// The explicit type conversions expressed by
01659 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
01660 /// where \c T is some type and \c a1, a2, ..., aN are values, and
01661 /// either \C T is a dependent type or one or more of the \c a's is
01662 /// type-dependent. For example, this would occur in a template such
01663 /// as:
01664 ///
01665 /// \code
01666 ///   template<typename T, typename A1>
01667 ///   inline T make_a(const A1& a1) {
01668 ///     return T(a1);
01669 ///   }
01670 /// \endcode
01671 ///
01672 /// When the returned expression is instantiated, it may resolve to a
01673 /// constructor call, conversion function call, or some kind of type
01674 /// conversion.
01675 class CXXUnresolvedConstructExpr : public Expr {
01676   /// \brief The starting location of the type
01677   SourceLocation TyBeginLoc;
01678 
01679   /// \brief The type being constructed.
01680   QualType Type;
01681 
01682   /// \brief The location of the left parentheses ('(').
01683   SourceLocation LParenLoc;
01684 
01685   /// \brief The location of the right parentheses (')').
01686   SourceLocation RParenLoc;
01687 
01688   /// \brief The number of arguments used to construct the type.
01689   unsigned NumArgs;
01690 
01691   CXXUnresolvedConstructExpr(SourceLocation TyBegin,
01692                              QualType T,
01693                              SourceLocation LParenLoc,
01694                              Expr **Args,
01695                              unsigned NumArgs,
01696                              SourceLocation RParenLoc);
01697 
01698 public:
01699   static CXXUnresolvedConstructExpr *Create(ASTContext &C,
01700                                             SourceLocation TyBegin,
01701                                             QualType T,
01702                                             SourceLocation LParenLoc,
01703                                             Expr **Args,
01704                                             unsigned NumArgs,
01705                                             SourceLocation RParenLoc);
01706 
01707   /// \brief Retrieve the source location where the type begins.
01708   SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
01709   void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
01710 
01711   /// \brief Retrieve the type that is being constructed, as specified
01712   /// in the source code.
01713   QualType getTypeAsWritten() const { return Type; }
01714   void setTypeAsWritten(QualType T) { Type = T; }
01715 
01716   /// \brief Retrieve the location of the left parentheses ('(') that
01717   /// precedes the argument list.
01718   SourceLocation getLParenLoc() const { return LParenLoc; }
01719   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
01720 
01721   /// \brief Retrieve the location of the right parentheses (')') that
01722   /// follows the argument list.
01723   SourceLocation getRParenLoc() const { return RParenLoc; }
01724   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
01725 
01726   /// \brief Retrieve the number of arguments.
01727   unsigned arg_size() const { return NumArgs; }
01728 
01729   typedef Expr** arg_iterator;
01730   arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
01731   arg_iterator arg_end() { return arg_begin() + NumArgs; }
01732 
01733   typedef const Expr* const * const_arg_iterator;
01734   const_arg_iterator arg_begin() const {
01735     return reinterpret_cast<const Expr* const *>(this + 1);
01736   }
01737   const_arg_iterator arg_end() const {
01738     return arg_begin() + NumArgs;
01739   }
01740 
01741   Expr *getArg(unsigned I) {
01742     assert(I < NumArgs && "Argument index out-of-range");
01743     return *(arg_begin() + I);
01744   }
01745 
01746   const Expr *getArg(unsigned I) const {
01747     assert(I < NumArgs && "Argument index out-of-range");
01748     return *(arg_begin() + I);
01749   }
01750 
01751   virtual SourceRange getSourceRange() const {
01752     return SourceRange(TyBeginLoc, RParenLoc);
01753   }
01754   static bool classof(const Stmt *T) {
01755     return T->getStmtClass() == CXXUnresolvedConstructExprClass;
01756   }
01757   static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
01758 
01759   // Iterators
01760   virtual child_iterator child_begin();
01761   virtual child_iterator child_end();
01762 };
01763 
01764 /// \brief Represents a C++ member access expression where the actual
01765 /// member referenced could not be resolved because the base
01766 /// expression or the member name was dependent.
01767 ///
01768 /// Like UnresolvedMemberExprs, these can be either implicit or
01769 /// explicit accesses.  It is only possible to get one of these with
01770 /// an implicit access if a qualifier is provided.
01771 class CXXDependentScopeMemberExpr : public Expr {
01772   /// \brief The expression for the base pointer or class reference,
01773   /// e.g., the \c x in x.f.  Can be null in implicit accesses.
01774   Stmt *Base;
01775 
01776   /// \brief The type of the base expression.  Never null, even for
01777   /// implicit accesses.
01778   QualType BaseType;
01779 
01780   /// \brief Whether this member expression used the '->' operator or
01781   /// the '.' operator.
01782   bool IsArrow : 1;
01783 
01784   /// \brief Whether this member expression has explicitly-specified template
01785   /// arguments.
01786   bool HasExplicitTemplateArgs : 1;
01787 
01788   /// \brief The location of the '->' or '.' operator.
01789   SourceLocation OperatorLoc;
01790 
01791   /// \brief The nested-name-specifier that precedes the member name, if any.
01792   NestedNameSpecifier *Qualifier;
01793 
01794   /// \brief The source range covering the nested name specifier.
01795   SourceRange QualifierRange;
01796 
01797   /// \brief In a qualified member access expression such as t->Base::f, this
01798   /// member stores the resolves of name lookup in the context of the member
01799   /// access expression, to be used at instantiation time.
01800   ///
01801   /// FIXME: This member, along with the Qualifier and QualifierRange, could
01802   /// be stuck into a structure that is optionally allocated at the end of
01803   /// the CXXDependentScopeMemberExpr, to save space in the common case.
01804   NamedDecl *FirstQualifierFoundInScope;
01805 
01806   /// \brief The member to which this member expression refers, which
01807   /// can be name, overloaded operator, or destructor.
01808   /// FIXME: could also be a template-id
01809   DeclarationName Member;
01810 
01811   /// \brief The location of the member name.
01812   SourceLocation MemberLoc;
01813 
01814   /// \brief Retrieve the explicit template argument list that followed the
01815   /// member template name, if any.
01816   ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
01817     assert(HasExplicitTemplateArgs);
01818     return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
01819   }
01820 
01821   /// \brief Retrieve the explicit template argument list that followed the
01822   /// member template name, if any.
01823   const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
01824     return const_cast<CXXDependentScopeMemberExpr *>(this)
01825              ->getExplicitTemplateArgumentList();
01826   }
01827 
01828   CXXDependentScopeMemberExpr(ASTContext &C,
01829                           Expr *Base, QualType BaseType, bool IsArrow,
01830                           SourceLocation OperatorLoc,
01831                           NestedNameSpecifier *Qualifier,
01832                           SourceRange QualifierRange,
01833                           NamedDecl *FirstQualifierFoundInScope,
01834                           DeclarationName Member,
01835                           SourceLocation MemberLoc,
01836                           const TemplateArgumentListInfo *TemplateArgs);
01837 
01838 public:
01839   CXXDependentScopeMemberExpr(ASTContext &C,
01840                           Expr *Base, QualType BaseType,
01841                           bool IsArrow,
01842                           SourceLocation OperatorLoc,
01843                           NestedNameSpecifier *Qualifier,
01844                           SourceRange QualifierRange,
01845                           NamedDecl *FirstQualifierFoundInScope,
01846                           DeclarationName Member,
01847                           SourceLocation MemberLoc)
01848   : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
01849     Base(Base), BaseType(BaseType), IsArrow(IsArrow),
01850     HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
01851     Qualifier(Qualifier), QualifierRange(QualifierRange),
01852     FirstQualifierFoundInScope(FirstQualifierFoundInScope),
01853     Member(Member), MemberLoc(MemberLoc) { }
01854 
01855   static CXXDependentScopeMemberExpr *
01856   Create(ASTContext &C,
01857          Expr *Base, QualType BaseType, bool IsArrow,
01858          SourceLocation OperatorLoc,
01859          NestedNameSpecifier *Qualifier,
01860          SourceRange QualifierRange,
01861          NamedDecl *FirstQualifierFoundInScope,
01862          DeclarationName Member,
01863          SourceLocation MemberLoc,
01864          const TemplateArgumentListInfo *TemplateArgs);
01865 
01866   /// \brief True if this is an implicit access, i.e. one in which the
01867   /// member being accessed was not written in the source.  The source
01868   /// location of the operator is invalid in this case.
01869   bool isImplicitAccess() const { return Base == 0; }
01870 
01871   /// \brief Retrieve the base object of this member expressions,
01872   /// e.g., the \c x in \c x.m.
01873   Expr *getBase() const {
01874     assert(!isImplicitAccess());
01875     return cast<Expr>(Base);
01876   }
01877   void setBase(Expr *E) { Base = E; }
01878 
01879   QualType getBaseType() const { return BaseType; }
01880 
01881   /// \brief Determine whether this member expression used the '->'
01882   /// operator; otherwise, it used the '.' operator.
01883   bool isArrow() const { return IsArrow; }
01884   void setArrow(bool A) { IsArrow = A; }
01885 
01886   /// \brief Retrieve the location of the '->' or '.' operator.
01887   SourceLocation getOperatorLoc() const { return OperatorLoc; }
01888   void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
01889 
01890   /// \brief Retrieve the nested-name-specifier that qualifies the member
01891   /// name.
01892   NestedNameSpecifier *getQualifier() const { return Qualifier; }
01893 
01894   /// \brief Retrieve the source range covering the nested-name-specifier
01895   /// that qualifies the member name.
01896   SourceRange getQualifierRange() const { return QualifierRange; }
01897 
01898   /// \brief Retrieve the first part of the nested-name-specifier that was
01899   /// found in the scope of the member access expression when the member access
01900   /// was initially parsed.
01901   ///
01902   /// This function only returns a useful result when member access expression
01903   /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
01904   /// returned by this function describes what was found by unqualified name
01905   /// lookup for the identifier "Base" within the scope of the member access
01906   /// expression itself. At template instantiation time, this information is
01907   /// combined with the results of name lookup into the type of the object
01908   /// expression itself (the class type of x).
01909   NamedDecl *getFirstQualifierFoundInScope() const {
01910     return FirstQualifierFoundInScope;
01911   }
01912 
01913   /// \brief Retrieve the name of the member that this expression
01914   /// refers to.
01915   DeclarationName getMember() const { return Member; }
01916   void setMember(DeclarationName N) { Member = N; }
01917 
01918   // \brief Retrieve the location of the name of the member that this
01919   // expression refers to.
01920   SourceLocation getMemberLoc() const { return MemberLoc; }
01921   void setMemberLoc(SourceLocation L) { MemberLoc = L; }
01922 
01923   /// \brief Determines whether this member expression actually had a C++
01924   /// template argument list explicitly specified, e.g., x.f<int>.
01925   bool hasExplicitTemplateArgs() const {
01926     return HasExplicitTemplateArgs;
01927   }
01928 
01929   /// \brief Copies the template arguments (if present) into the given
01930   /// structure.
01931   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
01932     assert(HasExplicitTemplateArgs);
01933     getExplicitTemplateArgumentList()->copyInto(List);
01934   }
01935 
01936   /// \brief Retrieve the location of the left angle bracket following the
01937   /// member name ('<'), if any.
01938   SourceLocation getLAngleLoc() const {
01939     assert(HasExplicitTemplateArgs);
01940     return getExplicitTemplateArgumentList()->LAngleLoc;
01941   }
01942 
01943   /// \brief Retrieve the template arguments provided as part of this
01944   /// template-id.
01945   const TemplateArgumentLoc *getTemplateArgs() const {
01946     assert(HasExplicitTemplateArgs);
01947     return getExplicitTemplateArgumentList()->getTemplateArgs();
01948   }
01949 
01950   /// \brief Retrieve the number of template arguments provided as part of this
01951   /// template-id.
01952   unsigned getNumTemplateArgs() const {
01953     assert(HasExplicitTemplateArgs);
01954     return getExplicitTemplateArgumentList()->NumTemplateArgs;
01955   }
01956 
01957   /// \brief Retrieve the location of the right angle bracket following the
01958   /// template arguments ('>').
01959   SourceLocation getRAngleLoc() const {
01960     assert(HasExplicitTemplateArgs);
01961     return getExplicitTemplateArgumentList()->RAngleLoc;
01962   }
01963 
01964   virtual SourceRange getSourceRange() const {
01965     SourceRange Range;
01966     if (!isImplicitAccess())
01967       Range.setBegin(Base->getSourceRange().getBegin());
01968     else if (getQualifier())
01969       Range.setBegin(getQualifierRange().getBegin());
01970     else
01971       Range.setBegin(MemberLoc);
01972 
01973     if (hasExplicitTemplateArgs())
01974       Range.setEnd(getRAngleLoc());
01975     else
01976       Range.setEnd(MemberLoc);
01977     return Range;
01978   }
01979 
01980   static bool classof(const Stmt *T) {
01981     return T->getStmtClass() == CXXDependentScopeMemberExprClass;
01982   }
01983   static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
01984 
01985   // Iterators
01986   virtual child_iterator child_begin();
01987   virtual child_iterator child_end();
01988 };
01989 
01990 /// \brief Represents a C++ member access expression for which lookup
01991 /// produced a set of overloaded functions.
01992 ///
01993 /// The member access may be explicit or implicit:
01994 ///    struct A {
01995 ///      int a, b;
01996 ///      int explicitAccess() { return this->a + this->A::b; }
01997 ///      int implicitAccess() { return a + A::b; }
01998 ///    };
01999 ///
02000 /// In the final AST, an explicit access always becomes a MemberExpr.
02001 /// An implicit access may become either a MemberExpr or a
02002 /// DeclRefExpr, depending on whether the member is static.
02003 class UnresolvedMemberExpr : public OverloadExpr {
02004   /// \brief Whether this member expression used the '->' operator or
02005   /// the '.' operator.
02006   bool IsArrow : 1;
02007 
02008   /// \brief Whether the lookup results contain an unresolved using
02009   /// declaration.
02010   bool HasUnresolvedUsing : 1;
02011 
02012   /// \brief The expression for the base pointer or class reference,
02013   /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
02014   /// member expression
02015   Stmt *Base;
02016 
02017   /// \brief The type of the base expression;  never null.
02018   QualType BaseType;
02019 
02020   /// \brief The location of the '->' or '.' operator.
02021   SourceLocation OperatorLoc;
02022 
02023   UnresolvedMemberExpr(QualType T, bool Dependent,
02024                        bool HasUnresolvedUsing,
02025                        Expr *Base, QualType BaseType, bool IsArrow,
02026                        SourceLocation OperatorLoc,
02027                        NestedNameSpecifier *Qualifier,
02028                        SourceRange QualifierRange,
02029                        DeclarationName Member,
02030                        SourceLocation MemberLoc,
02031                        const TemplateArgumentListInfo *TemplateArgs);
02032 
02033 public:
02034   static UnresolvedMemberExpr *
02035   Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing,
02036          Expr *Base, QualType BaseType, bool IsArrow,
02037          SourceLocation OperatorLoc,
02038          NestedNameSpecifier *Qualifier,
02039          SourceRange QualifierRange,
02040          DeclarationName Member,
02041          SourceLocation MemberLoc,
02042          const TemplateArgumentListInfo *TemplateArgs);
02043 
02044   /// \brief True if this is an implicit access, i.e. one in which the
02045   /// member being accessed was not written in the source.  The source
02046   /// location of the operator is invalid in this case.
02047   bool isImplicitAccess() const { return Base == 0; }
02048 
02049   /// \brief Retrieve the base object of this member expressions,
02050   /// e.g., the \c x in \c x.m.
02051   Expr *getBase() {
02052     assert(!isImplicitAccess());
02053     return cast<Expr>(Base);
02054   }
02055   const Expr *getBase() const {
02056     assert(!isImplicitAccess());
02057     return cast<Expr>(Base);
02058   }
02059   void setBase(Expr *E) { Base = E; }
02060 
02061   QualType getBaseType() const { return BaseType; }
02062 
02063   /// \brief Determine whether this member expression used the '->'
02064   /// operator; otherwise, it used the '.' operator.
02065   bool isArrow() const { return IsArrow; }
02066   void setArrow(bool A) { IsArrow = A; }
02067 
02068   /// \brief Retrieve the location of the '->' or '.' operator.
02069   SourceLocation getOperatorLoc() const { return OperatorLoc; }
02070   void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
02071 
02072   /// \brief Retrieves the naming class of this lookup.
02073   CXXRecordDecl *getNamingClass() const;
02074 
02075   /// \brief Retrieve the name of the member that this expression
02076   /// refers to.
02077   DeclarationName getMemberName() const { return getName(); }
02078   void setMemberName(DeclarationName N) { setName(N); }
02079 
02080   // \brief Retrieve the location of the name of the member that this
02081   // expression refers to.
02082   SourceLocation getMemberLoc() const { return getNameLoc(); }
02083   void setMemberLoc(SourceLocation L) { setNameLoc(L); }
02084 
02085   /// \brief Retrieve the explicit template argument list that followed the
02086   /// member template name.
02087   ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
02088     assert(hasExplicitTemplateArgs());
02089     return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
02090   }
02091 
02092   /// \brief Retrieve the explicit template argument list that followed the
02093   /// member template name, if any.
02094   const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
02095     assert(hasExplicitTemplateArgs());
02096     return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
02097   }
02098 
02099   /// \brief Copies the template arguments into the given structure.
02100   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
02101     getExplicitTemplateArgs().copyInto(List);
02102   }
02103 
02104   /// \brief Retrieve the location of the left angle bracket following
02105   /// the member name ('<').
02106   SourceLocation getLAngleLoc() const {
02107     return getExplicitTemplateArgs().LAngleLoc;
02108   }
02109 
02110   /// \brief Retrieve the template arguments provided as part of this
02111   /// template-id.
02112   const TemplateArgumentLoc *getTemplateArgs() const {
02113     return getExplicitTemplateArgs().getTemplateArgs();
02114   }
02115 
02116   /// \brief Retrieve the number of template arguments provided as
02117   /// part of this template-id.
02118   unsigned getNumTemplateArgs() const {
02119     return getExplicitTemplateArgs().NumTemplateArgs;
02120   }
02121 
02122   /// \brief Retrieve the location of the right angle bracket
02123   /// following the template arguments ('>').
02124   SourceLocation getRAngleLoc() const {
02125     return getExplicitTemplateArgs().RAngleLoc;
02126   }
02127 
02128   virtual SourceRange getSourceRange() const {
02129     SourceRange Range;
02130     if (!isImplicitAccess())
02131       Range.setBegin(Base->getSourceRange().getBegin());
02132     else if (getQualifier())
02133       Range.setBegin(getQualifierRange().getBegin());
02134     else
02135       Range.setBegin(getMemberLoc());
02136 
02137     if (hasExplicitTemplateArgs())
02138       Range.setEnd(getRAngleLoc());
02139     else
02140       Range.setEnd(getMemberLoc());
02141     return Range;
02142   }
02143 
02144   static bool classof(const Stmt *T) {
02145     return T->getStmtClass() == UnresolvedMemberExprClass;
02146   }
02147   static bool classof(const UnresolvedMemberExpr *) { return true; }
02148 
02149   // Iterators
02150   virtual child_iterator child_begin();
02151   virtual child_iterator child_end();
02152 };
02153 
02154 inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
02155   if (isa<UnresolvedLookupExpr>(this))
02156     return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
02157   else
02158     return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
02159 }
02160 
02161 }  // end namespace clang
02162 
02163 #endif