Skip to content

Commit 56e608f

Browse files
authored
Cleanup dependencies (#8)
Resolve dependencies to GridTools as follows. - Removed from GridTools: any_moveable.hpp, copy_into_variadic.hpp, is_there_in_sequence_if.hpp - integer_sequence moved into make_indices.hpp (GT with c++14 doesn't have it integer_sequence anymore; the rest is trivial.) - Duplicated and moved to cpp_bindgen namespace: type_traits.hpp (removed unused aliases, probably duplications are removed from GT with c++14), for_each.hpp (removed device variants). Additional changes: - New namespace cpp_bindgen replaces gridtools::c_bindings
1 parent 0bc1fb2 commit 56e608f

84 files changed

Lines changed: 1346 additions & 3734 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/c_bindings/export.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
#include "function_wrapper.hpp"
1919
#include "generator.hpp"
2020

21-
#define GT_EXPORT_BINDING_IMPL_PARAM_DECL(z, i, signature) \
22-
typename boost::mpl::at_c< \
23-
typename boost::function_types::parameter_types<::gridtools::c_bindings::wrapped_t<signature>>::type, \
21+
#define GT_EXPORT_BINDING_IMPL_PARAM_DECL(z, i, signature) \
22+
typename boost::mpl::at_c< \
23+
typename boost::function_types::parameter_types<::cpp_bindgen::wrapped_t<signature>>::type, \
2424
i>::type param_##i
2525

26-
#define GT_ADD_GENERATED_DEFINITION_IMPL(n, name, cppsignature, impl) \
27-
static_assert(::boost::function_types::function_arity<cppsignature>::value == n, "arity mismatch"); \
28-
extern "C" typename ::boost::function_types::result_type<::gridtools::c_bindings::wrapped_t<cppsignature>>::type \
29-
name(BOOST_PP_ENUM(n, GT_EXPORT_BINDING_IMPL_PARAM_DECL, cppsignature)) { \
30-
return ::gridtools::c_bindings::wrap<cppsignature>(impl)(BOOST_PP_ENUM_PARAMS(n, param_)); \
26+
#define GT_ADD_GENERATED_DEFINITION_IMPL(n, name, cppsignature, impl) \
27+
static_assert(::boost::function_types::function_arity<cppsignature>::value == n, "arity mismatch"); \
28+
extern "C" typename ::boost::function_types::result_type<::cpp_bindgen::wrapped_t<cppsignature>>::type name( \
29+
BOOST_PP_ENUM(n, GT_EXPORT_BINDING_IMPL_PARAM_DECL, cppsignature)) { \
30+
return ::cpp_bindgen::wrap<cppsignature>(impl)(BOOST_PP_ENUM_PARAMS(n, param_)); \
3131
}
3232

3333
/**
@@ -56,7 +56,7 @@
5656
*/
5757
#define GT_EXPORT_BINDING_WITH_SIGNATURE(n, name, cppsignature, impl) \
5858
GT_ADD_GENERATED_DEFINITION_IMPL(n, name, cppsignature, impl) \
59-
GT_ADD_GENERATED_DECLARATION(::gridtools::c_bindings::wrapped_t<cppsignature>, name)
59+
GT_ADD_GENERATED_DECLARATION(::cpp_bindgen::wrapped_t<cppsignature>, name)
6060

6161
/**
6262
* Defines the function with the given name with the C linkage with an additional wrapper in the fortran bindings. The

include/c_bindings/fortran_array_view.hpp

Lines changed: 178 additions & 184 deletions
Large diffs are not rendered by default.

include/c_bindings/function_wrapper.hpp

Lines changed: 139 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -18,156 +18,151 @@
1818
#include "fortran_array_view.hpp"
1919
#include "handle_impl.hpp"
2020

21-
namespace gridtools {
22-
namespace c_bindings {
23-
namespace _impl {
24-
25-
template <class T, class = void>
26-
struct result_converted_to_c;
27-
28-
template <class T>
29-
struct result_converted_to_c<T,
30-
typename std::enable_if<std::is_void<T>::value || std::is_arithmetic<T>::value>::type> {
31-
using type = T;
32-
};
33-
34-
template <class T>
35-
struct result_converted_to_c<T,
36-
typename std::enable_if<std::is_class<typename std::remove_reference<T>::type>::value>::type> {
37-
using type = gt_handle *;
38-
};
39-
40-
template <class T, class = void>
41-
struct param_converted_to_c;
42-
43-
template <class T>
44-
struct param_converted_to_c<T, typename std::enable_if<std::is_arithmetic<T>::value>::type> {
45-
using type = T;
46-
};
47-
48-
template <class T>
49-
struct param_converted_to_c<T *, typename std::enable_if<std::is_arithmetic<T>::value>::type> {
50-
using type = T *;
51-
};
52-
53-
template <class T>
54-
struct param_converted_to_c<T &, typename std::enable_if<std::is_arithmetic<T>::value>::type> {
55-
using type = T *;
56-
};
57-
58-
template <class T>
59-
struct param_converted_to_c<T *,
60-
typename std::enable_if<std::is_class<T>::value && !is_fortran_array_bindable<T *>::value>::type> {
61-
using type = gt_handle *;
62-
};
63-
template <class T>
64-
struct param_converted_to_c<T,
65-
typename std::enable_if<std::is_class<remove_reference_t<T>>::value &&
66-
!is_fortran_array_bindable<T>::value>::type> {
67-
using type = gt_handle *;
68-
};
69-
70-
template <class T>
71-
struct param_converted_to_c<T, typename std::enable_if<is_fortran_array_bindable<T>::value>::type> {
72-
using type = gt_fortran_array_descriptor *;
73-
};
74-
75-
template <class T, typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
76-
T convert_to_c(T obj) {
77-
return obj;
78-
}
21+
namespace cpp_bindgen {
22+
namespace _impl {
7923

80-
template <class T,
81-
typename std::enable_if<std::is_class<typename std::remove_reference<T>::type>::value, int>::type = 0>
82-
gt_handle *convert_to_c(T &&obj) {
83-
return new gt_handle{std::forward<T>(obj)};
84-
}
24+
template <class T, class = void>
25+
struct result_converted_to_c;
8526

86-
template <class T>
87-
using result_converted_to_c_t = typename result_converted_to_c<T>::type;
88-
template <class T>
89-
using param_converted_to_c_t = typename param_converted_to_c<T>::type;
90-
91-
template <class T,
92-
typename std::enable_if<std::is_arithmetic<typename std::remove_pointer<T>::type>::value, int>::type =
93-
0>
94-
T convert_from_c(T obj) {
95-
return obj;
96-
};
97-
98-
template <class T,
99-
typename std::enable_if<std::is_reference<T>::value &&
100-
std::is_arithmetic<typename std::remove_reference<T>::type>::value,
101-
int>::type = 0>
102-
T convert_from_c(typename std::remove_reference<T>::type *obj) {
103-
return *obj;
104-
};
105-
106-
template <class T, typename std::enable_if<std::is_pointer<T>::value, int>::type = 0>
107-
T convert_from_c(gt_handle *obj) {
108-
return &any_cast<remove_pointer_t<T> &>(obj->m_value);
109-
}
110-
template <class T, typename std::enable_if<!std::is_pointer<T>::value, int>::type = 0>
111-
T convert_from_c(gt_handle *obj) {
112-
return any_cast<T>(obj->m_value);
113-
}
114-
template <class T>
115-
T convert_from_c(gt_fortran_array_descriptor *obj) {
116-
return make_fortran_array_view<T>(obj);
117-
}
27+
template <class T>
28+
struct result_converted_to_c<T,
29+
typename std::enable_if<std::is_void<T>::value || std::is_arithmetic<T>::value>::type> {
30+
using type = T;
31+
};
11832

119-
template <class T, class Impl>
120-
struct wrapped_f;
121-
122-
template <class R, class... Params, class Impl>
123-
struct wrapped_f<R(Params...), Impl> {
124-
Impl m_fun;
125-
result_converted_to_c_t<R> operator()(param_converted_to_c_t<Params>... args) const {
126-
return convert_to_c(m_fun(convert_from_c<Params>(args)...));
127-
}
128-
};
129-
130-
template <class... Params, class Impl>
131-
struct wrapped_f<void(Params...), Impl> {
132-
Impl m_fun;
133-
void operator()(param_converted_to_c_t<Params>... args) const {
134-
m_fun(convert_from_c<Params>(args)...);
135-
}
136-
};
137-
138-
template <class T>
139-
struct wrapped;
140-
141-
template <class T>
142-
struct wrapped<T *> {
143-
using type = typename wrapped<T>::type;
144-
};
145-
146-
template <class T>
147-
struct wrapped<T &> {
148-
using type = typename wrapped<T>::type;
149-
};
150-
151-
template <class R, class... Params>
152-
struct wrapped<R(Params...)> {
153-
using type = result_converted_to_c_t<R>(typename param_converted_to_c<Params>::type...);
154-
};
155-
} // namespace _impl
156-
157-
/// Transform a function type to to the function type that is callable from C
15833
template <class T>
159-
using wrapped_t = typename _impl::wrapped<T>::type;
34+
struct result_converted_to_c<T,
35+
typename std::enable_if<std::is_class<typename std::remove_reference<T>::type>::value>::type> {
36+
using type = gt_handle *;
37+
};
16038

161-
/// Wrap the functor of type `Impl` to another functor that can be invoked with the 'wrapped_t<T>' signature.
162-
template <class T, class Impl>
163-
constexpr _impl::wrapped_f<T, typename std::decay<Impl>::type> wrap(Impl &&obj) {
164-
return {std::forward<Impl>(obj)};
39+
template <class T, class = void>
40+
struct param_converted_to_c;
41+
42+
template <class T>
43+
struct param_converted_to_c<T, typename std::enable_if<std::is_arithmetic<T>::value>::type> {
44+
using type = T;
45+
};
46+
47+
template <class T>
48+
struct param_converted_to_c<T *, typename std::enable_if<std::is_arithmetic<T>::value>::type> {
49+
using type = T *;
50+
};
51+
52+
template <class T>
53+
struct param_converted_to_c<T &, typename std::enable_if<std::is_arithmetic<T>::value>::type> {
54+
using type = T *;
55+
};
56+
57+
template <class T>
58+
struct param_converted_to_c<T *,
59+
typename std::enable_if<std::is_class<T>::value && !is_fortran_array_bindable<T *>::value>::type> {
60+
using type = gt_handle *;
61+
};
62+
template <class T>
63+
struct param_converted_to_c<T,
64+
typename std::enable_if<std::is_class<remove_reference_t<T>>::value &&
65+
!is_fortran_array_bindable<T>::value>::type> {
66+
using type = gt_handle *;
67+
};
68+
69+
template <class T>
70+
struct param_converted_to_c<T, typename std::enable_if<is_fortran_array_bindable<T>::value>::type> {
71+
using type = gt_fortran_array_descriptor *;
72+
};
73+
74+
template <class T, typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
75+
T convert_to_c(T obj) {
76+
return obj;
77+
}
78+
79+
template <class T,
80+
typename std::enable_if<std::is_class<typename std::remove_reference<T>::type>::value, int>::type = 0>
81+
gt_handle *convert_to_c(T &&obj) {
82+
return new gt_handle{std::forward<T>(obj)};
16583
}
16684

167-
/// Specialization for function pointers.
16885
template <class T>
169-
constexpr _impl::wrapped_f<T, T *> wrap(T *obj) {
170-
return {obj};
86+
using result_converted_to_c_t = typename result_converted_to_c<T>::type;
87+
template <class T>
88+
using param_converted_to_c_t = typename param_converted_to_c<T>::type;
89+
90+
template <class T,
91+
typename std::enable_if<std::is_arithmetic<typename std::remove_pointer<T>::type>::value, int>::type = 0>
92+
T convert_from_c(T obj) {
93+
return obj;
94+
};
95+
96+
template <class T,
97+
typename std::enable_if<std::is_reference<T>::value &&
98+
std::is_arithmetic<typename std::remove_reference<T>::type>::value,
99+
int>::type = 0>
100+
T convert_from_c(typename std::remove_reference<T>::type *obj) {
101+
return *obj;
102+
};
103+
104+
template <class T, typename std::enable_if<std::is_pointer<T>::value, int>::type = 0>
105+
T convert_from_c(gt_handle *obj) {
106+
return &any_cast<remove_pointer_t<T> &>(obj->m_value);
107+
}
108+
template <class T, typename std::enable_if<!std::is_pointer<T>::value, int>::type = 0>
109+
T convert_from_c(gt_handle *obj) {
110+
return any_cast<T>(obj->m_value);
171111
}
172-
} // namespace c_bindings
173-
} // namespace gridtools
112+
template <class T>
113+
T convert_from_c(gt_fortran_array_descriptor *obj) {
114+
return make_fortran_array_view<T>(obj);
115+
}
116+
117+
template <class T, class Impl>
118+
struct wrapped_f;
119+
120+
template <class R, class... Params, class Impl>
121+
struct wrapped_f<R(Params...), Impl> {
122+
Impl m_fun;
123+
result_converted_to_c_t<R> operator()(param_converted_to_c_t<Params>... args) const {
124+
return convert_to_c(m_fun(convert_from_c<Params>(args)...));
125+
}
126+
};
127+
128+
template <class... Params, class Impl>
129+
struct wrapped_f<void(Params...), Impl> {
130+
Impl m_fun;
131+
void operator()(param_converted_to_c_t<Params>... args) const { m_fun(convert_from_c<Params>(args)...); }
132+
};
133+
134+
template <class T>
135+
struct wrapped;
136+
137+
template <class T>
138+
struct wrapped<T *> {
139+
using type = typename wrapped<T>::type;
140+
};
141+
142+
template <class T>
143+
struct wrapped<T &> {
144+
using type = typename wrapped<T>::type;
145+
};
146+
147+
template <class R, class... Params>
148+
struct wrapped<R(Params...)> {
149+
using type = result_converted_to_c_t<R>(typename param_converted_to_c<Params>::type...);
150+
};
151+
} // namespace _impl
152+
153+
/// Transform a function type to to the function type that is callable from C
154+
template <class T>
155+
using wrapped_t = typename _impl::wrapped<T>::type;
156+
157+
/// Wrap the functor of type `Impl` to another functor that can be invoked with the 'wrapped_t<T>' signature.
158+
template <class T, class Impl>
159+
constexpr _impl::wrapped_f<T, typename std::decay<Impl>::type> wrap(Impl &&obj) {
160+
return {std::forward<Impl>(obj)};
161+
}
162+
163+
/// Specialization for function pointers.
164+
template <class T>
165+
constexpr _impl::wrapped_f<T, T *> wrap(T *obj) {
166+
return {obj};
167+
}
168+
} // namespace cpp_bindgen

0 commit comments

Comments
 (0)