From b91fa0e386669e120f7f65cd29ec6f505414dc0d Mon Sep 17 00:00:00 2001 From: Alexandre Bique Date: Fri, 10 Apr 2009 11:34:40 +0100 Subject: [PATCH] added a cast-simplifie but i don't think that's the right way. --- src/ozulis/generators/data.cc | 23 ++++++++++++--------- src/ozulis/visitors/cast-simplifier.cc | 37 ++++++++++++++++++++++++++++++++++ src/ozulis/visitors/cast-simplifier.hh | 29 ++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 src/ozulis/visitors/cast-simplifier.cc create mode 100644 src/ozulis/visitors/cast-simplifier.hh diff --git a/src/ozulis/generators/data.cc b/src/ozulis/generators/data.cc index ca1ab05..8dfc3c0 100644 --- a/src/ozulis/generators/data.cc +++ b/src/ozulis/generators/data.cc @@ -174,7 +174,7 @@ const ag::Node ag::nodes[] = { } }, - {"CastBoolToIntExp", "CastExp", "A cast from bool to int", { + {"CastBoolToIntegerExp", "CastExp", "A cast from bool to integer", { {"", ""} } }, @@ -189,32 +189,32 @@ const ag::Node ag::nodes[] = { } }, - {"CastIntToBoolExp", "CastExp", "A cast from int to bool", { + {"CastIntegerToBoolExp", "CastExp", "A cast from integer to bool", { {"", ""} } }, - {"CastIntToIntExp", "CastExp", "A cast from int to int", { + {"CastIntegerToIntegerExp", "CastExp", "A cast from integer to integer", { {"", ""} } }, - {"CastIntToFloatExp", "CastExp", "A cast from int to float", { + {"CastIntegerToFloatExp", "CastExp", "A cast from integer to float", { {"", ""} } }, - {"CastIntToDoubleExp", "CastExp", "A cast from int to double", { + {"CastIntegerToDoubleExp", "CastExp", "A cast from integer to double", { {"", ""} } }, - {"CastIntToPointerExp", "CastExp", "A cast from int to pointer", { + {"CastIntegerToPointegererExp", "CastExp", "A cast from integer to pointer", { {"", ""} } }, - {"CastFloatToIntExp", "CastExp", "A cast from float to int", { + {"CastFloatToIntegerExp", "CastExp", "A cast from float to integer", { {"", ""} } }, @@ -224,7 +224,7 @@ const ag::Node ag::nodes[] = { } }, - {"CastDoubleToIntExp", "CastExp", "A cast from double to int", { + {"CastDoubleToIntegerExp", "CastExp", "A cast from double to integer", { {"", ""} } }, @@ -234,7 +234,12 @@ const ag::Node ag::nodes[] = { } }, - {"CastPointerToIntExp", "CastExp", "A cast from pointer to int", { + {"CastPointegererToIntegerExp", "CastExp", "A cast from pointer to integer", { + {"", ""} + } + }, + + {"CastPointegererToPointerExp", "CastExp", "A cast from pointer to pointer", { {"", ""} } }, diff --git a/src/ozulis/visitors/cast-simplifier.cc b/src/ozulis/visitors/cast-simplifier.cc new file mode 100644 index 0000000..dcf9c94 --- /dev/null +++ b/src/ozulis/visitors/cast-simplifier.cc @@ -0,0 +1,37 @@ +#include "cast-simplifier.hh" + +namespace ozulis +{ + namespace visitors + { + CastSimplifier::CastSimplifier() + : core::DispatchTable (), + core::Singleton () + { + } + +#define DUMMY_CAST(Type) \ + static ast::Exp * simplify##Type##To##Type(ast::CastExp & cast) \ + { \ + return cast.exp; \ + } + + DUMMY_CAST(Bool) + DUMMY_CAST(Float) + DUMMY_CAST(Double) + + void + CastSimplifier::init() + { +#define ADD_ENTRY(Type1, Type2) \ + addEntry(simplify##Type1##To##Type2, \ + ast::Type1##Type::nodeTypeId(), \ + ast::Type2##Type::nodeTypeId()) + + ADD_ENTRY(Bool, Bool); + ADD_ENTRY(Float, Float); + ADD_ENTRY(Double, Double); + } + } +} diff --git a/src/ozulis/visitors/cast-simplifier.hh b/src/ozulis/visitors/cast-simplifier.hh new file mode 100644 index 0000000..45861ae --- /dev/null +++ b/src/ozulis/visitors/cast-simplifier.hh @@ -0,0 +1,29 @@ +#ifndef CORE_CAST_SIMPLIFIER_HH +# define CORE_CAST_SIMPLIFIER_HH + +# include +# include +# include + +namespace ozulis +{ + namespace visitors + { + class CastSimplifier : + public core::DispatchTable, + public core::Singleton + { + public: + CastSimplifier(); + + /** @brief used to initialize the dispatch table. + * You should not call it. Singleton will do it. */ + void init(); + /** @brief will simplify a cast */ + static ast::Exp * simplify(ast::CastExp & cast); + }; + } +} + +#endif /* !CORE_CAST_SIMPLIFIER_HH */ -- 2.11.4.GIT