summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/marshall_annotation.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_annotation.hh134
1 files changed, 16 insertions, 118 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
index 6ddb990..4159b6a 100644
--- a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
+++ b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
@@ -90,7 +90,7 @@ struct marshall_annotation_visitor_generate
90 {"string", true, [&] { 90 {"string", true, [&] {
91 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; 91 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]";
92 }}, 92 }},
93 {"string", false, [&] { 93 {"string", nullptr, [&] {
94 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; 94 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]";
95 }}, 95 }},
96 {"mstring", true, [&] { 96 {"mstring", true, [&] {
@@ -112,10 +112,10 @@ struct marshall_annotation_visitor_generate
112 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))]"; 112 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))]";
113 }}, 113 }},
114 {"strbuf", true, [&] { 114 {"strbuf", true, [&] {
115 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))]"; 115 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))]";
116 }}, 116 }},
117 {"strbuf", false, [&] { 117 {"strbuf", false, [&] {
118 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]"; 118 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]";
119 }}, 119 }},
120 }; 120 };
121 121
@@ -142,122 +142,22 @@ struct marshall_annotation_visitor_generate
142 } 142 }
143 bool operator()(attributes::klass_name const& klass_name) const 143 bool operator()(attributes::klass_name const& klass_name) const
144 { 144 {
145 const char no_return_prefix[] = "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Efl.Eo.MarshalTest<"; 145 const char *return_prefix = is_return ? "return:" : "";
146 const char return_prefix[] = "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Efl.Eo.MarshalTest<"; 146 const char *marshal_prefix = "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(";
147 return as_generator
148 ((is_return ? return_prefix : no_return_prefix)
149 << string << ", Efl.Eo." << (klass_name.base_qualifier & qualifier_info::is_own ? "OwnTag" : "NonOwnTag") << ">))]"
150 ).generate(sink, name_helpers::klass_full_concrete_name(klass_name), *context);
151 }
152 bool operator()(attributes::complex_type_def const& c) const
153 {
154 if (c.outer.base_type == "future")
155 {
156 std::string prefix = is_return ? "return: " : "";
157 return as_generator("[" << prefix << "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.FutureMarshaler))]").generate(sink, nullptr, *context);
158 }
159 return true;
160 }
161};
162
163template <typename OutputIterator, typename Context>
164struct marshall_native_annotation_visitor_generate
165{
166 mutable OutputIterator sink;
167 Context const* context;
168 std::string c_type;
169 bool is_out;
170 bool is_return;
171 bool is_ptr;
172 147
173 typedef marshall_type_visitor_generate<OutputIterator, Context> visitor_type; 148 std::string name = name_helpers::klass_full_concrete_name(klass_name);
174 typedef bool result_type;
175 149
176 bool operator()(attributes::regular_type_def const& regular) const 150 if (name == "Efl.Class")
177 { 151 name = "Efl.Eo.MarshalEflClass";
178 using attributes::regular_type_def; 152 else
179 struct match 153 {
180 { 154 auto own = klass_name.base_qualifier & qualifier_info::is_own ? "OwnTag" : "NonOwnTag";
181 eina::optional<std::string> name; 155 name = "Efl.Eo.MarshalTest<" + name + ", Efl.Eo." + own + ">";
182 eina::optional<bool> has_own; 156 }
183 std::function<std::string()> function;
184 };
185 match const parameter_match_table[] =
186 {
187 // signed primitives
188 {"bool", nullptr, [&] { return " [MarshalAs(UnmanagedType.U1)]"; }},
189 {"string", true, [&] {
190 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]";
191 }},
192 {"string", false, [&] {
193 if (is_out)
194 return "";
195 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]";
196 }},
197 {"stringshare", true, [&] {
198 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))]";
199 }},
200 {"stringshare", false, [&] {
201 if (is_out)
202 return "";
203 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))]";
204 }},
205 {"strbuf", true, [&] {
206 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))]";
207 }},
208 {"strbuf", false, [&] {
209 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]";
210 }},
211 };
212 match const return_match_table[] =
213 {
214 // signed primitives
215 {"bool", nullptr, [&] { return " [return: MarshalAs(UnmanagedType.U1)]"; }},
216 {"string", true, [&] {
217 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]";
218 }},
219 {"string", false, [&] { return ""; }},
220 {"stringshare", true, [&] {
221 return " [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))]";
222 }},
223 {"stringshare", false, [&] { return ""; }},
224 {"strbuf", true, [&] {
225 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))]";
226 }},
227 {"strbuf", false, [&] {
228 return " [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]";
229 }},
230 };
231 157
232 if(eina::optional<bool> b = call_annotation_match 158 return as_generator(
233 ((is_return ? return_match_table : parameter_match_table) 159 lit("[") << return_prefix << marshal_prefix << name << "))]"
234 , [&] (match const& m) 160 ).generate(sink, name, *context);
235 {
236 return (!m.name || *m.name == regular.base_type)
237 && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own))
238 ;
239 }
240 , [&] (std::string const& string)
241 {
242 std::copy(string.begin(), string.end(), sink);
243 return true;
244 }))
245 {
246 return *b;
247 }
248 else
249 {
250 return true;
251 }
252 }
253 bool operator()(attributes::klass_name const& klass_name) const
254 {
255 const char no_return_prefix[] = "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Efl.Eo.MarshalTest<";
256 const char return_prefix[] = "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Efl.Eo.MarshalTest<";
257 return as_generator
258 ((is_return ? return_prefix : no_return_prefix)
259 << string << ", Efl.Eo." << (klass_name.base_qualifier & qualifier_info::is_own ? "OwnTag" : "NonOwnTag") << ">))]"
260 ).generate(sink, name_helpers::klass_full_concrete_name(klass_name), *context);
261 } 161 }
262 bool operator()(attributes::complex_type_def const& c) const 162 bool operator()(attributes::complex_type_def const& c) const
263 { 163 {
@@ -269,8 +169,6 @@ struct marshall_native_annotation_visitor_generate
269 return true; 169 return true;
270 } 170 }
271}; 171};
272
273
274} } 172} }
275 173
276#endif 174#endif