summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/marshall_annotation.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/marshall_annotation.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/marshall_annotation.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_annotation.hh246
1 files changed, 246 insertions, 0 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
new file mode 100644
index 0000000000..2765dcdc25
--- /dev/null
+++ b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
@@ -0,0 +1,246 @@
1#ifndef EOLIAN_MONO_MARSHALL_ANNOTATION_IMPL_HH
2#define EOLIAN_MONO_MARSHALL_ANNOTATION_IMPL_HH
3
4#include "grammar/generator.hpp"
5#include "grammar/klass_def.hpp"
6#include "grammar/case.hpp"
7#include "namespace.hh"
8#include "type_impl.hh"
9
10namespace eolian_mono {
11
12namespace eina = efl::eina;
13
14namespace detail {
15
16template <typename Array, typename F, int N, typename A>
17eina::optional<bool> call_annotation_match(Array const (&array)[N], F f, A a)
18{
19 typedef Array const* iterator_type;
20 iterator_type match_iterator = &array[0], match_last = match_iterator + N;
21 match_iterator = std::find_if(match_iterator, match_last, f);
22 if(match_iterator != match_last)
23 {
24 return a(match_iterator->function());
25 }
26 return {nullptr};
27}
28
29template <typename OutputIterator, typename Context>
30struct marshall_annotation_visitor_generate
31{
32 mutable OutputIterator sink;
33 Context const* context;
34 std::string c_type;
35 bool is_out;
36 bool is_return;
37 bool is_ptr;
38
39 typedef marshall_type_visitor_generate<OutputIterator, Context> visitor_type;
40 typedef bool result_type;
41
42 bool operator()(attributes::regular_type_def const& regular) const
43 {
44 using attributes::regular_type_def;
45 struct match
46 {
47 eina::optional<std::string> name;
48 eina::optional<bool> has_own;
49 std::function<std::string()> function;
50 };
51 match const parameter_match_table[] =
52 {
53 // signed primitives
54 {"bool", nullptr, [&] { return " [MarshalAs(UnmanagedType.I1)]"; }},
55 {"string", true, [&] {
56 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringPassOwnershipMarshaler))]";
57 }},
58 {"string", false, [&] {
59 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringKeepOwnershipMarshaler))]";
60 }},
61 {"mstring", true, [&] {
62 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringPassOwnershipMarshaler))]";
63 }},
64 {"mstring", false, [&] {
65 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringKeepOwnershipMarshaler))]";
66 }},
67 {"stringshare", true, [&] {
68 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringsharePassOwnershipMarshaler))]";
69 }},
70 {"stringshare", false, [&] {
71 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringshareKeepOwnershipMarshaler))]";
72 }},
73 {"any_value_ptr", true, [&] {
74 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(eina.ValueMarshalerOwn))]";
75 }},
76 {"any_value_ptr", false, [&] {
77 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(eina.ValueMarshaler))]";
78 }},
79 };
80 match const return_match_table[] =
81 {
82 // signed primitives
83 {"bool", nullptr, [&] { return " [return: MarshalAs(UnmanagedType.I1)]"; }},
84 {"string", true, [&] {
85 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringPassOwnershipMarshaler))]";
86 }},
87 {"string", false, [&] {
88 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringKeepOwnershipMarshaler))]";
89 }},
90 {"mstring", true, [&] {
91 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringPassOwnershipMarshaler))]";
92 }},
93 {"mstring", false, [&] {
94 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringKeepOwnershipMarshaler))]";
95 }},
96 {"stringshare", true, [&] {
97 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringsharePassOwnershipMarshaler))]";
98 }},
99 {"stringshare", false, [&] {
100 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringshareKeepOwnershipMarshaler))]";
101 }},
102 {"any_value_ptr", true, [&] {
103 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(eina.ValueMarshalerOwn))]";
104 }},
105 {"any_value_ptr", false, [&] {
106 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(eina.ValueMarshaler))]";
107 }},
108 };
109
110 if(eina::optional<bool> b = call_annotation_match
111 ((is_return ? return_match_table : parameter_match_table)
112 , [&] (match const& m)
113 {
114 return (!m.name || *m.name == regular.base_type)
115 && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own))
116 ;
117 }
118 , [&] (std::string const& string)
119 {
120 std::copy(string.begin(), string.end(), sink);
121 return true;
122 }))
123 {
124 return *b;
125 }
126 else
127 {
128 return true;
129 }
130 }
131 bool operator()(attributes::klass_name const& klass_name) const
132 {
133 const char no_return_prefix[] = "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(efl.eo.MarshalTest<";
134 const char return_prefix[] = "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(efl.eo.MarshalTest<";
135 std::vector<std::string> namespaces = escape_namespace(klass_name.namespaces);
136 return as_generator
137 ((is_return ? return_prefix : no_return_prefix)
138 << *(lower_case[string] << ".") << string
139 << "Concrete, efl.eo." << (klass_name.base_qualifier & qualifier_info::is_own ? "OwnTag" : "NonOwnTag") << ">))]"
140 ).generate(sink, std::make_tuple(namespaces, klass_name.eolian_name), *context);
141 }
142 bool operator()(attributes::complex_type_def const&) const
143 {
144 return true;
145 }
146};
147
148template <typename OutputIterator, typename Context>
149struct marshall_native_annotation_visitor_generate
150{
151 mutable OutputIterator sink;
152 Context const* context;
153 std::string c_type;
154 bool is_out;
155 bool is_return;
156 bool is_ptr;
157
158 typedef marshall_type_visitor_generate<OutputIterator, Context> visitor_type;
159 typedef bool result_type;
160
161 bool operator()(attributes::regular_type_def const& regular) const
162 {
163 using attributes::regular_type_def;
164 struct match
165 {
166 eina::optional<std::string> name;
167 eina::optional<bool> has_own;
168 std::function<std::string()> function;
169 };
170 match const parameter_match_table[] =
171 {
172 // signed primitives
173 {"bool", nullptr, [&] { return " [MarshalAs(UnmanagedType.I1)]"; }},
174 {"string", true, [&] {
175 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringPassOwnershipMarshaler))]";
176 }},
177 {"string", false, [&] {
178 if (is_out)
179 return "";
180 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringKeepOwnershipMarshaler))]";
181 }},
182 {"stringshare", true, [&] {
183 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringsharePassOwnershipMarshaler))]";
184 }},
185 {"stringshare", false, [&] {
186 if (is_out)
187 return "";
188 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringshareKeepOwnershipMarshaler))]";
189 }},
190 };
191 match const return_match_table[] =
192 {
193 // signed primitives
194 {"bool", nullptr, [&] { return " [return: MarshalAs(UnmanagedType.I1)]"; }},
195 {"string", true, [&] {
196 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringPassOwnershipMarshaler))]";
197 }},
198 {"string", false, [&] { return ""; }},
199 {"stringshare", true, [&] {
200 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(efl.eo.StringsharePassOwnershipMarshaler))]";
201 }},
202 {"stringshare", false, [&] { return ""; }},
203 };
204
205 if(eina::optional<bool> b = call_annotation_match
206 ((is_return ? return_match_table : parameter_match_table)
207 , [&] (match const& m)
208 {
209 return (!m.name || *m.name == regular.base_type)
210 && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own))
211 ;
212 }
213 , [&] (std::string const& string)
214 {
215 std::copy(string.begin(), string.end(), sink);
216 return true;
217 }))
218 {
219 return *b;
220 }
221 else
222 {
223 return true;
224 }
225 }
226 bool operator()(attributes::klass_name const& klass_name) const
227 {
228 const char no_return_prefix[] = "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(efl.eo.MarshalTest<";
229 const char return_prefix[] = "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(efl.eo.MarshalTest<";
230 std::vector<std::string> namespaces = escape_namespace(klass_name.namespaces);
231 return as_generator
232 ((is_return ? return_prefix : no_return_prefix)
233 << *(lower_case[string] << ".") << string
234 << "Concrete, efl.eo." << (klass_name.base_qualifier & qualifier_info::is_own ? "OwnTag" : "NonOwnTag") << ">))]"
235 ).generate(sink, std::make_tuple(namespaces, klass_name.eolian_name), *context);
236 }
237 bool operator()(attributes::complex_type_def const&) const
238 {
239 return true;
240 }
241};
242
243
244} }
245
246#endif