ExprCXX.h revision ba13543329afac4a0d01304ec2ec4924d99306a6
141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// 341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// The LLVM Compiler Infrastructure 441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// 541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// This file is distributed under the University of Illinois Open Source 641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// License. See LICENSE.TXT for details. 741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// 841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//===----------------------------------------------------------------------===// 941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// 1041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// This file defines the Expr interface and subclasses for C++ expressions. 1141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// 1241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//===----------------------------------------------------------------------===// 1341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 1441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#ifndef LLVM_CLANG_AST_EXPRCXX_H 1541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define LLVM_CLANG_AST_EXPRCXX_H 1641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 1741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "clang/Basic/TypeTraits.h" 1841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "clang/AST/Expr.h" 1941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "clang/AST/Decl.h" 2041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "clang/AST/DeclCXX.h" 2141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 2241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotnamespace clang { 2341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 2441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot class CXXConstructorDecl; 2541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot class CXXDestructorDecl; 2641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot class CXXMethodDecl; 2741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot class CXXTemporary; 2841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 2941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//===--------------------------------------------------------------------===// 3041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// C++ Expressions. 3141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//===--------------------------------------------------------------------===// 3241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 3341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// \brief A call to an overloaded operator written using operator 3441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// syntax. 3541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// 3641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// Represents a call to an overloaded operator written using operator 3741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 3841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// normal call, this AST node provides better information about the 3941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// syntactic representation of the call. 4041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// 4141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// In a C++ template, this expression node kind will be used whenever 4241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// any of the arguments are type-dependent. In this case, the 4341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// function itself will be a (possibly empty) set of functions and 4441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// function templates that were found by name lookup at template 4541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// definition time. 4641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXOperatorCallExpr : public CallExpr { 4741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// \brief The overloaded operator. 4841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot OverloadedOperatorKind Operator; 4941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 5041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 5141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 5241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Expr **args, unsigned numargs, QualType t, 5341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot SourceLocation operatorloc) 5441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot : CallExpr(C, CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc), 5541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Operator(Op) {} 5641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 5741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CallExpr(C, CXXOperatorCallExprClass, Empty) { } 5841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 5941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 6041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// getOperator - Returns the kind of overloaded operator that this 6141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// expression refers to. 6241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot OverloadedOperatorKind getOperator() const { return Operator; } 6341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; } 6441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 6541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// getOperatorLoc - Returns the location of the operator symbol in 6641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// the expression. When @c getOperator()==OO_Call, this is the 6741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// location of the right parentheses; when @c 6841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// getOperator()==OO_Subscript, this is the location of the right 6941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// bracket. 7041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot SourceLocation getOperatorLoc() const { return getRParenLoc(); } 7141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 7241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual SourceRange getSourceRange() const; 7341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 7441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 7541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return T->getStmtClass() == CXXOperatorCallExprClass; 7641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 7741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXOperatorCallExpr *) { return true; } 7841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 7941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 8041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXMemberCallExpr - Represents a call to a member function that 8141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// may be written either with member call syntax (e.g., "obj.func()" 8241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// or "objptr->func()") or with normal function-call syntax 8341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// ("func()") within a member function that ends up calling a member 8441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// function. The callee in either case is a MemberExpr that contains 8541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// both the object argument and the member function, while the 8641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// arguments are the arguments within the parentheses (not including 8741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// the object argument). 8841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXMemberCallExpr : public CallExpr { 8941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 9041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXMemberCallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 9141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot QualType t, SourceLocation rparenloc) 9241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot : CallExpr(C, CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) {} 9341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 9441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// getImplicitObjectArgument - Retrieves the implicit object 9541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// argument for the member call. For example, in "x.f(5)", this 9641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// operation would return "x". 9741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Expr *getImplicitObjectArgument(); 9841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 9941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual SourceRange getSourceRange() const; 10041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 10141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 10241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return T->getStmtClass() == CXXMemberCallExprClass; 10341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 10441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXMemberCallExpr *) { return true; } 10541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 10641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 10741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 10841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 10941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// const_cast. 11041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// 11141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// This abstract class is inherited by all of the classes 11241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// representing "named" casts, e.g., CXXStaticCastExpr, 11341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 11441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXNamedCastExpr : public ExplicitCastExpr { 11541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotprivate: 11641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot SourceLocation Loc; // the location of the casting op 11741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 11841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotprotected: 11941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXNamedCastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op, 12041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot QualType writtenTy, SourceLocation l) 12141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot : ExplicitCastExpr(SC, ty, kind, op, writtenTy), Loc(l) {} 12241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 12341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 12441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot const char *getCastName() const; 12541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 12641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// \brief Retrieve the location of the cast operator keyword, e.g., 12741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot /// "static_cast". 12841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot SourceLocation getOperatorLoc() const { return Loc; } 12941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot void setOperatorLoc(SourceLocation L) { Loc = L; } 13041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 13141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual SourceRange getSourceRange() const { 13241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); 13341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 13441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 13541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot switch (T->getStmtClass()) { 13641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot case CXXNamedCastExprClass: 13741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot case CXXStaticCastExprClass: 13841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot case CXXDynamicCastExprClass: 13941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot case CXXReinterpretCastExprClass: 14041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot case CXXConstCastExprClass: 14141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return true; 14241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot default: 14341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return false; 14441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 14541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 14641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXNamedCastExpr *) { return true; } 14741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 14841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 14941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]). 15041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// 15141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// This expression node represents a C++ static cast, e.g., 15241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// @c static_cast<int>(1.0). 15341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXStaticCastExpr : public CXXNamedCastExpr { 15441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 15541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op, 15641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot QualType writtenTy, SourceLocation l) 15741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, writtenTy, l) {} 15841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 15941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 16041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return T->getStmtClass() == CXXStaticCastExprClass; 16141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 16241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXStaticCastExpr *) { return true; } 16341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 16441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 16541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 16641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 16741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// determine how to perform the type cast. 16841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// 16941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// This expression node represents a dynamic cast, e.g., 17041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// @c dynamic_cast<Derived*>(BasePtr). 17141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXDynamicCastExpr : public CXXNamedCastExpr { 17241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 17341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op, QualType writtenTy, 17441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot SourceLocation l) 17541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, writtenTy, l) {} 17641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 17741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 17841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return T->getStmtClass() == CXXDynamicCastExprClass; 17941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 18041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXDynamicCastExpr *) { return true; } 18141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 18241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 18341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 18441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// [expr.reinterpret.cast]), which provides a differently-typed view 18541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// of a value but performs no actual work at run time. 18641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// 18741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// This expression node represents a reinterpret cast, e.g., 18841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// @c reinterpret_cast<int>(VoidPtr). 18941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXReinterpretCastExpr : public CXXNamedCastExpr { 19041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 19141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op, 19241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot QualType writtenTy, SourceLocation l) 19341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op, 19441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot writtenTy, l) {} 19541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 19641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 19741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return T->getStmtClass() == CXXReinterpretCastExprClass; 19841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 19941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXReinterpretCastExpr *) { return true; } 20041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 20141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 20241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 20341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// which can remove type qualifiers but does not change the underlying value. 20441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// 20541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// This expression node represents a const cast, e.g., 20641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// @c const_cast<char*>(PtrToConstChar). 20741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXConstCastExpr : public CXXNamedCastExpr { 20841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 20941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXConstCastExpr(QualType ty, Expr *op, QualType writtenTy, 21041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot SourceLocation l) 21141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op, writtenTy, l) {} 21241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 21341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 21441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return T->getStmtClass() == CXXConstCastExprClass; 21541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 21641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXConstCastExpr *) { return true; } 21741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 21841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 21941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 22041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// 22141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXBoolLiteralExpr : public Expr { 22241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot bool Value; 22341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot SourceLocation Loc; 22441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 22541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 22641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {} 22741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 22841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot bool getValue() const { return Value; } 22941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 23041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 23141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 23241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 23341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return T->getStmtClass() == CXXBoolLiteralExprClass; 23441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 23541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXBoolLiteralExpr *) { return true; } 23641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 23741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // Iterators 23841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual child_iterator child_begin(); 23941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual child_iterator child_end(); 24041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 24141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 24241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 24341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXNullPtrLiteralExpr : public Expr { 24441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot SourceLocation Loc; 24541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 24641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 24741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Expr(CXXNullPtrLiteralExprClass, Ty), Loc(l) {} 24841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 24941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 25041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 25141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 25241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return T->getStmtClass() == CXXNullPtrLiteralExprClass; 25341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 25441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXNullPtrLiteralExpr *) { return true; } 25541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 25641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual child_iterator child_begin(); 25741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual child_iterator child_end(); 25841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 25941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 26041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 26141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// the type_info that corresponds to the supplied type, or the (possibly 26241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// dynamic) type of the supplied expression. 26341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// 26441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// This represents code like @c typeid(int) or @c typeid(*objPtr) 26541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXTypeidExpr : public Expr { 26641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotprivate: 26741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot bool isTypeOp : 1; 26841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot union { 26941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot void *Ty; 27041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Stmt *Ex; 27141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } Operand; 27241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot SourceRange Range; 27341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 27441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 27541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXTypeidExpr(bool isTypeOp, void *op, QualType Ty, const SourceRange r) : 27641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Expr(CXXTypeidExprClass, Ty, 27741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // typeid is never type-dependent (C++ [temp.dep.expr]p4) 27841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot false, 27941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // typeid is value-dependent if the type or expression are dependent 28041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot (isTypeOp ? QualType::getFromOpaquePtr(op)->isDependentType() 28141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot : static_cast<Expr*>(op)->isValueDependent())), 28241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot isTypeOp(isTypeOp), Range(r) { 28341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot if (isTypeOp) 28441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Operand.Ty = op; 28541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot else 28641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // op was an Expr*, so cast it back to that to be safe 28741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Operand.Ex = static_cast<Expr*>(op); 28841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 28941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 29041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot bool isTypeOperand() const { return isTypeOp; } 29141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot QualType getTypeOperand() const { 29241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 29341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return QualType::getFromOpaquePtr(Operand.Ty); 29441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 29541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Expr* getExprOperand() const { 29641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 29741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return static_cast<Expr*>(Operand.Ex); 29841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 29941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 30041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual SourceRange getSourceRange() const { 30141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return Range; 30241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 30341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 30441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return T->getStmtClass() == CXXTypeidExprClass; 30541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 30641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXTypeidExpr *) { return true; } 30741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 30841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // Iterators 30941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual child_iterator child_begin(); 31041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual child_iterator child_end(); 31141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 31241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 31341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// CXXThisExpr - Represents the "this" expression in C++, which is a 31441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// pointer to the object on which the current member function is 31541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// executing (C++ [expr.prim]p3). Example: 31641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// 31741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// @code 31841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// class Foo { 31941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// public: 32041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// void bar(); 32141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// void test() { this->bar(); } 32241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// }; 32341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot/// @endcode 32441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CXXThisExpr : public Expr { 32541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot SourceLocation Loc; 32641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 32741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotpublic: 32841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CXXThisExpr(SourceLocation L, QualType Type) 32941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot : Expr(CXXThisExprClass, Type, 33041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // 'this' is type-dependent if the class type of the enclosing 33141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // member function is dependent (C++ [temp.dep.expr]p2) 33241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Type->isDependentType(), Type->isDependentType()), 33341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Loc(L) { } 33441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 33541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 33641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 33741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const Stmt *T) { 33841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return T->getStmtClass() == CXXThisExprClass; 33941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot } 34041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static bool classof(const CXXThisExpr *) { return true; } 34141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 342 // Iterators 343 virtual child_iterator child_begin(); 344 virtual child_iterator child_end(); 345}; 346 347/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 348/// 'throw' and 'throw' assignment-expression. When 349/// assignment-expression isn't present, Op will be null. 350/// 351class CXXThrowExpr : public Expr { 352 Stmt *Op; 353 SourceLocation ThrowLoc; 354public: 355 // Ty is the void type which is used as the result type of the 356 // exepression. The l is the location of the throw keyword. expr 357 // can by null, if the optional expression to throw isn't present. 358 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) : 359 Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {} 360 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 361 Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 362 void setSubExpr(Expr *E) { Op = E; } 363 364 SourceLocation getThrowLoc() const { return ThrowLoc; } 365 void setThrowLoc(SourceLocation L) { ThrowLoc = L; } 366 367 virtual SourceRange getSourceRange() const { 368 if (getSubExpr() == 0) 369 return SourceRange(ThrowLoc, ThrowLoc); 370 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 371 } 372 373 static bool classof(const Stmt *T) { 374 return T->getStmtClass() == CXXThrowExprClass; 375 } 376 static bool classof(const CXXThrowExpr *) { return true; } 377 378 // Iterators 379 virtual child_iterator child_begin(); 380 virtual child_iterator child_end(); 381}; 382 383/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 384/// function call argument that was created from the corresponding 385/// parameter's default argument, when the call did not explicitly 386/// supply arguments for all of the parameters. 387class CXXDefaultArgExpr : public Expr { 388 ParmVarDecl *Param; 389 390protected: 391 CXXDefaultArgExpr(StmtClass SC, ParmVarDecl *param) 392 : Expr(SC, param->hasUnparsedDefaultArg() ? 393 param->getType().getNonReferenceType() 394 : param->getDefaultArg()->getType()), 395 Param(param) { } 396 397public: 398 // Param is the parameter whose default argument is used by this 399 // expression. 400 static CXXDefaultArgExpr *Create(ASTContext &C, ParmVarDecl *Param) { 401 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Param); 402 } 403 404 // Retrieve the parameter that the argument was created from. 405 const ParmVarDecl *getParam() const { return Param; } 406 ParmVarDecl *getParam() { return Param; } 407 408 // Retrieve the actual argument to the function call. 409 const Expr *getExpr() const { return Param->getDefaultArg(); } 410 Expr *getExpr() { return Param->getDefaultArg(); } 411 412 virtual SourceRange getSourceRange() const { 413 // Default argument expressions have no representation in the 414 // source, so they have an empty source range. 415 return SourceRange(); 416 } 417 418 static bool classof(const Stmt *T) { 419 return T->getStmtClass() == CXXDefaultArgExprClass; 420 } 421 static bool classof(const CXXDefaultArgExpr *) { return true; } 422 423 // Iterators 424 virtual child_iterator child_begin(); 425 virtual child_iterator child_end(); 426}; 427 428/// CXXTemporary - Represents a C++ temporary. 429class CXXTemporary { 430 /// Destructor - The destructor that needs to be called. 431 const CXXDestructorDecl *Destructor; 432 433 CXXTemporary(const CXXDestructorDecl *destructor) 434 : Destructor(destructor) { } 435 ~CXXTemporary() { } 436 437public: 438 static CXXTemporary *Create(ASTContext &C, 439 const CXXDestructorDecl *Destructor); 440 441 void Destroy(ASTContext &Ctx); 442 443 const CXXDestructorDecl *getDestructor() const { return Destructor; } 444}; 445 446/// CXXBindTemporaryExpr - Represents binding an expression to a temporary, 447/// so its destructor can be called later. 448class CXXBindTemporaryExpr : public Expr { 449 CXXTemporary *Temp; 450 451 Stmt *SubExpr; 452 453 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr) 454 : Expr(CXXBindTemporaryExprClass, 455 subexpr->getType()), Temp(temp), SubExpr(subexpr) { } 456 ~CXXBindTemporaryExpr() { } 457 458protected: 459 virtual void DoDestroy(ASTContext &C); 460 461public: 462 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 463 Expr* SubExpr); 464 465 CXXTemporary *getTemporary() { return Temp; } 466 const CXXTemporary *getTemporary() const { return Temp; } 467 468 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 469 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 470 void setSubExpr(Expr *E) { SubExpr = E; } 471 472 virtual SourceRange getSourceRange() const { 473 return SubExpr->getSourceRange(); 474 } 475 476 // Implement isa/cast/dyncast/etc. 477 static bool classof(const Stmt *T) { 478 return T->getStmtClass() == CXXBindTemporaryExprClass; 479 } 480 static bool classof(const CXXBindTemporaryExpr *) { return true; } 481 482 // Iterators 483 virtual child_iterator child_begin(); 484 virtual child_iterator child_end(); 485}; 486 487/// CXXConstructExpr - Represents a call to a C++ constructor. 488class CXXConstructExpr : public Expr { 489 CXXConstructorDecl *Constructor; 490 491 bool Elidable; 492 493 Stmt **Args; 494 unsigned NumArgs; 495 496protected: 497 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 498 CXXConstructorDecl *d, bool elidable, 499 Expr **args, unsigned numargs); 500 ~CXXConstructExpr() { } 501 502 virtual void DoDestroy(ASTContext &C); 503 504public: 505 /// \brief Construct an empty C++ construction expression that will store 506 /// \p numargs arguments. 507 CXXConstructExpr(EmptyShell Empty, ASTContext &C, unsigned numargs); 508 509 static CXXConstructExpr *Create(ASTContext &C, QualType T, 510 CXXConstructorDecl *D, bool Elidable, 511 Expr **Args, unsigned NumArgs); 512 513 514 CXXConstructorDecl* getConstructor() const { return Constructor; } 515 void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 516 517 /// \brief Whether this construction is elidable. 518 bool isElidable() const { return Elidable; } 519 void setElidable(bool E) { Elidable = E; } 520 521 typedef ExprIterator arg_iterator; 522 typedef ConstExprIterator const_arg_iterator; 523 524 arg_iterator arg_begin() { return Args; } 525 arg_iterator arg_end() { return Args + NumArgs; } 526 const_arg_iterator arg_begin() const { return Args; } 527 const_arg_iterator arg_end() const { return Args + NumArgs; } 528 529 unsigned getNumArgs() const { return NumArgs; } 530 531 /// getArg - Return the specified argument. 532 Expr *getArg(unsigned Arg) { 533 assert(Arg < NumArgs && "Arg access out of range!"); 534 return cast<Expr>(Args[Arg]); 535 } 536 const Expr *getArg(unsigned Arg) const { 537 assert(Arg < NumArgs && "Arg access out of range!"); 538 return cast<Expr>(Args[Arg]); 539 } 540 541 /// setArg - Set the specified argument. 542 void setArg(unsigned Arg, Expr *ArgExpr) { 543 assert(Arg < NumArgs && "Arg access out of range!"); 544 Args[Arg] = ArgExpr; 545 } 546 547 virtual SourceRange getSourceRange() const { 548 // FIXME: Should we know where the parentheses are, if there are any? 549 if (NumArgs == 0) 550 return SourceRange(); 551 552 return SourceRange(Args[0]->getLocStart(), Args[NumArgs - 1]->getLocEnd()); 553 } 554 555 static bool classof(const Stmt *T) { 556 return T->getStmtClass() == CXXConstructExprClass || 557 T->getStmtClass() == CXXTemporaryObjectExprClass; 558 } 559 static bool classof(const CXXConstructExpr *) { return true; } 560 561 // Iterators 562 virtual child_iterator child_begin(); 563 virtual child_iterator child_end(); 564}; 565 566/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 567/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 568/// x = int(0.5); 569class CXXFunctionalCastExpr : public ExplicitCastExpr { 570 SourceLocation TyBeginLoc; 571 SourceLocation RParenLoc; 572public: 573 CXXFunctionalCastExpr(QualType ty, QualType writtenTy, 574 SourceLocation tyBeginLoc, CastKind kind, 575 Expr *castExpr, SourceLocation rParenLoc) 576 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr, 577 writtenTy), 578 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 579 580 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 581 SourceLocation getRParenLoc() const { return RParenLoc; } 582 583 virtual SourceRange getSourceRange() const { 584 return SourceRange(TyBeginLoc, RParenLoc); 585 } 586 static bool classof(const Stmt *T) { 587 return T->getStmtClass() == CXXFunctionalCastExprClass; 588 } 589 static bool classof(const CXXFunctionalCastExpr *) { return true; } 590}; 591 592/// @brief Represents a C++ functional cast expression that builds a 593/// temporary object. 594/// 595/// This expression type represents a C++ "functional" cast 596/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 597/// constructor to build a temporary object. If N == 0 but no 598/// constructor will be called (because the functional cast is 599/// performing a value-initialized an object whose class type has no 600/// user-declared constructors), CXXZeroInitValueExpr will represent 601/// the functional cast. Finally, with N == 1 arguments the functional 602/// cast expression will be represented by CXXFunctionalCastExpr. 603/// Example: 604/// @code 605/// struct X { X(int, float); } 606/// 607/// X create_X() { 608/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 609/// }; 610/// @endcode 611class CXXTemporaryObjectExpr : public CXXConstructExpr { 612 SourceLocation TyBeginLoc; 613 SourceLocation RParenLoc; 614 615public: 616 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 617 QualType writtenTy, SourceLocation tyBeginLoc, 618 Expr **Args,unsigned NumArgs, 619 SourceLocation rParenLoc); 620 621 ~CXXTemporaryObjectExpr() { } 622 623 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 624 SourceLocation getRParenLoc() const { return RParenLoc; } 625 626 virtual SourceRange getSourceRange() const { 627 return SourceRange(TyBeginLoc, RParenLoc); 628 } 629 static bool classof(const Stmt *T) { 630 return T->getStmtClass() == CXXTemporaryObjectExprClass; 631 } 632 static bool classof(const CXXTemporaryObjectExpr *) { return true; } 633}; 634 635/// CXXZeroInitValueExpr - [C++ 5.2.3p2] 636/// Expression "T()" which creates a value-initialized rvalue of type 637/// T, which is either a non-class type or a class type without any 638/// user-defined constructors. 639/// 640class CXXZeroInitValueExpr : public Expr { 641 SourceLocation TyBeginLoc; 642 SourceLocation RParenLoc; 643 644public: 645 CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc, 646 SourceLocation rParenLoc ) : 647 Expr(CXXZeroInitValueExprClass, ty, false, false), 648 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 649 650 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 651 SourceLocation getRParenLoc() const { return RParenLoc; } 652 653 /// @brief Whether this initialization expression was 654 /// implicitly-generated. 655 bool isImplicit() const { 656 return TyBeginLoc.isInvalid() && RParenLoc.isInvalid(); 657 } 658 659 virtual SourceRange getSourceRange() const { 660 return SourceRange(TyBeginLoc, RParenLoc); 661 } 662 663 static bool classof(const Stmt *T) { 664 return T->getStmtClass() == CXXZeroInitValueExprClass; 665 } 666 static bool classof(const CXXZeroInitValueExpr *) { return true; } 667 668 // Iterators 669 virtual child_iterator child_begin(); 670 virtual child_iterator child_end(); 671}; 672 673/// CXXConditionDeclExpr - Condition declaration of a if/switch/while/for 674/// statement, e.g: "if (int x = f()) {...}". 675/// The main difference with DeclRefExpr is that CXXConditionDeclExpr owns the 676/// decl that it references. 677/// 678class CXXConditionDeclExpr : public DeclRefExpr { 679public: 680 CXXConditionDeclExpr(SourceLocation startLoc, 681 SourceLocation eqLoc, VarDecl *var) 682 : DeclRefExpr(CXXConditionDeclExprClass, var, 683 var->getType().getNonReferenceType(), startLoc, 684 var->getType()->isDependentType(), 685 /*FIXME:integral constant?*/ 686 var->getType()->isDependentType()) {} 687 688 SourceLocation getStartLoc() const { return getLocation(); } 689 690 VarDecl *getVarDecl() { return cast<VarDecl>(getDecl()); } 691 const VarDecl *getVarDecl() const { return cast<VarDecl>(getDecl()); } 692 693 virtual SourceRange getSourceRange() const { 694 return SourceRange(getStartLoc(), getVarDecl()->getInit()->getLocEnd()); 695 } 696 697 static bool classof(const Stmt *T) { 698 return T->getStmtClass() == CXXConditionDeclExprClass; 699 } 700 static bool classof(const CXXConditionDeclExpr *) { return true; } 701 702 // Iterators 703 virtual child_iterator child_begin(); 704 virtual child_iterator child_end(); 705}; 706 707/// CXXNewExpr - A new expression for memory allocation and constructor calls, 708/// e.g: "new CXXNewExpr(foo)". 709class CXXNewExpr : public Expr { 710 // Was the usage ::new, i.e. is the global new to be used? 711 bool GlobalNew : 1; 712 // Was the form (type-id) used? Otherwise, it was new-type-id. 713 bool ParenTypeId : 1; 714 // Is there an initializer? If not, built-ins are uninitialized, else they're 715 // value-initialized. 716 bool Initializer : 1; 717 // Do we allocate an array? If so, the first SubExpr is the size expression. 718 bool Array : 1; 719 // The number of placement new arguments. 720 unsigned NumPlacementArgs : 14; 721 // The number of constructor arguments. This may be 1 even for non-class 722 // types; use the pseudo copy constructor. 723 unsigned NumConstructorArgs : 14; 724 // Contains an optional array size expression, any number of optional 725 // placement arguments, and any number of optional constructor arguments, 726 // in that order. 727 Stmt **SubExprs; 728 // Points to the allocation function used. 729 FunctionDecl *OperatorNew; 730 // Points to the deallocation function used in case of error. May be null. 731 FunctionDecl *OperatorDelete; 732 // Points to the constructor used. Cannot be null if AllocType is a record; 733 // it would still point at the default constructor (even an implicit one). 734 // Must be null for all other types. 735 CXXConstructorDecl *Constructor; 736 737 SourceLocation StartLoc; 738 SourceLocation EndLoc; 739 740public: 741 CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, Expr **placementArgs, 742 unsigned numPlaceArgs, bool ParenTypeId, Expr *arraySize, 743 CXXConstructorDecl *constructor, bool initializer, 744 Expr **constructorArgs, unsigned numConsArgs, 745 FunctionDecl *operatorDelete, QualType ty, 746 SourceLocation startLoc, SourceLocation endLoc); 747 ~CXXNewExpr() { 748 delete[] SubExprs; 749 } 750 751 QualType getAllocatedType() const { 752 assert(getType()->isPointerType()); 753 return getType()->getAs<PointerType>()->getPointeeType(); 754 } 755 756 FunctionDecl *getOperatorNew() const { return OperatorNew; } 757 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 758 CXXConstructorDecl *getConstructor() const { return Constructor; } 759 760 bool isArray() const { return Array; } 761 Expr *getArraySize() { 762 return Array ? cast<Expr>(SubExprs[0]) : 0; 763 } 764 const Expr *getArraySize() const { 765 return Array ? cast<Expr>(SubExprs[0]) : 0; 766 } 767 768 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 769 Expr *getPlacementArg(unsigned i) { 770 assert(i < NumPlacementArgs && "Index out of range"); 771 return cast<Expr>(SubExprs[Array + i]); 772 } 773 const Expr *getPlacementArg(unsigned i) const { 774 assert(i < NumPlacementArgs && "Index out of range"); 775 return cast<Expr>(SubExprs[Array + i]); 776 } 777 778 bool isGlobalNew() const { return GlobalNew; } 779 bool isParenTypeId() const { return ParenTypeId; } 780 bool hasInitializer() const { return Initializer; } 781 782 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 783 Expr *getConstructorArg(unsigned i) { 784 assert(i < NumConstructorArgs && "Index out of range"); 785 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 786 } 787 const Expr *getConstructorArg(unsigned i) const { 788 assert(i < NumConstructorArgs && "Index out of range"); 789 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 790 } 791 792 typedef ExprIterator arg_iterator; 793 typedef ConstExprIterator const_arg_iterator; 794 795 arg_iterator placement_arg_begin() { 796 return SubExprs + Array; 797 } 798 arg_iterator placement_arg_end() { 799 return SubExprs + Array + getNumPlacementArgs(); 800 } 801 const_arg_iterator placement_arg_begin() const { 802 return SubExprs + Array; 803 } 804 const_arg_iterator placement_arg_end() const { 805 return SubExprs + Array + getNumPlacementArgs(); 806 } 807 808 arg_iterator constructor_arg_begin() { 809 return SubExprs + Array + getNumPlacementArgs(); 810 } 811 arg_iterator constructor_arg_end() { 812 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 813 } 814 const_arg_iterator constructor_arg_begin() const { 815 return SubExprs + Array + getNumPlacementArgs(); 816 } 817 const_arg_iterator constructor_arg_end() const { 818 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 819 } 820 821 virtual SourceRange getSourceRange() const { 822 return SourceRange(StartLoc, EndLoc); 823 } 824 825 static bool classof(const Stmt *T) { 826 return T->getStmtClass() == CXXNewExprClass; 827 } 828 static bool classof(const CXXNewExpr *) { return true; } 829 830 // Iterators 831 virtual child_iterator child_begin(); 832 virtual child_iterator child_end(); 833}; 834 835/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 836/// calls, e.g. "delete[] pArray". 837class CXXDeleteExpr : public Expr { 838 // Is this a forced global delete, i.e. "::delete"? 839 bool GlobalDelete : 1; 840 // Is this the array form of delete, i.e. "delete[]"? 841 bool ArrayForm : 1; 842 // Points to the operator delete overload that is used. Could be a member. 843 FunctionDecl *OperatorDelete; 844 // The pointer expression to be deleted. 845 Stmt *Argument; 846 // Location of the expression. 847 SourceLocation Loc; 848public: 849 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 850 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 851 : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete), 852 ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg), 853 Loc(loc) { } 854 855 bool isGlobalDelete() const { return GlobalDelete; } 856 bool isArrayForm() const { return ArrayForm; } 857 858 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 859 860 Expr *getArgument() { return cast<Expr>(Argument); } 861 const Expr *getArgument() const { return cast<Expr>(Argument); } 862 863 virtual SourceRange getSourceRange() const { 864 return SourceRange(Loc, Argument->getLocEnd()); 865 } 866 867 static bool classof(const Stmt *T) { 868 return T->getStmtClass() == CXXDeleteExprClass; 869 } 870 static bool classof(const CXXDeleteExpr *) { return true; } 871 872 // Iterators 873 virtual child_iterator child_begin(); 874 virtual child_iterator child_end(); 875}; 876 877/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 878/// 879/// Example: 880/// 881/// \code 882/// template<typename T> 883/// void destroy(T* ptr) { 884/// ptr->~T(); 885/// } 886/// \endcode 887/// 888/// When the template is parsed, the expression \c ptr->~T will be stored as 889/// a member reference expression. If it then instantiated with a scalar type 890/// as a template argument for T, the resulting expression will be a 891/// pseudo-destructor expression. 892class CXXPseudoDestructorExpr : public Expr { 893 /// \brief The base expression (that is being destroyed). 894 Stmt *Base; 895 896 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 897 /// period ('.'). 898 bool IsArrow : 1; 899 900 /// \brief The location of the '.' or '->' operator. 901 SourceLocation OperatorLoc; 902 903 /// \brief The nested-name-specifier that follows the operator, if present. 904 NestedNameSpecifier *Qualifier; 905 906 /// \brief The source range that covers the nested-name-specifier, if 907 /// present. 908 SourceRange QualifierRange; 909 910 /// \brief The type being destroyed. 911 QualType DestroyedType; 912 913 /// \brief The location of the type after the '~'. 914 SourceLocation DestroyedTypeLoc; 915 916public: 917 CXXPseudoDestructorExpr(ASTContext &Context, 918 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 919 NestedNameSpecifier *Qualifier, 920 SourceRange QualifierRange, 921 QualType DestroyedType, 922 SourceLocation DestroyedTypeLoc) 923 : Expr(CXXPseudoDestructorExprClass, 924 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, 925 false, 0)), 926 /*isTypeDependent=*/false, 927 /*isValueDependent=*/Base->isValueDependent()), 928 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), 929 OperatorLoc(OperatorLoc), Qualifier(Qualifier), 930 QualifierRange(QualifierRange), DestroyedType(DestroyedType), 931 DestroyedTypeLoc(DestroyedTypeLoc) { } 932 933 void setBase(Expr *E) { Base = E; } 934 Expr *getBase() const { return cast<Expr>(Base); } 935 936 /// \brief Determines whether this member expression actually had 937 /// a C++ nested-name-specifier prior to the name of the member, e.g., 938 /// x->Base::foo. 939 bool hasQualifier() const { return Qualifier != 0; } 940 941 /// \brief If the member name was qualified, retrieves the source range of 942 /// the nested-name-specifier that precedes the member name. Otherwise, 943 /// returns an empty source range. 944 SourceRange getQualifierRange() const { return QualifierRange; } 945 946 /// \brief If the member name was qualified, retrieves the 947 /// nested-name-specifier that precedes the member name. Otherwise, returns 948 /// NULL. 949 NestedNameSpecifier *getQualifier() const { return Qualifier; } 950 951 /// \brief Determine whether this pseudo-destructor expression was written 952 /// using an '->' (otherwise, it used a '.'). 953 bool isArrow() const { return IsArrow; } 954 void setArrow(bool A) { IsArrow = A; } 955 956 /// \brief Retrieve the location of the '.' or '->' operator. 957 SourceLocation getOperatorLoc() const { return OperatorLoc; } 958 959 /// \brief Retrieve the type that is being destroyed. 960 QualType getDestroyedType() const { return DestroyedType; } 961 962 /// \brief Retrieve the location of the type being destroyed. 963 SourceLocation getDestroyedTypeLoc() const { return DestroyedTypeLoc; } 964 965 virtual SourceRange getSourceRange() const { 966 return SourceRange(Base->getLocStart(), DestroyedTypeLoc); 967 } 968 969 static bool classof(const Stmt *T) { 970 return T->getStmtClass() == CXXPseudoDestructorExprClass; 971 } 972 static bool classof(const CXXPseudoDestructorExpr *) { return true; } 973 974 // Iterators 975 virtual child_iterator child_begin(); 976 virtual child_iterator child_end(); 977}; 978 979/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 980/// implementation of TR1/C++0x type trait templates. 981/// Example: 982/// __is_pod(int) == true 983/// __is_enum(std::string) == false 984class UnaryTypeTraitExpr : public Expr { 985 /// UTT - The trait. 986 UnaryTypeTrait UTT; 987 988 /// Loc - The location of the type trait keyword. 989 SourceLocation Loc; 990 991 /// RParen - The location of the closing paren. 992 SourceLocation RParen; 993 994 /// QueriedType - The type we're testing. 995 QualType QueriedType; 996 997public: 998 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried, 999 SourceLocation rparen, QualType ty) 1000 : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()), 1001 UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { } 1002 1003 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 1004 1005 UnaryTypeTrait getTrait() const { return UTT; } 1006 1007 QualType getQueriedType() const { return QueriedType; } 1008 1009 bool EvaluateTrait(ASTContext&) const; 1010 1011 static bool classof(const Stmt *T) { 1012 return T->getStmtClass() == UnaryTypeTraitExprClass; 1013 } 1014 static bool classof(const UnaryTypeTraitExpr *) { return true; } 1015 1016 // Iterators 1017 virtual child_iterator child_begin(); 1018 virtual child_iterator child_end(); 1019}; 1020 1021/// \brief A reference to a name which we were able to look up during 1022/// parsing but could not resolve to a specific declaration. This 1023/// arises in several ways: 1024/// * we might be waiting for argument-dependent lookup 1025/// * the name might resolve to an overloaded function 1026/// and eventually: 1027/// * the lookup might have included a function template 1028/// These never include UnresolvedUsingValueDecls, which are always 1029/// class members and therefore appear only in 1030/// UnresolvedMemberLookupExprs. 1031class UnresolvedLookupExpr : public Expr { 1032 /// The results. These are undesugared, which is to say, they may 1033 /// include UsingShadowDecls. 1034 UnresolvedSet Results; 1035 1036 /// The name declared. 1037 DeclarationName Name; 1038 1039 /// The qualifier given, if any. 1040 NestedNameSpecifier *Qualifier; 1041 1042 /// The source range of the nested name specifier. 1043 SourceRange QualifierRange; 1044 1045 /// The location of the name. 1046 SourceLocation NameLoc; 1047 1048 /// True if these lookup results should be extended by 1049 /// argument-dependent lookup if this is the operand of a function 1050 /// call. 1051 bool RequiresADL; 1052 1053 UnresolvedLookupExpr(QualType T, 1054 NestedNameSpecifier *Qualifier, SourceRange QRange, 1055 DeclarationName Name, SourceLocation NameLoc, 1056 bool RequiresADL) 1057 : Expr(UnresolvedLookupExprClass, T, false, false), 1058 Name(Name), Qualifier(Qualifier), QualifierRange(QRange), 1059 NameLoc(NameLoc), RequiresADL(RequiresADL) 1060 {} 1061 1062public: 1063 static UnresolvedLookupExpr *Create(ASTContext &C, 1064 NestedNameSpecifier *Qualifier, 1065 SourceRange QualifierRange, 1066 DeclarationName Name, 1067 SourceLocation NameLoc, 1068 bool ADL) { 1069 return new(C) UnresolvedLookupExpr(C.OverloadTy, Qualifier, QualifierRange, 1070 Name, NameLoc, ADL); 1071 } 1072 1073 void addDecl(NamedDecl *Decl) { 1074 Results.addDecl(Decl); 1075 } 1076 1077 typedef UnresolvedSet::iterator decls_iterator; 1078 decls_iterator decls_begin() const { return Results.begin(); } 1079 decls_iterator decls_end() const { return Results.end(); } 1080 1081 /// True if this declaration should be extended by 1082 /// argument-dependent lookup. 1083 bool requiresADL() const { return RequiresADL; } 1084 1085 /// Fetches the name looked up. 1086 DeclarationName getName() const { return Name; } 1087 1088 /// Gets the location of the name. 1089 SourceLocation getNameLoc() const { return NameLoc; } 1090 1091 /// Fetches the nested-name qualifier, if one was given. 1092 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1093 1094 /// Fetches the range of the nested-name qualifier. 1095 SourceRange getQualifierRange() const { return QualifierRange; } 1096 1097 1098 virtual SourceRange getSourceRange() const { 1099 if (Qualifier) return SourceRange(QualifierRange.getBegin(), NameLoc); 1100 return SourceRange(NameLoc, NameLoc); 1101 } 1102 1103 virtual StmtIterator child_begin(); 1104 virtual StmtIterator child_end(); 1105 1106 static bool classof(const Stmt *T) { 1107 return T->getStmtClass() == UnresolvedLookupExprClass; 1108 } 1109 static bool classof(const UnresolvedLookupExpr *) { return true; } 1110}; 1111 1112/// \brief A qualified reference to a name whose declaration cannot 1113/// yet be resolved. 1114/// 1115/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 1116/// it expresses a reference to a declaration such as 1117/// X<T>::value. The difference, however, is that an 1118/// DependentScopeDeclRefExpr node is used only within C++ templates when 1119/// the qualification (e.g., X<T>::) refers to a dependent type. In 1120/// this case, X<T>::value cannot resolve to a declaration because the 1121/// declaration will differ from on instantiation of X<T> to the 1122/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 1123/// qualifier (X<T>::) and the name of the entity being referenced 1124/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 1125/// declaration can be found. 1126class DependentScopeDeclRefExpr : public Expr { 1127 /// The name of the entity we will be referencing. 1128 DeclarationName Name; 1129 1130 /// Location of the name of the declaration we're referencing. 1131 SourceLocation Loc; 1132 1133 /// QualifierRange - The source range that covers the 1134 /// nested-name-specifier. 1135 SourceRange QualifierRange; 1136 1137 /// \brief The nested-name-specifier that qualifies this unresolved 1138 /// declaration name. 1139 NestedNameSpecifier *NNS; 1140 1141 /// \brief Whether this expr is an address of (&) operand. 1142 /// FIXME: Stash this bit into NNS! 1143 bool IsAddressOfOperand; 1144 1145public: 1146 DependentScopeDeclRefExpr(DeclarationName N, QualType T, SourceLocation L, 1147 SourceRange R, NestedNameSpecifier *NNS, 1148 bool IsAddressOfOperand) 1149 : Expr(DependentScopeDeclRefExprClass, T, true, true), 1150 Name(N), Loc(L), QualifierRange(R), NNS(NNS), 1151 IsAddressOfOperand(IsAddressOfOperand) { } 1152 1153 /// \brief Retrieve the name that this expression refers to. 1154 DeclarationName getDeclName() const { return Name; } 1155 1156 /// \brief Retrieve the location of the name within the expression. 1157 SourceLocation getLocation() const { return Loc; } 1158 1159 /// \brief Retrieve the source range of the nested-name-specifier. 1160 SourceRange getQualifierRange() const { return QualifierRange; } 1161 1162 /// \brief Retrieve the nested-name-specifier that qualifies this 1163 /// declaration. 1164 NestedNameSpecifier *getQualifier() const { return NNS; } 1165 1166 /// \brief Retrieve whether this is an address of (&) operand. 1167 1168 bool isAddressOfOperand() const { return IsAddressOfOperand; } 1169 virtual SourceRange getSourceRange() const { 1170 return SourceRange(QualifierRange.getBegin(), getLocation()); 1171 } 1172 1173 static bool classof(const Stmt *T) { 1174 return T->getStmtClass() == DependentScopeDeclRefExprClass; 1175 } 1176 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 1177 1178 virtual StmtIterator child_begin(); 1179 virtual StmtIterator child_end(); 1180}; 1181 1182/// \brief An expression that refers to a C++ template-id, such as 1183/// @c isa<FunctionDecl>. 1184class TemplateIdRefExpr : public Expr { 1185 /// \brief If this template-id was qualified-id, e.g., @c std::sort<int>, 1186 /// this nested name specifier contains the @c std::. 1187 NestedNameSpecifier *Qualifier; 1188 1189 /// \brief If this template-id was a qualified-id, e.g., @c std::sort<int>, 1190 /// this covers the source code range of the @c std::. 1191 SourceRange QualifierRange; 1192 1193 /// \brief The actual template to which this template-id refers. 1194 TemplateName Template; 1195 1196 /// \brief The source location of the template name. 1197 SourceLocation TemplateNameLoc; 1198 1199 /// \brief The source location of the left angle bracket ('<'); 1200 SourceLocation LAngleLoc; 1201 1202 /// \brief The source location of the right angle bracket ('>'); 1203 SourceLocation RAngleLoc; 1204 1205 /// \brief The number of template arguments in TemplateArgs. 1206 unsigned NumTemplateArgs; 1207 1208 TemplateIdRefExpr(QualType T, 1209 NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 1210 TemplateName Template, SourceLocation TemplateNameLoc, 1211 SourceLocation LAngleLoc, 1212 const TemplateArgumentLoc *TemplateArgs, 1213 unsigned NumTemplateArgs, 1214 SourceLocation RAngleLoc); 1215 1216 virtual void DoDestroy(ASTContext &Context); 1217 1218public: 1219 static TemplateIdRefExpr * 1220 Create(ASTContext &Context, QualType T, 1221 NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 1222 TemplateName Template, SourceLocation TemplateNameLoc, 1223 SourceLocation LAngleLoc, const TemplateArgumentLoc *TemplateArgs, 1224 unsigned NumTemplateArgs, SourceLocation RAngleLoc); 1225 1226 /// \brief Retrieve the nested name specifier used to qualify the name of 1227 /// this template-id, e.g., the "std::sort" in @c std::sort<int>, or NULL 1228 /// if this template-id was an unqualified-id. 1229 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1230 1231 /// \brief Retrieve the source range describing the nested name specifier 1232 /// used to qualified the name of this template-id, if the name was qualified. 1233 SourceRange getQualifierRange() const { return QualifierRange; } 1234 1235 /// \brief Retrieve the name of the template referenced, e.g., "sort" in 1236 /// @c std::sort<int>; 1237 TemplateName getTemplateName() const { return Template; } 1238 1239 /// \brief Retrieve the location of the name of the template referenced, e.g., 1240 /// the location of "sort" in @c std::sort<int>. 1241 SourceLocation getTemplateNameLoc() const { return TemplateNameLoc; } 1242 1243 /// \brief Retrieve the location of the left angle bracket following the 1244 /// template name ('<'). 1245 SourceLocation getLAngleLoc() const { return LAngleLoc; } 1246 1247 /// \brief Retrieve the template arguments provided as part of this 1248 /// template-id. 1249 const TemplateArgumentLoc *getTemplateArgs() const { 1250 return reinterpret_cast<const TemplateArgumentLoc *>(this + 1); 1251 } 1252 1253 /// \brief Retrieve the number of template arguments provided as part of this 1254 /// template-id. 1255 unsigned getNumTemplateArgs() const { return NumTemplateArgs; } 1256 1257 /// \brief Retrieve the location of the right angle bracket following the 1258 /// template arguments ('>'). 1259 SourceLocation getRAngleLoc() const { return RAngleLoc; } 1260 1261 virtual SourceRange getSourceRange() const { 1262 return SourceRange(Qualifier? QualifierRange.getBegin() : TemplateNameLoc, 1263 RAngleLoc); 1264 } 1265 1266 // Iterators 1267 virtual child_iterator child_begin(); 1268 virtual child_iterator child_end(); 1269 1270 static bool classof(const Stmt *T) { 1271 return T->getStmtClass() == TemplateIdRefExprClass; 1272 } 1273 static bool classof(const TemplateIdRefExpr *) { return true; } 1274}; 1275 1276class CXXExprWithTemporaries : public Expr { 1277 Stmt *SubExpr; 1278 1279 CXXTemporary **Temps; 1280 unsigned NumTemps; 1281 1282 bool ShouldDestroyTemps; 1283 1284 CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps, 1285 unsigned NumTemps, bool ShouldDestroyTemps); 1286 ~CXXExprWithTemporaries(); 1287 1288protected: 1289 virtual void DoDestroy(ASTContext &C); 1290 1291public: 1292 static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr, 1293 CXXTemporary **Temps, unsigned NumTemps, 1294 bool ShouldDestroyTemporaries); 1295 1296 unsigned getNumTemporaries() const { return NumTemps; } 1297 CXXTemporary *getTemporary(unsigned i) { 1298 assert(i < NumTemps && "Index out of range"); 1299 return Temps[i]; 1300 } 1301 const CXXTemporary *getTemporary(unsigned i) const { 1302 assert(i < NumTemps && "Index out of range"); 1303 return Temps[i]; 1304 } 1305 1306 bool shouldDestroyTemporaries() const { return ShouldDestroyTemps; } 1307 1308 void removeLastTemporary() { NumTemps--; } 1309 1310 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1311 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1312 void setSubExpr(Expr *E) { SubExpr = E; } 1313 1314 virtual SourceRange getSourceRange() const { 1315 return SubExpr->getSourceRange(); 1316 } 1317 1318 // Implement isa/cast/dyncast/etc. 1319 static bool classof(const Stmt *T) { 1320 return T->getStmtClass() == CXXExprWithTemporariesClass; 1321 } 1322 static bool classof(const CXXExprWithTemporaries *) { return true; } 1323 1324 // Iterators 1325 virtual child_iterator child_begin(); 1326 virtual child_iterator child_end(); 1327}; 1328 1329/// \brief Describes an explicit type conversion that uses functional 1330/// notion but could not be resolved because one or more arguments are 1331/// type-dependent. 1332/// 1333/// The explicit type conversions expressed by 1334/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 1335/// where \c T is some type and \c a1, a2, ..., aN are values, and 1336/// either \C T is a dependent type or one or more of the \c a's is 1337/// type-dependent. For example, this would occur in a template such 1338/// as: 1339/// 1340/// \code 1341/// template<typename T, typename A1> 1342/// inline T make_a(const A1& a1) { 1343/// return T(a1); 1344/// } 1345/// \endcode 1346/// 1347/// When the returned expression is instantiated, it may resolve to a 1348/// constructor call, conversion function call, or some kind of type 1349/// conversion. 1350class CXXUnresolvedConstructExpr : public Expr { 1351 /// \brief The starting location of the type 1352 SourceLocation TyBeginLoc; 1353 1354 /// \brief The type being constructed. 1355 QualType Type; 1356 1357 /// \brief The location of the left parentheses ('('). 1358 SourceLocation LParenLoc; 1359 1360 /// \brief The location of the right parentheses (')'). 1361 SourceLocation RParenLoc; 1362 1363 /// \brief The number of arguments used to construct the type. 1364 unsigned NumArgs; 1365 1366 CXXUnresolvedConstructExpr(SourceLocation TyBegin, 1367 QualType T, 1368 SourceLocation LParenLoc, 1369 Expr **Args, 1370 unsigned NumArgs, 1371 SourceLocation RParenLoc); 1372 1373public: 1374 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 1375 SourceLocation TyBegin, 1376 QualType T, 1377 SourceLocation LParenLoc, 1378 Expr **Args, 1379 unsigned NumArgs, 1380 SourceLocation RParenLoc); 1381 1382 /// \brief Retrieve the source location where the type begins. 1383 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 1384 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 1385 1386 /// \brief Retrieve the type that is being constructed, as specified 1387 /// in the source code. 1388 QualType getTypeAsWritten() const { return Type; } 1389 void setTypeAsWritten(QualType T) { Type = T; } 1390 1391 /// \brief Retrieve the location of the left parentheses ('(') that 1392 /// precedes the argument list. 1393 SourceLocation getLParenLoc() const { return LParenLoc; } 1394 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1395 1396 /// \brief Retrieve the location of the right parentheses (')') that 1397 /// follows the argument list. 1398 SourceLocation getRParenLoc() const { return RParenLoc; } 1399 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1400 1401 /// \brief Retrieve the number of arguments. 1402 unsigned arg_size() const { return NumArgs; } 1403 1404 typedef Expr** arg_iterator; 1405 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 1406 arg_iterator arg_end() { return arg_begin() + NumArgs; } 1407 1408 Expr *getArg(unsigned I) { 1409 assert(I < NumArgs && "Argument index out-of-range"); 1410 return *(arg_begin() + I); 1411 } 1412 1413 virtual SourceRange getSourceRange() const { 1414 return SourceRange(TyBeginLoc, RParenLoc); 1415 } 1416 static bool classof(const Stmt *T) { 1417 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 1418 } 1419 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 1420 1421 // Iterators 1422 virtual child_iterator child_begin(); 1423 virtual child_iterator child_end(); 1424}; 1425 1426/// \brief Represents a C++ member access expression where the actual 1427/// member referenced could not be resolved because the base 1428/// expression or the member name was dependent. 1429class CXXDependentScopeMemberExpr : public Expr { 1430 /// \brief The expression for the base pointer or class reference, 1431 /// e.g., the \c x in x.f. 1432 Stmt *Base; 1433 1434 /// \brief Whether this member expression used the '->' operator or 1435 /// the '.' operator. 1436 bool IsArrow : 1; 1437 1438 /// \brief Whether this member expression has explicitly-specified template 1439 /// arguments. 1440 bool HasExplicitTemplateArgumentList : 1; 1441 1442 /// \brief The location of the '->' or '.' operator. 1443 SourceLocation OperatorLoc; 1444 1445 /// \brief The nested-name-specifier that precedes the member name, if any. 1446 NestedNameSpecifier *Qualifier; 1447 1448 /// \brief The source range covering the nested name specifier. 1449 SourceRange QualifierRange; 1450 1451 /// \brief In a qualified member access expression such as t->Base::f, this 1452 /// member stores the resolves of name lookup in the context of the member 1453 /// access expression, to be used at instantiation time. 1454 /// 1455 /// FIXME: This member, along with the Qualifier and QualifierRange, could 1456 /// be stuck into a structure that is optionally allocated at the end of 1457 /// the CXXDependentScopeMemberExpr, to save space in the common case. 1458 NamedDecl *FirstQualifierFoundInScope; 1459 1460 /// \brief The member to which this member expression refers, which 1461 /// can be name, overloaded operator, or destructor. 1462 /// FIXME: could also be a template-id 1463 DeclarationName Member; 1464 1465 /// \brief The location of the member name. 1466 SourceLocation MemberLoc; 1467 1468 /// \brief Retrieve the explicit template argument list that followed the 1469 /// member template name, if any. 1470 ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 1471 if (!HasExplicitTemplateArgumentList) 1472 return 0; 1473 1474 return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1475 } 1476 1477 /// \brief Retrieve the explicit template argument list that followed the 1478 /// member template name, if any. 1479 const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 1480 return const_cast<CXXDependentScopeMemberExpr *>(this) 1481 ->getExplicitTemplateArgumentList(); 1482 } 1483 1484 CXXDependentScopeMemberExpr(ASTContext &C, 1485 Expr *Base, bool IsArrow, 1486 SourceLocation OperatorLoc, 1487 NestedNameSpecifier *Qualifier, 1488 SourceRange QualifierRange, 1489 NamedDecl *FirstQualifierFoundInScope, 1490 DeclarationName Member, 1491 SourceLocation MemberLoc, 1492 bool HasExplicitTemplateArgs, 1493 SourceLocation LAngleLoc, 1494 const TemplateArgumentLoc *TemplateArgs, 1495 unsigned NumTemplateArgs, 1496 SourceLocation RAngleLoc); 1497 1498public: 1499 CXXDependentScopeMemberExpr(ASTContext &C, 1500 Expr *Base, bool IsArrow, 1501 SourceLocation OperatorLoc, 1502 NestedNameSpecifier *Qualifier, 1503 SourceRange QualifierRange, 1504 NamedDecl *FirstQualifierFoundInScope, 1505 DeclarationName Member, 1506 SourceLocation MemberLoc) 1507 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true), 1508 Base(Base), IsArrow(IsArrow), HasExplicitTemplateArgumentList(false), 1509 OperatorLoc(OperatorLoc), 1510 Qualifier(Qualifier), QualifierRange(QualifierRange), 1511 FirstQualifierFoundInScope(FirstQualifierFoundInScope), 1512 Member(Member), MemberLoc(MemberLoc) { } 1513 1514 static CXXDependentScopeMemberExpr * 1515 Create(ASTContext &C, 1516 Expr *Base, bool IsArrow, 1517 SourceLocation OperatorLoc, 1518 NestedNameSpecifier *Qualifier, 1519 SourceRange QualifierRange, 1520 NamedDecl *FirstQualifierFoundInScope, 1521 DeclarationName Member, 1522 SourceLocation MemberLoc, 1523 bool HasExplicitTemplateArgs, 1524 SourceLocation LAngleLoc, 1525 const TemplateArgumentLoc *TemplateArgs, 1526 unsigned NumTemplateArgs, 1527 SourceLocation RAngleLoc); 1528 1529 /// \brief Retrieve the base object of this member expressions, 1530 /// e.g., the \c x in \c x.m. 1531 Expr *getBase() { return cast<Expr>(Base); } 1532 void setBase(Expr *E) { Base = E; } 1533 1534 /// \brief Determine whether this member expression used the '->' 1535 /// operator; otherwise, it used the '.' operator. 1536 bool isArrow() const { return IsArrow; } 1537 void setArrow(bool A) { IsArrow = A; } 1538 1539 /// \brief Retrieve the location of the '->' or '.' operator. 1540 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1541 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1542 1543 /// \brief Retrieve the nested-name-specifier that qualifies the member 1544 /// name. 1545 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1546 1547 /// \brief Retrieve the source range covering the nested-name-specifier 1548 /// that qualifies the member name. 1549 SourceRange getQualifierRange() const { return QualifierRange; } 1550 1551 /// \brief Retrieve the first part of the nested-name-specifier that was 1552 /// found in the scope of the member access expression when the member access 1553 /// was initially parsed. 1554 /// 1555 /// This function only returns a useful result when member access expression 1556 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 1557 /// returned by this function describes what was found by unqualified name 1558 /// lookup for the identifier "Base" within the scope of the member access 1559 /// expression itself. At template instantiation time, this information is 1560 /// combined with the results of name lookup into the type of the object 1561 /// expression itself (the class type of x). 1562 NamedDecl *getFirstQualifierFoundInScope() const { 1563 return FirstQualifierFoundInScope; 1564 } 1565 1566 /// \brief Retrieve the name of the member that this expression 1567 /// refers to. 1568 DeclarationName getMember() const { return Member; } 1569 void setMember(DeclarationName N) { Member = N; } 1570 1571 // \brief Retrieve the location of the name of the member that this 1572 // expression refers to. 1573 SourceLocation getMemberLoc() const { return MemberLoc; } 1574 void setMemberLoc(SourceLocation L) { MemberLoc = L; } 1575 1576 /// \brief Determines whether this member expression actually had a C++ 1577 /// template argument list explicitly specified, e.g., x.f<int>. 1578 bool hasExplicitTemplateArgumentList() { 1579 return HasExplicitTemplateArgumentList; 1580 } 1581 1582 /// \brief Retrieve the location of the left angle bracket following the 1583 /// member name ('<'), if any. 1584 SourceLocation getLAngleLoc() const { 1585 if (!HasExplicitTemplateArgumentList) 1586 return SourceLocation(); 1587 1588 return getExplicitTemplateArgumentList()->LAngleLoc; 1589 } 1590 1591 /// \brief Retrieve the template arguments provided as part of this 1592 /// template-id. 1593 const TemplateArgumentLoc *getTemplateArgs() const { 1594 if (!HasExplicitTemplateArgumentList) 1595 return 0; 1596 1597 return getExplicitTemplateArgumentList()->getTemplateArgs(); 1598 } 1599 1600 /// \brief Retrieve the number of template arguments provided as part of this 1601 /// template-id. 1602 unsigned getNumTemplateArgs() const { 1603 if (!HasExplicitTemplateArgumentList) 1604 return 0; 1605 1606 return getExplicitTemplateArgumentList()->NumTemplateArgs; 1607 } 1608 1609 /// \brief Retrieve the location of the right angle bracket following the 1610 /// template arguments ('>'). 1611 SourceLocation getRAngleLoc() const { 1612 if (!HasExplicitTemplateArgumentList) 1613 return SourceLocation(); 1614 1615 return getExplicitTemplateArgumentList()->RAngleLoc; 1616 } 1617 1618 virtual SourceRange getSourceRange() const { 1619 if (HasExplicitTemplateArgumentList) 1620 return SourceRange(Base->getSourceRange().getBegin(), 1621 getRAngleLoc()); 1622 1623 return SourceRange(Base->getSourceRange().getBegin(), 1624 MemberLoc); 1625 } 1626 1627 static bool classof(const Stmt *T) { 1628 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 1629 } 1630 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 1631 1632 // Iterators 1633 virtual child_iterator child_begin(); 1634 virtual child_iterator child_end(); 1635}; 1636 1637} // end namespace clang 1638 1639#endif 1640