
Module: ppl/ppl Branch: floating_point Commit: 743a6e470392137a963641956f7c273b84b04f05 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=743a6e4703921...
Author: Abramo Bagnara abramo.bagnara@gmail.com Date: Wed Jul 28 00:47:30 2010 +0200
Added is and as methods.
---
src/Concrete_Expression.defs.hh | 18 ++++++++++++++++++ src/linearize.hh | 8 ++++---- tests/Concrete_Expression/C_Expr.defs.hh | 1 + 3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/Concrete_Expression.defs.hh b/src/Concrete_Expression.defs.hh index 88fbca8..3bafbbd 100644 --- a/src/Concrete_Expression.defs.hh +++ b/src/Concrete_Expression.defs.hh @@ -123,6 +123,24 @@ public:
//! Returns the kind of * this. Concrete_Expression_Kind kind() const; + + template <template <typename T> class Derived> + bool is() const { + return Concrete_Expression<Target>::kind() == Derived<Target>::KIND; + } + + template <template <typename T> class Derived> + Derived<Target>* as() { + PPL_ASSERT(is<Derived>()); + return static_cast<Derived<Target>*>(this); + } + + template <template <typename T> class Derived> + const Derived<Target>* as() const { + PPL_ASSERT(is<Derived>()); + return static_cast<const Derived<Target>*>(this); + } + };
template <typename Target> diff --git a/src/linearize.hh b/src/linearize.hh index ee8abc1..5fee0da 100644 --- a/src/linearize.hh +++ b/src/linearize.hh @@ -630,7 +630,7 @@ linearize(const Concrete_Expression<Target>& expr, case Floating_Point_Constant<Target>::KIND: { const Floating_Point_Constant<Target>* fpc_expr = - static_cast<const Floating_Point_Constant<Target>* >(&expr); + expr.template as<Floating_Point_Constant>(); result = FP_Linear_Form(FP_Interval_Type(fpc_expr->get_value_as_string())); return true; break; @@ -638,7 +638,7 @@ linearize(const Concrete_Expression<Target>& expr, case Unary_Operator<Target>::KIND: { const Unary_Operator<Target>* uop_expr = - static_cast<const Unary_Operator<Target>* >(&expr); + expr.template as<Unary_Operator>(); switch (uop_expr->unary_operator()) { case Unary_Operator<Target>::UPLUS: return linearize(*(uop_expr->argument()), int_store, lf_store, result); @@ -661,7 +661,7 @@ linearize(const Concrete_Expression<Target>& expr, case Binary_Operator<Target>::KIND: { const Binary_Operator<Target>* bop_expr = - static_cast<const Binary_Operator<Target>* >(&expr); + expr.template as<Binary_Operator>(); switch (bop_expr->binary_operator()) { case Binary_Operator<Target>::ADD: return add_linearize(*bop_expr, int_store, lf_store, result); @@ -692,7 +692,7 @@ linearize(const Concrete_Expression<Target>& expr, case Approximable_Reference<Target>::KIND: { const Approximable_Reference<Target>* ref_expr = - static_cast<const Approximable_Reference<Target>* >(&expr); + expr.template as<Approximable_Reference>(); /* Variable references are the only that we are currently able to analyze */ dimension_type variable_index = ref_expr->associated_dimension(); diff --git a/tests/Concrete_Expression/C_Expr.defs.hh b/tests/Concrete_Expression/C_Expr.defs.hh index 96bc1cd..0391a9c 100644 --- a/tests/Concrete_Expression/C_Expr.defs.hh +++ b/tests/Concrete_Expression/C_Expr.defs.hh @@ -49,6 +49,7 @@ public:
//! Returns the kind of * this. Concrete_Expression_Kind kind() const; + private: //! The expression's kind. C_Expr_Kind expr_kind;