https://svn.lrde.epita.fr/svn/oln/trunk/static
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add a deferred vtype lookup mechanism to scoop-alt.
* stc/scoop-alt.hh (deferred): New declaration.
(stc_find_type_in_, stc_find_type_in)
(stc_is_found_type, stc_is_not_found_type): New macros.
(stc_is_a): Rely on stc_find_type, not stc_deferred.
(stc_using_): New macro.
(stc_deferred): Rely on stc::deferred<>, not deferred_vtype<>.
(stc_deferred_from): New macro.
* stc/scoop-alt.inc (find_vtype): New forward declaration.
(direct_): New unwrapping mechanism.
(find_vtype): Use it.
* tests/scoop-alt.cc (ex9): Add a Point concept (interface).
Fix this test case.
stc/scoop-alt.hh | 47 +++++++++++++++++++++++++++----
stc/scoop-alt.inc | 44 +++++++++++++++++++++++++++--
tests/scoop-alt.cc | 80 ++++++++++++++++++++++++++++++++++++++++++-----------
3 files changed, 148 insertions(+), 23 deletions(-)
Index: tests/scoop-alt.cc
--- tests/scoop-alt.cc (revision 1016)
+++ tests/scoop-alt.cc (working copy)
@@ -734,6 +734,28 @@
// FIXME: I (Roland) don't know why this test succeeds, while the
// equivalent SCOOP 2 hierarchy doesn't work in Olena.
+
+ /*--------.
+ | Point. |
+ `--------*/
+
+ // Forward declaration.
+ namespace ex9
+ {
+ template <typename Exact>
+ struct Point
+ {
+ stc_typename(grid);
+ stc_typename(dim);
+
+ enum { n = mlc_value(dim) };
+
+ }; // end of oln::Point<Exact>
+
+ }
+
+
+
/*------------------------.
| internal::point_base_. |
`------------------------*/
@@ -751,6 +773,8 @@
template <typename Exact>
struct super_trait_< ex9::internal::point_base_<Exact> >
{
+ // super_trait_ set to stc::none, since Point is a concept
+ // (interface).
typedef stc::none ret;
};
@@ -761,8 +785,8 @@
typedef stc::abstract grid;
typedef stc_deferred(grid) grid__;
- typedef stc::final<stc_type(grid__, dim)> dim;
-
+ typedef stc_deferred_from(grid__, dim) dim__;
+ typedef stc::final< dim__ > dim;
};
// Actual definition.
@@ -773,7 +797,9 @@
template <typename Exact>
struct point_base_ : public stc::none
{
- stc_typename(dim);
+ typedef Point<Exact> super;
+
+ stc_using(dim);
static const unsigned dim_val = mlc_value(dim);
};
} // end of namespace my::ex9::internal
@@ -784,19 +810,41 @@
| internal::point2d_. |
`---------------------*/
- // FIXME: Add internal::point2d_, as in Olena, and check whether
- // this addition triggers the same behavior observed in Olena.
+ namespace ex9
+ {
+ // Forward declarations.
+ namespace internal
+ {
+ template <typename Exact> struct point2d_;
+ }
+ }
+
+ /// Super type.
+ template<typename Exact>
+ struct super_trait_< ex9::internal::point2d_<Exact> >
+ {
+ typedef ex9::internal::point_base_<Exact> ret;
+ };
-// namespace ex9
-// {
-// // Forward declarations.
-// namespace internal
-// {
-// template <typename Exact> struct point2d_;
-// }
-// }
+ /// Virtual types associated to internal::point2d_<Exact>.
+ template <typename Exact>
+ struct vtypes< ex9::internal::point2d_<Exact> >
+ {
+ };
- // ...
+ namespace ex9
+ {
+ // Actual definition.
+ namespace internal
+ {
+
+ template <typename Exact>
+ struct point2d_ : public point_base_<Exact>
+ {
+ typedef point_base_<Exact> super;
+ };
+ }
+ }
/*---------.
@@ -846,7 +894,7 @@
template <>
struct super_trait_< ex9::point2d >
{
- typedef ex9::internal::point_base_<ex9::point2d> ret;
+ typedef ex9::internal::point2d_<ex9::point2d> ret;
};
@@ -860,7 +908,7 @@
// Actual definition.
namespace ex9
{
- struct point2d : public internal::point_base_< point2d >
+ struct point2d : public internal::point2d_< point2d >
{
};
}
Index: stc/scoop-alt.hh
--- stc/scoop-alt.hh (revision 1016)
+++ stc/scoop-alt.hh (working copy)
@@ -64,11 +64,16 @@
struct not_found;
#endif
typedef mlc::not_found not_found;
+ // FIXME: Document all these tags!
struct abstract;
struct not_delegated;
struct not_delegated_abstract;
template <typename T> struct final;
+ // Deferred vtype lookup.
+ // FIXME: Document.
+ template <typename Source, typename Target> struct deferred;
+
template < template <class> class category >
struct is;
@@ -131,6 +136,8 @@
// FIXME: Document all these macros.
+// FIXME: Consistency: stc_type vs vtype<>.
+
/// Access to associated type.
/// \{
# define stc_type_(Source, Target) vtype<Source, typedef_::Target>::ret
@@ -150,46 +157,76 @@
/// \}
+// FIXME: Consistency: stc_find_type vs find_vtype<>.
+
/// Likewise, but more tolerant.
/// \{
# define stc_find_type_(Source, Target) \
find_vtype<Source, typedef_::Target>::ret
# define stc_find_type(Source, Target) \
typename stc_find_type_(Source, Target)
+
+# define stc_find_type_in_(Namespace, Source, Target) \
+ Namespace::find_vtype<Source, Namespace::typedef_::Target>::ret
+# define stc_find_type_in(Namespace, Source, Target) \
+ typename stc_find_type_in_(Namespace, Source, Target)
+
+
/// \}
/// Boolean expression counterpart of stc_find_type
/// \{
# define stc_type_is_found(Target) \
- stc::is_found< stc_deferred(Target) >
+ stc::is_found< stc_find_type(Exact, Target) >
# define stc_type_is_not_found(Target) \
- stc::is_not_found< stc_deferred(Target) >
+ stc::is_not_found< stc_find_type(Exact, Target) >
+
+# define stc_is_found_type(From, Type) \
+ stc::is_found< stc_deferred_type(From, Type) >
+# define stc_is_not_found_type(From, Type) \
+ stc::is_not_found< stc_deferred_type(From, Type) >
/// \}
+// FIXME: Using stc_deferred here (in scoop-alt) is probably nonsense.
+// We probably ought to introduce another macro for stc_deferred /
+// stc_deferred_from (and try to stick as much as possible to its
+// initial meaning); something like stc_deferred_def /
+// stc_deferred_def_from.
+# if 0
# define stc_is_a(T, U) \
mlc::wrap_< \
typename mlc::is_a_< sizeof(mlc::form::of< U >()) > \
::template ret< typename mlc::basic_< stc_deferred(T) >::ret, U > \
+#endif
+
+# define stc_is_a(T, U) \
+ mlc::wrap_< \
+ typename mlc::is_a_< sizeof(mlc::form::of< U >()) > \
+ ::template ret< typename mlc::basic_< stc_find_type(Exact, T) >::ret, U
> \
+ >
+
/// For concepts.
/// \{
# define stc_typename(Target) typedef stc_type(Exact, Target) Target
# define stc_using(Target) typedef typename super::Target Target
+# define stc_using_(Target) typedef super::Target Target
# define stc_using_from(Abstraction, Target) \
typedef typename Abstraction<Exact>::Target Target
+// FIXME: Might be renamed as stc_typename_from for consistency purpose.
# define stc_deduce_typename(Src, Target) typedef stc_type(Src, Target) Target
/// \}
/// For implementation classes.
/// \{
-/// Dummy
# define stc_deferred(Target) \
- stc_find_type(Exact, Target)
-// typename deferred_vtype<Exact, typedef_::Target >::ret
+ stc::deferred<Exact, typedef_::Target>
+# define stc_deferred_from(Source, Target) \
+ stc::deferred<Source, typedef_::Target>
# define stc_lookup(Target) \
typedef typename vtype< stc_type(current, exact_type), \
typedef_::Target>::ret Target
Index: stc/scoop-alt.inc
--- stc/scoop-alt.inc (revision 1016)
+++ stc/scoop-alt.inc (working copy)
@@ -614,6 +614,10 @@
/* ----------------------------------------------------------- find. */
+/* Forward declaration. */
+template <typename source, typename target> struct find_vtype;
+
+/* Unwrap the result. */
namespace find_
{
/* Forward declaration. */
@@ -660,14 +664,49 @@
} /* End of namespace find_. */
+/* Evaluate the result, removing any deferred tag. */
+namespace direct_
+{
+ /* Forward declaration. */
+ template <typename T> struct match_with;
+
+ /* One-layer deferred type.. */
+ template <typename Source, typename Target>
+ struct match_with< stc::deferred<Source, Target> >
+ {
+ /* Get direct definitions of Source and Target. */
+ typedef typename direct_::match_with<Source>::ret direct_source;
+ typedef typename direct_::match_with<Target>::ret direct_target;
+
+ /* Resolve the virtual type. */
+ typedef typename find_vtype<direct_source, direct_target>::ret res;
+
+ /* Re-lauch the direct process, in case the previous result was
+ itself a postponed virtual type definition. */
+ typedef typename direct_::match_with<res>::ret ret;
+ };
+
+
+ /* Default version. */
+ template <typename T>
+ struct match_with
+ {
+ typedef T ret;
+ };
+} /* End of namespace direct_. */
+
/** Find a virtual type. */
template <typename source, typename target>
struct find_vtype
{
typedef typename find_rec<source, target>::ret res;
- /* Result. */
- typedef typename find_::match_with<res>::ret ret;
+
+ /* Unwrap the result. */
+ typedef typename find_::match_with<res>::ret unwrapped;
+
+ /* Remove potential deferred tag, and return result. */
+ typedef typename direct_::match_with<unwrapped>::ret ret;
};
@@ -684,6 +723,7 @@
};
+
/*------------.
| Selectors. |
`------------*/