File: export.hpp

package info (click to toggle)
gridtools 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 21,728 kB
  • sloc: cpp: 45,263; python: 9,383; javascript: 8,445; ansic: 2,564; sh: 509; f90: 370; makefile: 216
file content (176 lines) | stat: -rw-r--r-- 11,521 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 * GridTools
 *
 * Copyright (c) 2014-2019, ETH Zurich
 * All rights reserved.
 *
 * Please, refer to the LICENSE file in the root directory.
 * SPDX-License-Identifier: BSD-3-Clause
 */
#pragma once

#include <boost/preprocessor.hpp>

#include "common/function_traits.hpp"
#include "function_wrapper.hpp"
#include "generator.hpp"

#define BINDGEN_EXPORT_BINDING_IMPL_PARAM_DECL(z, i, signature) \
    typename std::tuple_element<i,                              \
        ::cpp_bindgen::function_traits::parameter_types<::cpp_bindgen::wrapped_t<signature>>::type>::type param_##i

#define BINDGEN_ADD_GENERATED_DEFINITION_IMPL(n, name, cppsignature, impl)                                        \
    static_assert(::cpp_bindgen::function_traits::arity<cppsignature>::value == n, "arity mismatch");             \
    extern "C" typename ::cpp_bindgen::function_traits::result_type<::cpp_bindgen::wrapped_t<cppsignature>>::type \
    name(BOOST_PP_ENUM(n, BINDGEN_EXPORT_BINDING_IMPL_PARAM_DECL, cppsignature)) {                                \
        return ::cpp_bindgen::wrap<cppsignature>(impl)(BOOST_PP_ENUM_PARAMS(n, param_));                          \
    }

/**
 *   Defines the function with the given name with the C linkage.
 *
 *   The signature if the generated function will be transformed from the provided signature according to the following
 *   rules:
 *     - for result type:
 *       - `void` and arithmetic types remain the same;
 *       - classes (and structures) and references to them are transformed to the pointer to the opaque handle
 *         (`bindgen_handle*`) which should be released by calling `void bindgen_release(bindgen_handle*)` function;
 *       - all other result types will cause a compiler error.
 *     - for parameter types:
 *       - arithmetic types and pointers to them remain the same;
 *       - references to arithmetic types are transformed to the corresponded pointers;
 *       - types that fulfill the concept of being fortran_array_bindable are transformed to a
 *         bindgen_fortran_array_descriptor
 *       - classes (and structures) and references or pointers to them are transformed to `bindgen_handle*`;
 *       - all other parameter types will cause a compiler error.
 *   Additionally the newly generated function will be registered for automatic interface generation.
 *
 *   @param n The arity of the generated function.
 *   @param name The name of the generated function.
 *   @param cppsignature The signature that will be used to invoke `impl`.
 *   @param impl The functor that the generated function will delegate to.
 */
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(n, name, cppsignature, impl) \
    BINDGEN_ADD_GENERATED_DEFINITION_IMPL(n, name, cppsignature, impl)     \
    BINDGEN_ADD_GENERATED_DECLARATION(::cpp_bindgen::wrapped_t<cppsignature>, name)

