summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/function_helpers.hh
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2017-11-23 21:50:16 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2017-12-04 15:47:50 -0300
commitd93e9ff286ce1961f530d56b5536881f47104ebd (patch)
treed9fd8cd25a64b9ab6b23ae34b92c342dc8e6b543 /src/bin/eolian_mono/eolian/mono/function_helpers.hh
parent9391407319424c503a78479b407737ccead945b7 (diff)
eolian_mono: Added code for eolian_mono generator
Based on the eolian_cxx library generators. Buildsystem files will come in a future commmit.
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/function_helpers.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_helpers.hh243
1 files changed, 243 insertions, 0 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/function_helpers.hh b/src/bin/eolian_mono/eolian/mono/function_helpers.hh
new file mode 100644
index 0000000000..e7af6f9dc0
--- /dev/null
+++ b/src/bin/eolian_mono/eolian/mono/function_helpers.hh
@@ -0,0 +1,243 @@
1#ifndef EOLIAN_MONO_FUNCTION_DEFINITION_HELPERS_HH
2#define EOLIAN_MONO_FUNCTION_DEFINITION_HELPERS_HH
3
4#include <Eina.hh>
5
6#include "grammar/generator.hpp"
7#include "grammar/klass_def.hpp"
8
9#include "grammar/indentation.hpp"
10#include "grammar/list.hpp"
11#include "grammar/alternative.hpp"
12#include "grammar/attribute_reorder.hpp"
13/* #include "type.hh" */
14/* #include "marshall_type.hh" */
15#include "parameter.hh"
16#include "function_pointer.hh"
17/* #include "keyword.hh" */
18/* #include "using_decl.hh" */
19/* #include "generation_contexts.hh" */
20
21namespace eolian_mono {
22
23/*
24 * Generators for things that must happen inside the function definition *before* and
25 * *after* the actual invocation of the underlying C function.
26 *
27 * For example, declaration and assignment of intermediate variables for out/ return types
28 * that require some kind of manual work (e.g. string and Stringshare).
29 */
30
31struct native_function_definition_preamble_generator
32{
33 // FIXME Suport scoping tabs
34 template <typename OutputIterator, typename Context>
35 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
36 {
37 std::string return_type;
38
39 if(!as_generator(eolian_mono::type(true)).generate(std::back_inserter(return_type), f.return_type, context))
40 return false;
41
42 if (!as_generator(
43 scope_tab << scope_tab << "//Placeholder in variables\n"
44 << *(scope_tab << scope_tab << native_convert_in_variable << "\n")
45 << scope_tab << scope_tab << "//Placeholder out variables\n"
46 << *(scope_tab << scope_tab << native_convert_out_variable << "\n")
47 << scope_tab << scope_tab << "//Function pointer wrappers\n"
48 << *(scope_tab << scope_tab << native_convert_function_pointer << "\n")
49 << scope_tab << scope_tab << "//Return variable and function call\n"
50 << scope_tab << scope_tab << scope_tab << native_convert_return_variable << "\n"
51 ).generate(sink, std::make_tuple(f.parameters, f.parameters, f.parameters, f.return_type), context))
52 return false;
53
54 return true;
55 }
56};
57
58struct function_definition_preamble_generator
59{
60 // FIXME Suport scoping tabs
61 template <typename OutputIterator, typename Context>
62 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
63 {
64 std::string return_type;
65
66 if(!as_generator(eolian_mono::type(true)).generate(std::back_inserter(return_type), f.return_type, context))
67 return false;
68
69 if (!as_generator(
70 scope_tab << scope_tab << "//Placeholder in variables\n"
71 << *(scope_tab << scope_tab << convert_in_variable << "\n")
72 << scope_tab << scope_tab << "//Placeholder out variables\n"
73 << *(scope_tab << scope_tab << convert_out_variable << "\n")
74 << scope_tab << scope_tab << "//Function pointers handling\n"
75 << *(scope_tab << scope_tab << convert_function_pointer << "\n")
76 << scope_tab << scope_tab << "//Return variable and function call\n"
77 << scope_tab << scope_tab << convert_return_variable
78 ).generate(sink, std::make_tuple(f.parameters, f.parameters, f.parameters, f.return_type), context))
79 return false;
80
81 return true;
82 }
83};
84
85struct native_function_definition_epilogue_generator
86{
87 attributes::klass_def const* klass;
88
89 // FIXME Suport scoping tabs
90 template <typename OutputIterator, typename Context>
91 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
92 {
93 std::string return_type;
94
95 if(!as_generator(eolian_mono::type(true)).generate(std::back_inserter(return_type), f.return_type, context))
96 return false;
97
98 if (!as_generator(
99 scope_tab << scope_tab << "//Assigning out variables\n"
100 << *(scope_tab << scope_tab << native_convert_out_assign(*klass) << "\n")
101 << scope_tab << scope_tab << "//Converting return variable\n"
102 << scope_tab << scope_tab << native_convert_return(*klass)
103 ).generate(sink, std::make_tuple(f.parameters, f.return_type), context))
104 return false;
105
106 return true;
107 }
108};
109
110struct function_definition_epilogue_generator
111{
112 // FIXME Suport scoping tabs
113 template <typename OutputIterator, typename Context>
114 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
115 {
116 if (!as_generator(
117 scope_tab << scope_tab << "eina.Error.RaiseIfOccurred();\n"
118 << scope_tab << scope_tab << "//Assigning out variables\n"
119 << *(scope_tab << scope_tab << convert_out_assign << "\n")
120 << scope_tab << scope_tab << "//Converting return variable\n"
121 << scope_tab << scope_tab << convert_return
122 ).generate(sink, std::make_tuple(f.parameters, f.return_type), context))
123 return false;
124
125 return true;
126 }
127};
128
129// Preamble tokens
130struct native_function_definition_preamble_terminal
131{
132 native_function_definition_preamble_generator const operator()() const
133 {
134 return native_function_definition_preamble_generator();
135 }
136} const native_function_definition_preamble = {};
137
138native_function_definition_preamble_generator const as_generator(native_function_definition_preamble_terminal)
139{
140 return native_function_definition_preamble_generator{};
141}
142
143struct function_definition_preamble_terminal
144{
145 function_definition_preamble_generator const operator()() const
146 {
147 return function_definition_preamble_generator();
148 }
149} const function_definition_preamble = {};
150
151function_definition_preamble_generator const as_generator(function_definition_preamble_terminal)
152{
153 return function_definition_preamble_generator{};
154}
155
156// Epilogue tokens
157struct native_function_definition_epilogue_parameterized
158{
159 native_function_definition_epilogue_generator const operator()(attributes::klass_def const& klass) const
160 {
161 return {&klass};
162 }
163} const native_function_definition_epilogue;
164
165struct function_definition_epilogue_terminal
166{
167 function_definition_epilogue_generator const operator()() const
168 {
169 return function_definition_epilogue_generator();
170 }
171} const function_definition_epilogue = {};
172
173function_definition_epilogue_generator const as_generator(function_definition_epilogue_terminal)
174{
175 return function_definition_epilogue_generator{};
176}
177
178} // namespace eolian_mono
179
180namespace efl { namespace eolian { namespace grammar {
181
182// Preamble
183template <>
184struct is_eager_generator< ::eolian_mono::native_function_definition_preamble_generator> : std::true_type {};
185
186template <>
187struct is_generator< ::eolian_mono::native_function_definition_preamble_generator> : std::true_type {};
188template <>
189struct is_generator< ::eolian_mono::native_function_definition_preamble_terminal> : std::true_type {};
190
191template <>
192struct is_eager_generator< ::eolian_mono::function_definition_preamble_generator> : std::true_type {};
193
194template <>
195struct is_generator< ::eolian_mono::function_definition_preamble_generator> : std::true_type {};
196template <>
197struct is_generator< ::eolian_mono::function_definition_preamble_terminal> : std::true_type {};
198
199// Epilogue
200template <>
201struct is_eager_generator< ::eolian_mono::native_function_definition_epilogue_generator> : std::true_type {};
202
203template <>
204struct is_generator< ::eolian_mono::native_function_definition_epilogue_generator> : std::true_type {};
205template <>
206struct is_generator< ::eolian_mono::native_function_definition_epilogue_parameterized> : std::true_type {};
207
208template <>
209struct is_eager_generator< ::eolian_mono::function_definition_epilogue_generator> : std::true_type {};
210
211template <>
212struct is_generator< ::eolian_mono::function_definition_epilogue_generator> : std::true_type {};
213template <>
214struct is_generator< ::eolian_mono::function_definition_epilogue_terminal> : std::true_type {};
215
216namespace type_traits {
217// Preamble
218template <>
219struct attributes_needed< ::eolian_mono::native_function_definition_preamble_generator> : std::integral_constant<int, 1> {};
220template <>
221struct attributes_needed< ::eolian_mono::native_function_definition_preamble_terminal> : std::integral_constant<int, 1> {};
222
223template <>
224struct attributes_needed< ::eolian_mono::function_definition_preamble_generator> : std::integral_constant<int, 1> {};
225template <>
226struct attributes_needed< ::eolian_mono::function_definition_preamble_terminal> : std::integral_constant<int, 1> {};
227
228// Epilogue
229template <>
230struct attributes_needed< ::eolian_mono::native_function_definition_epilogue_generator> : std::integral_constant<int, 1> {};
231template <>
232struct attributes_needed< ::eolian_mono::native_function_definition_epilogue_parameterized> : std::integral_constant<int, 1> {};
233
234template <>
235struct attributes_needed< ::eolian_mono::function_definition_epilogue_generator> : std::integral_constant<int, 1> {};
236template <>
237struct attributes_needed< ::eolian_mono::function_definition_epilogue_terminal> : std::integral_constant<int, 1> {};
238
239}
240
241} } }
242
243#endif