
https://svn.lrde.epita.fr/svn/oln/trunk/static Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Set the pseudosuper link using a separate class instead of an internal virtual type. * stc/properties.hh (stc_equip_namespace_with_properties): Generate a set_pseudosuper_type struct. Use it to get the pseudosuper links in recursive vtype retrieval algorithms. (stc_set_pseudosuper, stc_pseudosuper, stc_pseudosuper_): New macros. * tests/properties.cc: Adjust. stc/properties.hh | 46 +++++++++++++++++++++++++++++++++++++--------- tests/properties.cc | 20 +++++++------------- 2 files changed, 44 insertions(+), 22 deletions(-) Index: tests/properties.cc --- tests/properties.cc (revision 425) +++ tests/properties.cc (working copy) @@ -118,24 +118,18 @@ // Forward declaration. struct C; - // C do not derive from B, but we want its vtypes to ``inherit'' - // from B's vtypes (see the specilization - // vtypes<category::my_cat, C>. + // C doesn't derive from B, but we want its vtypes to ``inherit'' + // from B's vtypes (see the specialization + // types<category::my_cat, C>). + + // Warning, this sugar might me remove from properties.hh. + /// Link to B (``pseudo'' inheritance). + stc_set_pseudosuper(C, B); /// Types associated to my::C. template<> struct vtypes<category::my_cat, C> { - // FIXME: Having this link here is not elegant when you consider - // ext_vtype<>: this means that even if you have only a vtype - // declared as ext_vtype, you'll still have to define a - // corresponding vtypes<>, at least to define the pseudosuper - // class. What about externalizing this information, maybe with - // set_pseudosuper_type<>, and a macro set_pseudosuper() as sugar? - - /// Link to B (``pseudo'' inheritance). - typedef B pseudosuper_type; - // A type defined only here (and not in the super class). typedef double zorg_type; }; Index: stc/properties.hh --- stc/properties.hh (revision 425) +++ stc/properties.hh (working copy) @@ -72,6 +72,17 @@ }; \ \ \ + /* ------------------------ */ \ + /* ``Pseudo'' inheritance. */ \ + /* ------------------------ */ \ + \ + template <typename type> \ + struct set_pseudosuper_type \ + { \ + typedef mlc::none ret; \ + }; \ + \ + \ /* --------------- */ \ /* Virtual types. */ \ /* --------------- */ \ @@ -137,8 +148,7 @@ /** Implicit parent (i.e. super), if any. */ \ typedef stc_super(from_type) super; \ /** Pseudosuper class, if any. */ \ - typedef stc_internal_get_typedef(types, typedef_::pseudosuper_type) \ - pseudosuper; \ + typedef stc_pseudosuper(from_type) pseudosuper; \ \ typedef typename \ mlc::if_< \ @@ -206,11 +216,7 @@ /** Implicit parent (i.e. super), if any. */ \ typedef stc_super(from_type) super; \ /** Pseudosuper class, if any. */ \ - /* FIXME: Looking for this information is not elegant. Have a */ \ - /* look at static/tests/properties.cc for a better suggestion. */ \ - typedef vtypes<category, from_type> types; \ - typedef stc_internal_get_typedef(types, typedef_::pseudosuper_type) \ - pseudosuper; \ + typedef stc_pseudosuper(from_type) pseudosuper; \ \ typedef typename \ mlc::if_< \ @@ -343,8 +349,10 @@ | Macros. | `---------*/ -/* FIXME: I don't know this macro will be really usable; what if T is - a template class? */ +/* FIXME: I don't know whether this macro will be really usable; what + if Type is a template class? We would have to provide additional + versions of this macro, with support for one parameter, two + parameters, etc. */ /// \def Declare the immediate base class \a Super of \a Type. # define stc_set_super(Type, Super) \ template <> \ @@ -353,6 +361,18 @@ typedef Super ret; \ } +/* FIXME: I don't know whether this macro will be really usable; what + if Type is a template class? We would have to provide additional + versions of this macro, with support for one parameter, two + parameters, etc. */ +/// \def Declare the pseudosuper class \a PseudoSuper of \a Type. +# define stc_set_pseudosuper(Type, PseudoSuper) \ + template <> \ + struct set_pseudosuper_type<Type> \ + { \ + typedef PseudoSuper ret; \ + } + /// \def Get the immediate base class of T (version with typename). # define stc_super(T) \ typename set_super_type<T>::ret @@ -361,6 +381,14 @@ # define stc_super_(T) \ set_super_type<T>::ret +/// \def Get the pseudosuper class of T (version with typename). +# define stc_pseudosuper(T) \ + typename set_pseudosuper_type<T>::ret + +/// \def Get the pseudosuper class of T (version without typename). +# define stc_pseudosuper_(T) \ + set_pseudosuper_type<T>::ret + /// Get the property \a Typedef from \a FromType (version with typename). #define stc_typeof(Category, FromType, Typedef) \ typename typeof_<Category, FromType, typedef_:: Typedef##_type >::ret