https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
Fix some warnings with icpc; add is_built_in_.
* tests (svn:ignore): Add '.deps'.
* tests/case.cc: Fix warning with icpc.
* tests/gcase.cc: New file.
* mlc/abstract: New directory.
* mlc/type.hh: Rename as...
* mlc/abstract/type.hh: ...this.
* mlc/bexpr.hh (abstract::bexpr): Move to...
* mlc/abstract/bexpr.hh: ...this new file.
* mlc/flags.hh: Update include.
* mlc/value.hh: Update include.
* mlc/ret.hh: Add separators in macros to fix error with icpc.
* mlc/assert.hh: Add dtor to fix warning with icpc.
* mlc/case.hh (internal::a_get_case): New flag.
(get_case_): New class; it differs from case_ in remaining silent
when no case matches.
* mlc/cmp.hh (is_builtin_): New class with its specializations.
mlc/abstract/bexpr.hh | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++
mlc/abstract/type.hh | 10 +++----
mlc/assert.hh | 1
mlc/bexpr.hh | 32 ++++++------------------
mlc/case.hh | 27 ++++++++++++++++++++
mlc/cmp.hh | 44 +++++++++++++++++++++++++++++++++
mlc/flags.hh | 2 -
mlc/value.hh | 2 -
tests/case.cc | 4 +--
tests/gcase.cc | 38 +++++++++++++++++++++++++++++
10 files changed, 192 insertions(+), 33 deletions(-)
Index: tests/case.cc
--- tests/case.cc (revision 452)
+++ tests/case.cc (working copy)
@@ -52,9 +52,9 @@
template <class T>
-void print()
+static void print()
{
- int tmp;
+ T tmp;
}
Index: tests/gcase.cc
--- tests/gcase.cc (revision 0)
+++ tests/gcase.cc (revision 0)
@@ -0,0 +1,38 @@
+#include <mlc/is_a.hh>
+#include <mlc/case.hh>
+
+
+struct test;
+
+
+mlc_case_equipment_for_namespace(client);
+
+
+namespace client
+{
+
+ template <class T>
+ struct case_ <test, T, 1> : public mlc::where_< mlc_is_a(T, short) >
+ {
+ };
+
+ template <class T>
+ struct case_ <test, T, 2> : public mlc::where_< mlc_is_a(T, int) >
+ {
+ };
+
+} // end of namespace client
+
+
+template <class T>
+void print()
+{
+ int tmp;
+}
+
+
+
+int main()
+{
+ print< client::get_case_<test, char>::ret >();
+}
Index: mlc/ret.hh
Index: mlc/flags.hh
--- mlc/flags.hh (revision 452)
+++ mlc/flags.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef METALIC_FLAGS_HH
# define METALIC_FLAGS_HH
-# include <mlc/type.hh>
+# include <mlc/abstract/type.hh>
namespace mlc {
Index: mlc/assert.hh
--- mlc/assert.hh (revision 452)
+++ mlc/assert.hh (working copy)
@@ -156,6 +156,7 @@
{
public:
static void check() {}
+ virtual ~assert_() {}
protected:
assert_() {}
};
Index: mlc/case.hh
--- mlc/case.hh (revision 452)
+++ mlc/case.hh (working copy)
@@ -64,6 +64,7 @@
namespace internal
{
+ struct a_get_case;
struct a_simple_case;
struct a_switch_case;
@@ -203,6 +204,22 @@
struct handle_default_case_; \
\
\
+ template <typename context, typename data> \
+ struct handle_default_case_ < mlc::internal::a_get_case, context, data
> \
+ \
+ : private mlc::assert_< mlc::implies_< mlc::is_defined_<
NAMESPACE::default_case_<context, data> >, \
+ mlc_is_not_a(mlc_comma_1(NAMESPACE::default_case_<context,
data>), \
+ mlc::where_) >, \
+ mlc::ERROR::A_default_case_STATEMENT_SHOULD_NOT_DERIVE_FROM_mlc_where_
> \
+ { \
+ typedef NAMESPACE::default_case_<context, data> case_t; \
+ typedef typename protected_in_<case_t>::the protected_case_t; \
+ \
+ typedef typename mlc::if_< mlc::is_found_<protected_case_t>, \
+ protected_case_t, \
+ case_t >::ret ret; \
+ }; \
+ \
\
template <typename context, typename data> \
struct handle_default_case_ < mlc::internal::a_simple_case, context, data
> \
@@ -261,7 +278,8 @@
mlc::where_) >, \
mlc::ERROR::A_case_STATEMENT_SHOULD_DERIVE_FROM_mlc_where_ >, \
\
- private mlc::assert_< mlc::is_defined_< NAMESPACE::default_case_<context,
data> >, \
+ private mlc::assert_< mlc::implies_< mlc::neq_< use, mlc::internal::a_get_case
>, \
+ mlc::is_defined_< NAMESPACE::default_case_<context, data> >
>, \
mlc::WARNING::NO_default_case_STATEMENT_HAS_BEEN_DEFINED > \
\
{ \
@@ -380,6 +398,13 @@
\
\
template <typename context, typename data> \
+ struct get_case_ \
+ { \
+ typedef typename NAMESPACE::internal::select_case_<mlc::internal::a_get_case,
context, data>::ret ret; \
+ }; \
+ \
+ \
+ template <typename context, typename data> \
struct case_ <context, data, mlc::internal::unknown_case_id> \
\
: private mlc::assert_< mlc::neq_< mlc_comma_2(typename
NAMESPACE::internal::select_case_<mlc::internal::a_simple_case, \
Index: mlc/cmp.hh
--- mlc/cmp.hh (revision 452)
+++ mlc/cmp.hh (working copy)
@@ -50,12 +50,16 @@
# define mlc_is_found(T) mlc::is_found_<T>
# define mlc_is_not_found(T) mlc::is_not_found_<T>
+// FIXME: or (?) mlc_is_not_defined below
# define mlc_is_undefined(T) mlc::is_undefined_<T>
# define mlc_is_defined(T) mlc::is_defined_<T>
# define mlc_is_ok(T) mlc::is_ok_<T>
# define mlc_is_not_ok(T) mlc::is_not_ok_<T>
+# define mlc_is_builtin(T) mlc::is_builtin_<T>
+# define mlc_is_not_builtin(T) mlc::is_not_builtin_<T>
+
/// \}
@@ -162,6 +166,46 @@
/// \}
+
+ /// Check whether a type is a builtin type.
+ /// \{
+
+ template <typename T>
+ struct is_builtin_ : public bexpr_<false>
+ {
+ };
+
+ template <typename T> struct is_builtin_ < const T > : public
is_builtin_< T >::bexpr {};
+ template <typename T> struct is_builtin_ < T* > : public
is_builtin_< T >::bexpr {};
+ template <typename T> struct is_builtin_ < T[] > : public
is_builtin_< T >::bexpr {};
+ template <typename T,
+ unsigned n> struct is_builtin_ < T[n] > : public is_builtin_<
T >::bexpr {};
+
+ template <> struct is_builtin_ < void > : public bexpr_<true> {}; //
FIXME: ?
+ template <> struct is_builtin_ < bool > : public bexpr_<true> {};
+ template <> struct is_builtin_ < char > : public bexpr_<true> {};
+
+ template <> struct is_builtin_ < float > : public
bexpr_<true> {};
+ template <> struct is_builtin_ < double > : public
bexpr_<true> {};
+ template <> struct is_builtin_ < long double > : public
bexpr_<true> {};
+
+ template <> struct is_builtin_ < unsigned char > : public
bexpr_<true> {};
+ template <> struct is_builtin_ < signed char > : public
bexpr_<true> {};
+ template <> struct is_builtin_ < unsigned short > : public
bexpr_<true> {};
+ template <> struct is_builtin_ < signed short > : public
bexpr_<true> {};
+ template <> struct is_builtin_ < unsigned int > : public
bexpr_<true> {};
+ template <> struct is_builtin_ < signed int > : public
bexpr_<true> {};
+ template <> struct is_builtin_ < unsigned long > : public
bexpr_<true> {};
+ template <> struct is_builtin_ < signed long > : public
bexpr_<true> {};
+
+ template <typename T>
+ struct is_not_builtin_ : public not_< is_builtin_<T> >::bexpr
+ {
+ };
+
+ /// \}
+
+
} // end of namespace mlc
Index: mlc/bexpr.hh
--- mlc/bexpr.hh (revision 452)
+++ mlc/bexpr.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef METALIC_BEXPR_HH
# define METALIC_BEXPR_HH
-# include <mlc/type.hh>
+# include <mlc/abstract/bexpr.hh>
# include <mlc/flags.hh>
@@ -46,28 +46,6 @@
- namespace abstract {
-
- /*! \class mlc::abstract::bexpr
- **
- ** Abstract base class for mlc Boolean expression types.
- **
- ** When you define a new class for a Boolean expression type, you
- ** should not directly derive from this class from fom its
- ** subclass: bexpr_<b>.
- **
- ** \see bexpr_<b>
- */
-
- struct bexpr : public type
- {
- // typedef void eval;
- };
-
- } // end of namespace mlc::abstract
-
-
-
/*! \class mlc::bexpr_<b>
**
** Base class for any class of mlc Boolean expression types.
@@ -109,6 +87,10 @@
// FIXME: doc
typedef bexpr_<true> bexpr;
+
+ protected:
+ /// Ctor is protected to prevent instantiations.
+ bexpr_() {}
};
@@ -128,6 +110,10 @@
typedef mlc::false_ eval;
typedef bexpr_<false> bexpr;
+
+ protected:
+ /// Ctor is protected to prevent instantiations.
+ bexpr_() {}
};
Index: mlc/abstract/type.hh
--- mlc/abstract/type.hh (revision 0)
+++ mlc/abstract/type.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef METALIC_TYPE_HH
-# define METALIC_TYPE_HH
+#ifndef METALIC_ABSTRACT_TYPE_HH
+# define METALIC_ABSTRACT_TYPE_HH
namespace mlc {
@@ -48,8 +48,8 @@
struct type
{
- private:
- /// Ctor is private to prevent instantiations.
+ protected:
+ /// Ctor is protected to prevent instantiations.
type() {}
};
@@ -58,4 +58,4 @@
} // end of namespace mlc
-#endif // ! METALIC_TYPE_HH
+#endif // ! METALIC_ABSTRACT_TYPE_HH
Index: mlc/abstract/bexpr.hh
--- mlc/abstract/bexpr.hh (revision 0)
+++ mlc/abstract/bexpr.hh (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef METALIC_ABSTRACT_BEXPR_HH
+# define METALIC_ABSTRACT_BEXPR_HH
+
+# include <mlc/abstract/type.hh>
+# include <mlc/flags.hh>
+
+
+
+namespace mlc
+{
+
+ namespace abstract
+ {
+
+ /*! \class mlc::abstract::bexpr
+ **
+ ** Abstract base class for mlc Boolean expression types.
+ **
+ ** When you define a new class for a Boolean expression type, you
+ ** should not directly derive from this class from fom its
+ ** subclass: bexpr_<b>.
+ **
+ ** \see bexpr_<b>
+ */
+
+ struct bexpr : public mlc::abstract::type
+ {
+ // typedef void eval;
+ };
+
+
+ } // end of namespace mlc::abstract
+
+} // end of namespace mlc
+
+
+
+#endif // ! METALIC_ABSTRACT_BEXPR_HH
Index: mlc/value.hh
--- mlc/value.hh (revision 452)
+++ mlc/value.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef METALIC_VALUE_HH
# define METALIC_VALUE_HH
-# include <mlc/type.hh>
+# include <mlc/abstract/type.hh>
// # include <mlc/assert.hh>
// # include <mlc/is_a.hh>