
(This message was sent to the olena-patches list but did not appear in the lrde.olena.patches newsgroup, so I'm posting it again. Sorry for the duplicate message in olena-patches.) https://svn.lrde.epita.fr/svn/oln/trunk/metalic This is just for testing purpose (namely, to see if the new typedef facility works with the old properties). I'm currently working on the new implementation of mlc/properties.hh, described in Théo's presentation from January 2006. Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Add the old properties system. * tests/properties.cc, mlc/to_string.hh: New files. * mlc/properties.hh: New test. mlc/properties.hh | 53 +++++++---------- tests/properties.cc | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+), 29 deletions(-) Index: tests/properties.cc --- tests/properties.cc (revision 0) +++ tests/properties.cc (revision 0) @@ -0,0 +1,160 @@ +#include <ostream> + +#include <mlc/properties.hh> +#include <mlc/to_string.hh> +#include <mlc/cmp.hh> + + +// FIXME: Split this test into several smaller tests? For instance, +// we have to test inheritance, properties/associated types, +// ``external properties'', etc. The best approach is probably to +// browse mlc/properties.hh so as to make a list of the features to be +// checked. + + +namespace my +{ + /*----------------------. + | Namespace equipment. | + `----------------------*/ + + mlc_equip_namespace_with_properties(); + + + /*-----------. + | Typedefs. | + `-----------*/ + + mlc_decl_typedef(ptr_type); + mlc_decl_typedef(foo_type); + mlc_decl_typedef(bar_type); + mlc_decl_typedef(baz_type); + mlc_decl_typedef(quux_type); + + + /*-----------. + | Category. | + `-----------*/ + + // We only use one category here. + namespace category + { + struct my_cat; + } + + template <> + struct set_default_props < category::my_cat > + { + typedef mlc::undefined ptr_type; + }; + + /* FIXME: In the current version of SCOOP 2, this ``packing'' is no + longer done at this stage, but thanks to the `get_types' + mechanism. */ + /// Retrieval of any image type properties (FIXME: say 'packing'). + template <typename T> + struct get_props < category::my_cat, T > + { + typedef char ptr_type; + + // FIXME: Same remark as in the above FIXME: this echo() method + // should be place lower in the prop/type hierarchy. + static void echo(std::ostream& ostr) + { + ostr << "props_of( oln::category::point, " + << mlc_to_string(T) << " ) =" << std::endl + << "{" << std::endl + << "\t ptr_type = " << mlc_to_string(ptr_type) << std::endl + << "}" << std::endl; + } + + static void ensure() + { + mlc::is_ok< ptr_type >::ensure(); + } + }; + +} + +// Helper macro. +#define my_type_of_(FromType, Alias) \ + mlc_type_of_(my, my::category::my_cat, FromType, Alias) + +namespace my +{ + /*----. + | A. | + `----*/ + + // Forward declaration. + struct A; + + // FIXME: Rename as set_types<> when mlc/properties.hh is updated. + // Associated types. + template<> + struct set_props<category::my_cat, my::A> + { + typedef int foo_type; + typedef float bar_type; + typedef mlc::undefined baz_type; + }; + + class A + { + // Aliases. + typedef my_type_of_(A, foo) foo_type; + typedef my_type_of_(A, bar) bar_type; + typedef my_type_of_(A, baz) baz_type; + }; + + + /*------------. + | B ---|> A. | + `------------*/ + + // Forward declaration. + struct B; + + // FIXME: Is there any `set_super_type(T)'' sugar available? + template<> + struct set_super_type<my::B> + { + typedef A ret; + }; + + template<> + struct set_props<category::my_cat, B> + { + // Note: foo_type is untouched here. + + // A type redefined here. + typedef double bar_type; + // A type defined here (but declared abstract in the super class). + typedef char baz_type; + // A type defined only here (and not in the super class). + typedef long quux_type; + }; + + // FIXME: Is there any `set_super_type(T)'' sugar available? + class B : public internal::get_super_type<B> + { + // Aliases. + typedef my_type_of_(B, foo) foo_type; + typedef my_type_of_(B, bar) bar_type; + typedef my_type_of_(B, baz) baz_type; + typedef my_type_of_(B, quux) quux_type; + }; +} + +int +main() +{ + // Check associated types. + mlc_eq(my::A::foo_type, int)::ensure (); + mlc_eq(my::A::bar_type, float)::ensure (); + + // Check associated types. + mlc_neq(my::B::bar_type, my::A::bar_type)::ensure (); + mlc_eq(my::B::baz_type, char)::ensure (); + mlc_eq(my::B::quux_type, long)::ensure (); +} Index: mlc/properties.hh --- mlc/properties.hh (revision 0) +++ mlc/properties.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2005 EPITA Research and Development Laboratory +// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,26 +28,21 @@ #ifndef METALIC_PROPERTIES_HH # define METALIC_PROPERTIES_HH -# include <mlc/types.hh> +# include <mlc/flags.hh> # include <mlc/typedef.hh> # include <mlc/bool.hh> -# include <mlc/implies.hh> # include <mlc/cmp.hh> # include <mlc/if.hh> # include <mlc/is_a.hh> +# include <mlc/implies.hh> - -// this is an internal macro -# define mlc_internal_get_typedef_(FromType, TypedefType) \ - typename internal::get_typedef <FromType, TypedefType> ::ret - +// Note: TypedefName must be of the form `typedef_::foo'. +# define mlc_internal_get_typedef_(Type, TypedefName) \ + typename TypedefName::template from_< Type >::ret # define mlc_equip_namespace_with_properties() \ \ - mlc_equip_namespace_with_typedef(); \ - mlc_decl_typedef(ret); \ - \ template <template <typename> class abstraction> \ struct is_a \ { \ @@ -61,13 +56,13 @@ template <typename type, unsigned i = 0> \ struct set_super_type \ { \ - typedef mlc::no_type ret; \ + typedef mlc::none ret; \ }; \ \ template <typename type, unsigned i = 0> \ struct set_category \ { \ - typedef mlc::no_type ret; \ + typedef mlc::none ret; \ }; \ \ template <typename category> \ @@ -122,10 +117,10 @@ typedef mlc_internal_get_typedef_(get_default_props<category>, \ typedef_type) prop_type; \ \ - mlc::implies< mlc::neq< mlc_typedef_of(super_type, ret), \ - mlc::internal::not_found >, \ - mlc::eq< prop_type, \ - mlc::internal::not_found > >::ensure(); \ + mlc::implies_< mlc::neq_< mlc_ret(super_type), \ + mlc::not_found >, \ + mlc::eq_< prop_type, \ + mlc::not_found > >::ensure(); \ } \ }; \ \ @@ -137,7 +132,7 @@ typedef mlc_internal_get_typedef_(props, typedef_type) prop; \ \ typedef typename \ - mlc::if_< mlc::neq< prop, mlc::internal::not_found >, \ + mlc::if_< mlc::neq_< prop, mlc::not_found >, \ prop, \ typename f_rec_get_prop< category, \ typename get_super_type<from_type, 0>::ret, \ @@ -146,14 +141,14 @@ }; \ \ template <typename category, typename typedef_type> \ - struct f_rec_get_prop <category, mlc::no_type, typedef_type> \ + struct f_rec_get_prop <category, mlc::none, typedef_type> \ { \ typedef mlc_internal_get_typedef_(get_default_props<category>, \ typedef_type) ret; \ ~f_rec_get_prop() \ { \ - mlc::and_< mlc::neq< ret, mlc::internal::not_found >, \ - mlc::neq< ret, mlc::undefined_type > >::ensure(); \ + mlc::and_< mlc::neq_< ret, mlc::not_found >, \ + mlc::neq_< ret, mlc::undefined > >::ensure(); \ } \ }; \ \ @@ -162,10 +157,10 @@ struct f_rec_get_type \ { \ typedef get_type<category, from_type, typedef_type> client_type; \ - typedef mlc_typedef_of(client_type, ret) type; \ + typedef mlc_ret(client_type) type; \ \ typedef typename \ - mlc::if_< mlc::neq< type, mlc::internal::not_found >, \ + mlc::if_< mlc::neq_< type, mlc::not_found >, \ type, \ typename f_rec_get_type< category, \ typename get_super_type<from_type, 0>::ret, \ @@ -174,9 +169,9 @@ }; \ \ template <typename category, typename typedef_type> \ - struct f_rec_get_type <category, mlc::no_type, typedef_type> \ + struct f_rec_get_type <category, mlc::none, typedef_type> \ { \ - typedef mlc::internal::not_found ret; \ + typedef mlc::not_found ret; \ }; \ \ template <typename category, typename from_type, typename typedef_type> \ @@ -196,7 +191,7 @@ \ ~f_get_type() \ { \ - mlc::implies< mlc::is_found<default_prop>, \ + mlc::implies_< mlc::is_found<default_prop>, \ mlc::is_not_found<type> >::ensure(); \ mlc::xor_< mlc::is_found<prop>, \ mlc::is_found<type> >::ensure(); \ @@ -206,7 +201,7 @@ prop, \ typename mlc::if_< mlc::is_ok<type>, \ type, \ - mlc::internal::not_ok \ + mlc::not_ok \ > ::ret \ > ::ret ret; \ }; \ @@ -220,12 +215,12 @@ # define mlc_type_of_(Namespace, Category, FromType, Alias) \ Namespace::internal::f_get_type<Category, \ FromType, \ - Namespace::internal::typedef_::Alias##_type>::ret + Namespace::typedef_::Alias##_type>::ret # define mlc_type_2_of_(Namespace, Category, FromType,_2, Alias) \ Namespace::internal::f_get_type<Category, \ FromType,_2, \ - Namespace::internal::typedef_::Alias##_type>::ret + Namespace::typedef_::Alias##_type>::ret # define mlc_type_of(Namespace, Category, FromType, Alias) \