/**
 *   Defines the function with the given name with the C linkage with an additional wrapper in the fortran bindings. The
 *   additional wrapper provides the following functionality:
 *     - It generates a bindgen_fortran_array_descriptor from an array, if the type on C++-side is
 *       fortran_array_wrappable.
 *
 *   The signature if the generated function will be transformed from the provided signature according to the following
 *   rules:
 *     - for result type:
 *       - `void` and arithmetic types remain the same;
 *       - classes (and structures) and references to them are transformed to the pointer to the opaque handle
 *         (`bindgen_handle*`) which should be released by calling `void bindgen_release(bindgen_handle*)` function;
 *       - all other result types will cause a compiler error.
 *     - for parameter types:
 *       - arithmetic types and pointers to them remain the same;
 *       - references to arithmetic types are transformed to the corresponded pointers;
 *       - types that are fortran_array_bindable but not fortran_array_wrappable are transformed to a
 *         bindgen_fortran_array_descriptor
 *       - types that are fortran_array_wrappable are transformed to a bindgen_fortran_array_descriptor in the
 *         c-bindings, and provide a wrapper in the fortran-bindings such that they can be called with a fortran array
 *       - classes (and structures) and references or pointers to them are transformed to `bindgen_handle*`;
 *       - all other parameter types will cause a compiler error.
 *   Additionally the newly generated function will be registered for automatic interface generation.
 *
 *   @param n The arity of the generated function.
 *   @param name The name of the generated function.
 *   @param cppsignature The signature that will be used to invoke `impl`.
 *   @param impl The functor that the generated function will delegate to.
 */
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(n, name, cppsignature, impl) \
    BINDGEN_ADD_GENERATED_DEFINITION_IMPL(n, name, cppsignature, impl)             \
    BINDGEN_ADD_GENERATED_DECLARATION_WRAPPED(cppsignature, name)

/// The flavour of BINDGEN_EXPORT_BINDING_WITH_SIGNATURE where the `impl` parameter is a function pointer.
#define BINDGEN_EXPORT_BINDING(n, name, impl) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(n, name, decltype(BOOST_PP_REMOVE_PARENS(impl)), impl)
#define BINDGEN_EXPORT_BINDING_WRAPPED(n, name, impl) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(n, name, decltype(BOOST_PP_REMOVE_PARENS(impl)), impl)

#define BINDGEN_EXPORT_GENERIC_BINDING_IMPL_IMPL(generatorsuffix, n, generic_name, concrete_name, impl) \
    BOOST_PP_CAT(BINDGEN_EXPORT_BINDING, generatorsuffix)(n, concrete_name, impl);                      \
    BINDGEN_ADD_GENERIC_DECLARATION(generic_name, concrete_name)

#define BINDGEN_EXPORT_GENERIC_BINDING_IMPL(generatorsuffix, n, name, suffix, impl) \
    BINDGEN_EXPORT_GENERIC_BINDING_IMPL_IMPL(generatorsuffix, n, name, BOOST_PP_CAT(name, suffix), impl)

#define BINDGEN_EXPORT_GENERIC_BINDING_IMPL_FUNCTOR(r, data, i, elem)    \
    BINDGEN_EXPORT_GENERIC_BINDING_IMPL(BOOST_PP_TUPLE_ELEM(4, 0, data), \
        BOOST_PP_TUPLE_ELEM(4, 1, data),                                 \
        BOOST_PP_TUPLE_ELEM(4, 2, data),                                 \
        i,                                                               \
        (BOOST_PP_TUPLE_ELEM(4, 3, data) < BOOST_PP_REMOVE_PARENS(elem) >));

#define BINDGEN_EXPORT_GENERIC_BINDING(n, name, impl_template, template_params) \
    BOOST_PP_SEQ_FOR_EACH_I(BINDGEN_EXPORT_GENERIC_BINDING_IMPL_FUNCTOR,        \
        (, n, name, impl_template),                                             \
        BOOST_PP_VARIADIC_SEQ_TO_SEQ(template_params))                          \
    static_assert(1, "")

#define BINDGEN_EXPORT_GENERIC_BINDING_WRAPPED(n, name, impl_template, template_params) \
    BOOST_PP_SEQ_FOR_EACH_I(BINDGEN_EXPORT_GENERIC_BINDING_IMPL_FUNCTOR,                \
        (_WRAPPED, n, name, impl_template),                                             \
        BOOST_PP_VARIADIC_SEQ_TO_SEQ(template_params))                                  \
    static_assert(1, "")

