https://svn.lrde.epita.fr/svn/oln/trunk/static
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Rename some Static entities.
* stc/properties.hh (typeof_): Rename class as...
(type_of_): ...this.
(stc::is_a): Rename class as...
(stc::abstraction_as_type): ...this.
(stc_typeof, stc_typeof_, stc_typeof_in_namespace)
(stc_typeof_in_namespace_): Rename macros as...
(stc_local_type_of, stc_local_type_of_, stc_type_of)
(stc_type_of_): ...these.
* tests/properties.cc: Adjust test.
* tests/entry.cc: Typos in comments.
stc/properties.hh | 41 ++++++++++++++++++++++-------------------
tests/entry.cc | 8 ++++----
tests/properties.cc | 2 +-
3 files changed, 27 insertions(+), 24 deletions(-)
Index: tests/properties.cc
--- tests/properties.cc (revision 471)
+++ tests/properties.cc (working copy)
@@ -38,7 +38,7 @@
typename my_type_of_(FromType, Typedef)
#define my_type_of_(FromType, Typedef) \
- stc_typeof_(my::category::my_cat, FromType, Typedef)
+ stc_local_type_of_(my::category::my_cat, FromType, Typedef)
namespace my
{
Index: tests/entry.cc
--- tests/entry.cc (revision 471)
+++ tests/entry.cc (working copy)
@@ -158,7 +158,7 @@
// Test.
public mlc::where_< mlc_is_a(prop1_type, int) >
{
- // Super class if test succeed.
+ // Super class if test succeeds.
typedef property1a ret;
};
@@ -167,7 +167,7 @@
// Test.
public mlc::where_< mlc_is_a(prop1_type, long) >
{
- // Super class if test succeed.
+ // Super class if test succeeds.
typedef property1b ret;
};
@@ -208,7 +208,7 @@
// Test.
public mlc::where_< mlc_is_a(prop2_type, float) >
{
- // Super class if test succeed.
+ // Super class if test succeeds.
typedef property2a ret;
};
@@ -217,7 +217,7 @@
// Test.
public mlc::where_< mlc_is_a(prop2_type, double) >
{
- // Super class if test succeed.
+ // Super class if test succeeds.
typedef property2b ret;
};
Index: stc/properties.hh
--- stc/properties.hh (revision 471)
+++ stc/properties.hh (working copy)
@@ -88,7 +88,7 @@
};
/// \}
-}
+} // end of namespace mlc
/*------------.
@@ -376,7 +376,7 @@
/* FIXME: Don't query from_type directly, but exact_type(from_type) */ \
/* instead. We need mlc::any for this. */ \
template <typename category, typename from_type, typename typedef_type> \
- struct typeof_ \
+ struct type_of_ \
{ \
/* Look for the typedef as an external type. */ \
typedef typename \
@@ -410,7 +410,7 @@
/// Allow the manipulation of an abstraction (i.e., a template type)
/// as a plain type.
template <template <typename> class abstraction>
- struct is_a
+ struct abstraction_as_type
{
template <typename E>
struct instantiated_with
@@ -418,7 +418,7 @@
typedef abstraction<E> ret;
};
};
-}
+} // end of namespace stc
/*---------.
@@ -469,27 +469,30 @@
# define stc_pseudosuper_(T) \
set_pseudosuper_type<T>::ret
-// FIXME: s/stc_typeof/stc_type_of/.
-
-/// Get the property \a Typedef from \a FromType (version to be used
-/// inside a template).
-#define stc_typeof(Category, FromType, Typedef) \
- typename stc_typeof_(Category, FromType, Typedef)
-
-/// Get the property \a Typedef from \a FromType (version to be used
-/// outside a template).
-#define stc_typeof_(Category, FromType, Typedef) \
- typeof_<Category, FromType, typedef_:: Typedef##_type >::ret
+// FIXME: Perhaps only ``external'' (i.e., non local) versions of
+// stc_type_of are really useful (since they are more precise), and we
+// could get rid of local versions (stc_local_type_of and
+// stc_local_type_of_).
+
+/// Get the property \a Typedef, declared in the current namespace,
+/// from \a FromType (version to be used inside a template).
+#define stc_local_type_of(Category, FromType, Typedef) \
+ typename stc_type_of_(Category, FromType, Typedef)
+
+/// Get the property \a Typedef, declared in the current namespace,
+/// from \a FromType (version to be used outside a template).
+#define stc_local_type_of_(Category, FromType, Typedef) \
+ type_of_<Category, FromType, typedef_:: Typedef##_type >::ret
/// Get the property \a Typedef, declared in \a Namespace, from \a
/// FromType (version to be used inside a template).
-#define stc_typeof_in_namespace(Namespace, Category, FromType, Typedef) \
- typename stc_typeof_in_namespace_(Namespace, Category, FromType, Typedef)
+#define stc_type_of(Namespace, Category, FromType, Typedef) \
+ typename stc_type_of_(Namespace, Category, FromType, Typedef)
/// Get the property \a Typedef, declared in \a Namespace, from \a
/// FromType (version to be used outside a template).
-#define stc_typeof_in_namespace_(Namespace, Category, FromType, Typedef) \
- Namespace::typeof_<Category, FromType, \
+#define stc_type_of_(Namespace, Category, FromType, Typedef) \
+ Namespace::type_of_<Category, FromType, \
Namespace::typedef_:: Typedef##_type >::ret
#endif // ! STATIC_PROPERTIES_HH
https://svn.lrde.epita.fr/svn/oln/trunk/static
This is currently a workaround inside Static, but it would be better
to let Metalic deal with this instead.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Allow the use of Metalic values as virtual types.
* stc/properties.hh (mlc::eqv, mlc::neqv): New (workaround)
classes.
(mlc_eqv, mlc_neqv): New macros.
(rec_get_vtype, rec_get_ext_vtype): Use them, to allow the use of
Metalic values as virtual types.
* tests/properties.cc: Ensure Metalic values can be valid
virtual types.
stc/properties.hh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++----
tests/properties.cc | 18 +++++++++++++--
2 files changed, 70 insertions(+), 7 deletions(-)
Index: tests/properties.cc
--- tests/properties.cc (revision 468)
+++ tests/properties.cc (working copy)
@@ -28,6 +28,7 @@
#include <stc/properties.hh>
#include <mlc/cmp.hh>
#include <mlc/assert.hh>
+#include <mlc/int.hh>
// This test focuses on the virtual types system, so the exact type of
// classes is not propagated here (stc::any is not used).
@@ -82,8 +83,13 @@
template<>
struct vtypes<category::my_cat, my::A>
{
+ // A native type.
typedef int foo_type;
- typedef float bar_type;
+ // A Metalic value, used here is to ensure that
+ // mlc::abstract::values are accepted as virtual types, as well as
+ // any other type).
+ typedef mlc::int_<42> bar_type;
+ // An undefined type.
typedef mlc::undefined baz_type;
};
@@ -212,10 +218,16 @@
{
// Check types associated to A.
mlc::assert_<mlc_eq(my::A::foo_type, int)>::check();
- mlc::assert_<mlc_eq(my::A::bar_type, float)>::check();
+ /* FIXME: Note that we use mlc_eqv, not mlc_eq, since the latter
+ doesn't accept Metalic values. Try to get rid of this
+ limitation. */
+ mlc::assert_<mlc_eqv(my::A::bar_type, mlc::int_<42>)>::check();
// Check types associated to B.
- mlc::assert_<mlc_neq(my::B::bar_type, my::A::bar_type)>::check();
+ /* FIXME: Note that we use mlc_neqv, not mlc_neq, since the latter
+ doesn't accept Metalic values. Try to get rid of this
+ limitation. */
+ mlc::assert_<mlc_neqv(my::B::bar_type, my::A::bar_type)>::check();
mlc::assert_<mlc_eq(my::B::baz_type, char)>::check();
mlc::assert_<mlc_eq(my::B::quux_type, long)>::check();
mlc::assert_<mlc_eq(my::B::yin_type, unsigned long)>::check();
Index: stc/properties.hh
--- stc/properties.hh (revision 468)
+++ stc/properties.hh (working copy)
@@ -42,6 +42,55 @@
# include <mlc/is_a.hh>
+/*----------------------.
+| Metalic workarounds. |
+`----------------------*/
+
+/// Shortcuts.
+/// \{
+# define mlc_eqv( T1, T2) mlc::eqv_ <T1, T2>
+# define mlc_neqv(T1, T2) mlc::neqv_<T1, T2>
+/// \}
+
+namespace mlc
+{
+ /* FIXME: This really is a work around Metalic's limitations
+ regarding the operands of its logic operators than cannot be
+ subtypes of mlc::abstract::value. This limitations breaks Static
+ when a virtual type *is* a Metalic value! Hence the introduction
+ of this more laxist version of mlc_neq. */
+
+ /// Equality test between a couple of types, also accepting Metalic
+ /// values (i.e., subtypes of mlc::abstract::value).
+ /// \{
+ template <typename T1, typename T2>
+ struct eqv_ : public bexpr_<false>
+ {
+ };
+
+ template <typename T>
+ struct eqv_ <T, T> : public bexpr_<true>
+ {
+ };
+ /// \}
+
+ /// Inequality test between a couple of types, also accepting Metalic
+ /// values (i.e., subtypes of mlc::abstract::value).
+ /// \{
+ template <typename T1, typename T2>
+ struct neqv_ : public bexpr_<true>
+ {
+ };
+
+ template <typename T>
+ struct neqv_ <T, T> : public bexpr_<false>
+ {
+ };
+ /// \}
+
+}
+
+
/*------------.
| Equipment. |
`------------*/
@@ -159,7 +208,7 @@
\
typedef typename \
mlc::if_< \
- mlc::neq_< type, mlc::not_found >, \
+ mlc::neqv_< type, mlc::not_found >, \
/* then */ \
/* return it */ \
/* (the typedef has been found in the vtypes */ \
@@ -169,7 +218,7 @@
/* check if the vtype of the `super' of FROM_TYPE */ \
/* has the typedef */ \
typename \
- mlc::if_< mlc::neq_< typename rec_get_vtype< category, \
+ mlc::if_< mlc::neqv_< typename rec_get_vtype<category, \
super, \
typedef_type >::ret, \
mlc::not_found >, \
@@ -227,7 +276,7 @@
\
typedef typename \
mlc::if_< \
- mlc::neq_< type, mlc::not_found >, \
+ mlc::neqv_< type, mlc::not_found >, \
/* then */ \
/* return it */ \
/* (the typedef has been found in the vtypes */ \
@@ -237,7 +286,7 @@
/* check if the vtype of the `super' of FROM_TYPE */ \
/* has the typedef */ \
typename \
- mlc::if_< mlc::neq_< typename rec_get_ext_vtype< category, \
+ mlc::if_< mlc::neqv_< typename rec_get_ext_vtype<category, \
super, \
typedef_type >::ret, \
mlc::not_found >, \
@@ -420,6 +469,8 @@
# define stc_pseudosuper_(T) \
set_pseudosuper_type<T>::ret
+// FIXME: s/stc_typeof/stc_type_of/.
+
/// Get the property \a Typedef from \a FromType (version to be used
/// inside a template).
#define stc_typeof(Category, FromType, Typedef) \