ExprCXX.h revision 49badde06e066d058d6c7fcf4e628a72999b65a9
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Expr interface and subclasses for C++ expressions.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPRCXX_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPRCXX_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h"
18c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar#include "clang/AST/Decl.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions.
241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
2649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
2749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
2849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast.
2949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
3049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes
3149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr,
3249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
3349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr {
341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate:
351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc; // the location of the casting op
3649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
3749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
3849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  CXXNamedCastExpr(StmtClass SC, QualType ty, Expr *op, QualType writtenTy,
3949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor                   SourceLocation l)
4049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    : ExplicitCastExpr(SC, ty, op, writtenTy), Loc(l) {}
4149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
4349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  const char *getCastName() const;
4449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
451060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual SourceRange getSourceRange() const {
461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
471060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
4949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    switch (T->getStmtClass()) {
5049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXNamedCastExprClass:
5149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXStaticCastExprClass:
5249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXDynamicCastExprClass:
5349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXReinterpretCastExprClass:
5449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXConstCastExprClass:
5549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
5649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    default:
5749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return false;
5849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    }
591060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXNamedCastExpr *) { return true; }
611060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  virtual void EmitImpl(llvm::Serializer& S) const;
6349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static CXXNamedCastExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C,
6449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor                                      StmtClass SC);
6549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
6649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
6749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
6849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
6949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g.,
7049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0).
7149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr {
7249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
7349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  CXXStaticCastExpr(QualType ty, Expr *op, QualType writtenTy, SourceLocation l)
7449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, op, writtenTy, l) {}
7549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
7649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const Stmt *T) {
7749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXStaticCastExprClass;
7849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
7949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXStaticCastExpr *) { return true; }
8049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
8149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
8249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
8349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
8449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast.
8549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
8649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g.,
8749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr).
8849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr {
8949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
9049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  CXXDynamicCastExpr(QualType ty, Expr *op, QualType writtenTy, SourceLocation l)
9149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, op, writtenTy, l) {}
9249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
9349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const Stmt *T) {
9449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXDynamicCastExprClass;
9549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
9649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXDynamicCastExpr *) { return true; }
9749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
9849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
9949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
10049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view
10149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time.
10249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
10349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g.,
10449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr).
10549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr {
10649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
10749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  CXXReinterpretCastExpr(QualType ty, Expr *op, QualType writtenTy,
10849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor                         SourceLocation l)
10949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, op, writtenTy, l) {}
11049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
11149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const Stmt *T) {
11249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXReinterpretCastExprClass;
11349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
11449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXReinterpretCastExpr *) { return true; }
11549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
11649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
11749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
11849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value.
11949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
12049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g.,
12149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar).
12249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr {
12349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
12449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  CXXConstCastExpr(QualType ty, Expr *op, QualType writtenTy,
12549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor                   SourceLocation l)
12649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    : CXXNamedCastExpr(CXXConstCastExprClass, ty, op, writtenTy, l) {}
12749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
12849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const Stmt *T) {
12949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXConstCastExprClass;
13049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
13149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXConstCastExpr *) { return true; }
1321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
1331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
1341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
1351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///
1361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr {
1371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool Value;
1381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc;
1391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
1401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
1411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {}
1421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
1431060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool getValue() const { return Value; }
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1451060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1471060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
1481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXBoolLiteralExprClass;
1491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
1501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXBoolLiteralExpr *) { return true; }
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1521060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
1531060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_begin();
1541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_end();
1551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
1561060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
1571060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
1581060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  'throw' and 'throw' assignment-expression.  When
1591060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  assignment-expression isn't present, Op will be null.
1601060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///
1611060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr {
1621060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Op;
1631060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation ThrowLoc;
1641060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
1651060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Ty is the void type which is used as the result type of the
1661060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // exepression.  The l is the location of the throw keyword.  expr
1671060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // can by null, if the optional expression to throw isn't present.
1681060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
1691060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    Expr(CXXThrowExprClass, Ty), Op(expr), ThrowLoc(l) {}
1701060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
1711060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
1721060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
1731060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual SourceRange getSourceRange() const {
1741060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    if (getSubExpr() == 0)
1751060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek      return SourceRange(ThrowLoc, ThrowLoc);
1761060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
1771060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
1781060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
1791060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
1801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXThrowExprClass;
1811060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
1821060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXThrowExpr *) { return true; }
1831060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
1841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
1851060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_begin();
1861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_end();
1871060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
1881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
1891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
1901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding
1911060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly
1921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters.
1931060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr {
1941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  ParmVarDecl *Param;
1951060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
1961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Param is the parameter whose default argument is used by this
1971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // expression.
1981060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  explicit CXXDefaultArgExpr(ParmVarDecl *param)
1991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    : Expr(CXXDefaultArgExprClass, param->getDefaultArg()->getType()),
2001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek      Param(param) { }
2011060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
2021060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the parameter that the argument was created from.
2031060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const ParmVarDecl *getParam() const { return Param; }
2041060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  ParmVarDecl *getParam() { return Param; }
2051060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
2061060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the actual argument to the function call.
2071060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getExpr() const { return Param->getDefaultArg(); }
2081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getExpr() { return Param->getDefaultArg(); }
2091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
2101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual SourceRange getSourceRange() const {
2111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // Default argument expressions have no representation in the
2121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // source, so they have an empty source range.
2131060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange();
2141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
2151060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
2161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
2171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXDefaultArgExprClass;
2181060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
2191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXDefaultArgExpr *) { return true; }
2201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
2211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
2221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_begin();
2231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_end();
2241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
2251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Serialization
2261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
2271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static CXXDefaultArgExpr* CreateImpl(llvm::Deserializer& D,
2281060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek                                       ASTContext& C);
2291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
230987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
23149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
23249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
23349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// x = int(0.5);
23449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr {
235987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation TyBeginLoc;
236987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
237987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
23849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  CXXFunctionalCastExpr(QualType ty, QualType writtenTy,
23949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor                        SourceLocation tyBeginLoc, Expr *castExpr,
240987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis                        SourceLocation rParenLoc) :
24149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    ExplicitCastExpr(CXXFunctionalCastExprClass, ty, castExpr, writtenTy),
242987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
243987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
244987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
245987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
246987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
247987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
248987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return SourceRange(TyBeginLoc, RParenLoc);
249987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
250987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const Stmt *T) {
251987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return T->getStmtClass() == CXXFunctionalCastExprClass;
252987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
253987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const CXXFunctionalCastExpr *) { return true; }
254987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
255987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  virtual void EmitImpl(llvm::Serializer& S) const;
256987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static CXXFunctionalCastExpr *
257987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis      CreateImpl(llvm::Deserializer& D, ASTContext& C);
258987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
259987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
260987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// CXXZeroInitValueExpr - [C++ 5.2.3p2]
261987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// Expression "T()" which creates a value-initialized Rvalue of non-class
262987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// type T.
263987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis///
264987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidisclass CXXZeroInitValueExpr : public Expr {
265987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation TyBeginLoc;
266987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
267987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
268987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
269987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc,
270987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis                       SourceLocation rParenLoc ) :
271987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    Expr(CXXZeroInitValueExprClass, ty),
272987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
273987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
274987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
275987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
276987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
277987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
278987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return SourceRange(TyBeginLoc, RParenLoc);
279987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
280987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
281987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const Stmt *T) {
282987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return T->getStmtClass() == CXXZeroInitValueExprClass;
283987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
284987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const CXXZeroInitValueExpr *) { return true; }
285987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
286987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // Iterators
287987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  virtual child_iterator child_begin();
288987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  virtual child_iterator child_end();
289987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
290987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  virtual void EmitImpl(llvm::Serializer& S) const;
291987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static CXXZeroInitValueExpr *
292987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis      CreateImpl(llvm::Deserializer& D, ASTContext& C);
293987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
294987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
2959e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis/// CXXConditionDeclExpr - Condition declaration of a if/switch/while/for
2969e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis/// statement, e.g: "if (int x = f()) {...}".
2979e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis/// The main difference with DeclRefExpr is that CXXConditionDeclExpr owns the
2989e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis/// decl that it references.
2999e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis///
3009e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisclass CXXConditionDeclExpr : public DeclRefExpr {
3019e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidispublic:
3029e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  CXXConditionDeclExpr(SourceLocation startLoc,
3039e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis                       SourceLocation eqLoc, VarDecl *var)
3049e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    : DeclRefExpr(CXXConditionDeclExprClass, var, var->getType(), startLoc) {}
3059e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3069e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  virtual void Destroy(ASTContext& Ctx);
3079e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3089e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  SourceLocation getStartLoc() const { return getLocation(); }
3099e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3109e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  VarDecl *getVarDecl() { return cast<VarDecl>(getDecl()); }
3119e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  const VarDecl *getVarDecl() const { return cast<VarDecl>(getDecl()); }
3129e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3139e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
3149e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    return SourceRange(getStartLoc(), getVarDecl()->getInit()->getLocEnd());
3159e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  }
3169e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3179e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  static bool classof(const Stmt *T) {
3189e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    return T->getStmtClass() == CXXConditionDeclExprClass;
3199e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  }
3209e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  static bool classof(const CXXConditionDeclExpr *) { return true; }
3219e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3229e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  // Iterators
3239e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  virtual child_iterator child_begin();
3249e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  virtual child_iterator child_end();
3259e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3269e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  // FIXME: Implement these.
3279e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  //virtual void EmitImpl(llvm::Serializer& S) const;
3289e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  //static CXXConditionDeclExpr *
3299e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  //    CreateImpl(llvm::Deserializer& D, ASTContext& C);
3309e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis};
3319e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
335