/// BINDGEN_EXPORT_BINDING_WITH_SIGNATURE shortcuts for the given arity
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_0(name, s, i) BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(0, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_1(name, s, i) BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(1, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_2(name, s, i) BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(2, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_3(name, s, i) BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(3, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_4(name, s, i) BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(4, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_5(name, s, i) BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(5, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_6(name, s, i) BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(6, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_7(name, s, i) BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(7, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_8(name, s, i) BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(8, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_9(name, s, i) BINDGEN_EXPORT_BINDING_WITH_SIGNATURE(9, name, s, i)

#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED_0(name, s, i) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(0, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED_1(name, s, i) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(1, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED_2(name, s, i) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(2, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED_3(name, s, i) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(3, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED_4(name, s, i) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(4, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED_5(name, s, i) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(5, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED_6(name, s, i) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(6, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED_7(name, s, i) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(7, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED_8(name, s, i) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(8, name, s, i)
#define BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED_9(name, s, i) \
    BINDGEN_EXPORT_BINDING_WITH_SIGNATURE_WRAPPED(9, name, s, i)

/// BINDGEN_EXPORT_BINDING shortcuts for the given arity
#define BINDGEN_EXPORT_BINDING_0(name, impl) BINDGEN_EXPORT_BINDING(0, name, impl)
#define BINDGEN_EXPORT_BINDING_1(name, impl) BINDGEN_EXPORT_BINDING(1, name, impl)
#define BINDGEN_EXPORT_BINDING_2(name, impl) BINDGEN_EXPORT_BINDING(2, name, impl)
#define BINDGEN_EXPORT_BINDING_3(name, impl) BINDGEN_EXPORT_BINDING(3, name, impl)
#define BINDGEN_EXPORT_BINDING_4(name, impl) BINDGEN_EXPORT_BINDING(4, name, impl)
#define BINDGEN_EXPORT_BINDING_5(name, impl) BINDGEN_EXPORT_BINDING(5, name, impl)
#define BINDGEN_EXPORT_BINDING_6(name, impl) BINDGEN_EXPORT_BINDING(6, name, impl)
#define BINDGEN_EXPORT_BINDING_7(name, impl) BINDGEN_EXPORT_BINDING(7, name, impl)
#define BINDGEN_EXPORT_BINDING_8(name, impl) BINDGEN_EXPORT_BINDING(8, name, impl)
#define BINDGEN_EXPORT_BINDING_9(name, impl) BINDGEN_EXPORT_BINDING(9, name, impl)

#define BINDGEN_EXPORT_BINDING_WRAPPED_0(name, impl) BINDGEN_EXPORT_BINDING_WRAPPED(0, name, impl)
#define BINDGEN_EXPORT_BINDING_WRAPPED_1(name, impl) BINDGEN_EXPORT_BINDING_WRAPPED(1, name, impl)
#define BINDGEN_EXPORT_BINDING_WRAPPED_2(name, impl) BINDGEN_EXPORT_BINDING_WRAPPED(2, name, impl)
#define BINDGEN_EXPORT_BINDING_WRAPPED_3(name, impl) BINDGEN_EXPORT_BINDING_WRAPPED(3, name, impl)
#define BINDGEN_EXPORT_BINDING_WRAPPED_4(name, impl) BINDGEN_EXPORT_BINDING_WRAPPED(4, name, impl)
#define BINDGEN_EXPORT_BINDING_WRAPPED_5(name, impl) BINDGEN_EXPORT_BINDING_WRAPPED(5, name, impl)
#define BINDGEN_EXPORT_BINDING_WRAPPED_6(name, impl) BINDGEN_EXPORT_BINDING_WRAPPED(6, name, impl)
#define BINDGEN_EXPORT_BINDING_WRAPPED_7(name, impl) BINDGEN_EXPORT_BINDING_WRAPPED(7, name, impl)
#define BINDGEN_EXPORT_BINDING_WRAPPED_8(name, impl) BINDGEN_EXPORT_BINDING_WRAPPED(8, name, impl)
#define BINDGEN_EXPORT_BINDING_WRAPPED_9(name, impl) BINDGEN_EXPORT_BINDING_WRAPPED(9, name, impl)