summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/marshall_type_impl.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_type_impl.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_type_impl.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh263
1 files changed, 263 insertions, 0 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
new file mode 100644
index 0000000000..caeb17f83f
--- /dev/null
+++ b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
@@ -0,0 +1,263 @@
1#ifndef EOLIAN_MONO_MARSHALL_TYPE_IMPL_HH
2#define EOLIAN_MONO_MARSHALL_TYPE_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#include "generation_contexts.hh"
10
11namespace eolian_mono {
12
13namespace eina = efl::eina;
14
15namespace detail {
16
17template <typename OutputIterator, typename Context>
18struct marshall_type_visitor_generate
19{
20 mutable OutputIterator sink;
21 Context const* context;
22 std::string c_type;
23 bool is_out;
24 bool is_return;
25 bool is_ptr;
26
27 typedef marshall_type_visitor_generate<OutputIterator, Context> visitor_type;
28 typedef bool result_type;
29
30 bool operator()(attributes::regular_type_def const& regular) const
31 {
32 using attributes::regular_type_def;
33 bool is_inherit_native = context_find_tag<class_context>(*context).current_wrapper_kind == class_context::inherit_native;
34
35 struct match
36 {
37 eina::optional<std::string> name;
38 eina::optional<bool> has_own;
39 std::function<attributes::type_def::variant_type()> function;
40 }
41 const match_table[] =
42 {
43 // signed primitives
44 {"string", true, [&]
45 {
46 regular_type_def r = regular;
47 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
48 // if(is_out || is_return)
49 return replace_base_type(r, " System.String");
50 // else return replace_base_type(r, " ::efl::eina::string_view");
51 }}
52 , {"string", false, [&]
53 {
54 regular_type_def r = regular;
55 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
56 if (is_inherit_native && (is_return || is_out))
57 return replace_base_type(r, " System.IntPtr");
58 return replace_base_type(r, " System.String");
59 }}
60 , {"mstring", true, [&]
61 {
62 regular_type_def r = regular;
63 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
64 // if(is_out || is_return)
65 return replace_base_type(r, " System.String");
66 // else return replace_base_type(r, " ::efl::eina::string_view");
67 }}
68 , {"mstring", false, [&]
69 {
70 regular_type_def r = regular;
71 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
72 if (is_inherit_native && (is_return || is_out))
73 return replace_base_type(r, " System.IntPtr");
74 return replace_base_type(r, " System.String");
75 }}
76 , {"stringshare", true, [&]
77 {
78 regular_type_def r = regular;
79 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
80 return replace_base_type(r, " System.String");
81 }}
82 , {"stringshare", false, [&]
83 {
84 regular_type_def r = regular;
85 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
86 if (is_inherit_native && (is_return || is_out))
87 return replace_base_type(r, " System.IntPtr");
88 else
89 return replace_base_type(r, " System.String");
90 }}
91 , {"Binbuf", true, [&]
92 {
93 regular_type_def r = regular;
94 r.base_type = " System.IntPtr";
95 r.namespaces.clear();
96 return r;
97 }}
98 , {"Binbuf", false, [&]
99 {
100 regular_type_def r = regular;
101 r.base_type = " System.IntPtr";
102 r.namespaces.clear();
103 return r;
104 }}
105 , {"any_value", true, [&]
106 {
107 regular_type_def r = regular;
108 r.namespaces.clear();
109 if (is_ptr)
110 r.base_type = " eina.Value";
111 else
112 r.base_type = " eina.Value_Native";
113 return r;
114 }}
115 , {"any_value", false, [&]
116 {
117 regular_type_def r = regular;
118 r.namespaces.clear();
119 if (is_ptr)
120 r.base_type = " eina.Value";
121 else
122 r.base_type = " eina.Value_Native";
123 return r;
124 }}
125 , {"any_value_ptr", true, [&]
126 {
127 regular_type_def r = regular;
128 r.namespaces.clear();
129 r.base_type = " eina.Value";
130 return r;
131 }}
132 , {"any_value_ptr", false, [&]
133 {
134 regular_type_def r = regular;
135 r.namespaces.clear();
136 r.base_type = " eina.Value";
137 return r;
138 }}
139 , {"void", nullptr, [&]
140 {
141 regular_type_def r = regular;
142 r.namespaces.clear();
143 if (is_out) // @inout too
144 r.base_type = " System.IntPtr";
145 else
146 r.base_type = " void";
147 return r;
148 }}
149 };
150
151 if(eina::optional<bool> b = call_match
152 (match_table
153 , [&] (match const& m)
154 {
155 return (!m.name || *m.name == regular.base_type)
156 && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own))
157 ;
158 }
159 , [&] (attributes::type_def::variant_type const& v)
160 {
161 return v.visit(*this); // we want to keep is_out info
162 }))
163 {
164 return *b;
165 }
166 else
167 {
168 return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return}(regular);
169 }
170 }
171 bool operator()(attributes::klass_name klass_name) const
172 {
173 return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return}(klass_name);
174 // return as_generator(" System.IntPtr").generate(sink, attributes::unused, *context);
175 }
176 bool operator()(attributes::complex_type_def const& complex) const
177 {
178 using attributes::regular_type_def;
179 using attributes::qualifier_info;
180 struct match
181 {
182 eina::optional<std::string> name;
183 eina::optional<bool> has_own;
184 eina::optional<bool> is_const;
185 std::function<attributes::type_def::variant_type()> function;
186 } const matches[] =
187 {
188 {"array", nullptr, nullptr, [&]
189 {
190 return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
191 }
192 }
193 ,{"inarray", nullptr, nullptr, [&]
194 {
195 return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
196 }
197 }
198 ,{"list", nullptr, nullptr, [&]
199 {
200 return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
201 }
202 }
203 ,{"inlist", nullptr, nullptr, [&]
204 {
205 return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
206 }
207 }
208 ,{"hash", nullptr, nullptr, [&]
209 {
210 return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
211 }
212 }
213 ,{"iterator", nullptr, nullptr, [&]
214 {
215 return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
216 }
217 }
218 };
219
220 auto default_match = [&] (attributes::complex_type_def const& complex)
221 {
222 regular_type_def no_pointer_regular = complex.outer;
223 // std::vector<attributes::pointer_indirection> pointers;
224 // pointers.swap(no_pointer_regular.pointers);
225 // if(is_out)
226 // pointers.push_back({{attributes::qualifier_info::is_none, {}}, true});
227 return visitor_type{sink, context, c_type, false}(no_pointer_regular)
228 && as_generator("<" << (type % ", ") << ">").generate(sink, complex.subtypes, *context)
229 ;
230 // && detail::generate_pointers(sink, pointers, *context, false);
231 };
232
233 if(eina::optional<bool> b = call_match
234 (matches
235 , [&] (match const& m)
236 {
237 return (!m.name || *m.name == complex.outer.base_type)
238 && (!m.has_own || *m.has_own == bool(complex.outer.base_qualifier & qualifier_info::is_own))
239 && (!m.is_const || *m.is_const == bool(complex.outer.base_qualifier & qualifier_info::is_const));
240 }
241 , [&] (attributes::type_def::variant_type const& v)
242 {
243 if(v.empty())
244 return true;
245 else if(attributes::complex_type_def const* complex
246 = eina::get<attributes::complex_type_def>(&v))
247 return default_match(*complex);
248 else
249 return v.visit(*this);
250 }))
251 {
252 return *b;
253 }
254
255 //return default_match(complex);
256 return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return}(complex);
257 // return as_generator(" System.IntPtr").generate(sink, attributes::unused, *context);
258 }
259};
260
261} }
262
263#endif