summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-04-18 23:07:22 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2018-04-26 10:55:18 -0300
commit1837e2de10dd3231f9c8efbbf0b042a853980516 (patch)
tree5b60d96768f1c04e7356bfd1073963edc2ba2db3 /src/bin/eolian_mono
parentff1fda829d1b5b9678b2cb9054d7476dbce4b27d (diff)
efl_mono: Fix support for event arguments.
Summary: Using a type visitor scheme similar to type and marshall_type, to ease increasing coverage for other types if needed. Also, changed the filter functions for those selections to check for the full name of the regular_type_def, allowing a better specificity of the name selections. This fixes things like "Eina.Error", which was conflicting with Efl.Image.Load.Error when we compared only the last name. It didn't appear before as Load.Error only appears in a Efl.Image.Load event. Depends on D5996 Reviewers: felipealmeida Reviewed By: felipealmeida Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D5997
Diffstat (limited to 'src/bin/eolian_mono')
-rw-r--r--src/bin/eolian_mono/eolian/mono/events.hh73
-rw-r--r--src/bin/eolian_mono/eolian/mono/type_impl.hh5
2 files changed, 64 insertions, 14 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh
index 34aeab5fe0..b73e7d5bbd 100644
--- a/src/bin/eolian_mono/eolian/mono/events.hh
+++ b/src/bin/eolian_mono/eolian/mono/events.hh
@@ -1,32 +1,73 @@
1#ifndef EOLIAN_MONO_EVENTS_HH 1#ifndef EOLIAN_MONO_EVENTS_HH
2#define EOLINA_MONO_EVENTS_HH 2#define EOLINA_MONO_EVENTS_HH
3 3
4#include <iterator>
5
4#include "grammar/generator.hpp" 6#include "grammar/generator.hpp"
5#include "grammar/klass_def.hpp" 7#include "grammar/klass_def.hpp"
8#include "type_impl.hh" // For call_match
6#include "name_helpers.hh" 9#include "name_helpers.hh"
7#include "using_decl.hh" 10#include "using_decl.hh"
8 11
9namespace eolian_mono { 12namespace eolian_mono {
10 13
11struct get_event_args_visitor 14template<typename OutputIterator, typename Context>
15struct unpack_event_args_visitor
12{ 16{
17 mutable OutputIterator sink;
18 Context const* context;
13 std::string arg_type; 19 std::string arg_type;
20 attributes::type_def const& type;
14 21
15 typedef get_event_args_visitor visitor_type; 22 typedef unpack_event_args_visitor<OutputIterator, Context> visitor_type;
16 typedef std::string result_type; 23 typedef bool result_type;
17 std::string operator()(grammar::attributes::regular_type_def const&) const 24 bool operator()(grammar::attributes::regular_type_def const& regular) const
18 { 25 {
19 if (arg_type == "string") 26 std::string const& arg = "evt.Info";
20 return "eina.StringConversion.NativeUtf8ToManagedString(evt.Info)"; 27
21 return "(" + arg_type + ")Marshal.PtrToStructure(evt.Info, typeof(" + arg_type + "))"; 28 // Structs are usually passed by pointer to events, like having a ptr<> modifier
29 if (type.is_ptr || regular.is_struct())
30 return as_generator("(" + arg_type + ")Marshal.PtrToStructure(" + arg + ", typeof(" + arg_type + "))")
31 .generate(sink, attributes::unused, *context);
32
33 using attributes::regular_type_def;
34 struct match
35 {
36 eina::optional<std::string> name;
37 std::function<std::string()> function;
38 }
39 const match_table [] =
40 {
41 {"bool", [&arg] { return arg + " != IntPtr.Zero"; }}
42 , {"int", [&arg] { return arg + ".ToInt32()"; }}
43 , {"uint", [&arg] { return "(uint)" + arg + ".ToInt32()";}}
44 , {"string", [&arg] { return "eina.StringConversion.NativeUtf8ToManagedString(" + arg + ")"; }}
45 , {"Eina.Error", [&arg] { return "(eina.Error)Marshal.PtrToStructure(" + arg + ", typeof(eina.Error))"; }}
46 };
47
48 std::string full_type_name = name_helpers::type_full_name(regular);
49 auto filter_func = [&regular, &full_type_name] (match const& m)
50 {
51 return (!m.name || *m.name == regular.base_type || *m.name == full_type_name);
52 };
53
54 auto accept_func = [&](std::string const& conversion)
55 {
56 return as_generator(conversion).generate(sink, attributes::unused, *context);
57 };
58
59 if (eina::optional<bool> b = call_match(match_table, filter_func, accept_func))
60 return *b;
61 else
62 return as_generator("default(" + arg_type + ")").generate(sink, attributes::unused, *context);
22 } 63 }
23 std::string operator()(grammar::attributes::klass_name const&) const 64 bool operator()(grammar::attributes::klass_name const&) const
24 { 65 {
25 return "new " + arg_type + "Concrete(evt.Info)"; 66 return as_generator("new " + arg_type + "Concrete(evt.Info)").generate(sink, attributes::unused, *context);
26 } 67 }
27 std::string operator()(attributes::complex_type_def const&) const 68 bool operator()(attributes::complex_type_def const&) const
28 { 69 {
29 return "UNSUPPORTED"; 70 return as_generator("UNSUPPORTED").generate(sink, attributes::unused, *context);
30 } 71 }
31}; 72};
32 73
@@ -138,7 +179,15 @@ struct event_definition_generator
138 wrapper_args_template = "<" + wrapper_args_type + ">"; 179 wrapper_args_template = "<" + wrapper_args_type + ">";
139 std::string arg_type = wrapper_args_type + " args = new " + wrapper_args_type + "();\n"; // = (*etype).original_type.visit(get_csharp_type_visitor{}); 180 std::string arg_type = wrapper_args_type + " args = new " + wrapper_args_type + "();\n"; // = (*etype).original_type.visit(get_csharp_type_visitor{});
140 std::string actual_arg_type = (*etype).original_type.visit(name_helpers::get_csharp_type_visitor{}); 181 std::string actual_arg_type = (*etype).original_type.visit(name_helpers::get_csharp_type_visitor{});
141 arg_type += " args.arg = " + (*etype).original_type.visit(get_event_args_visitor{actual_arg_type}) + ";\n"; 182
183 arg_type += " args.arg = ";
184
185 auto arg_type_sink = std::back_inserter(arg_type);
186
187 if (!(*etype).original_type.visit(unpack_event_args_visitor<decltype(arg_type_sink), Context>{arg_type_sink, &context, actual_arg_type, *etype}))
188 return false;
189
190 arg_type += ";\n";
142 191
143 event_args = arg_type; 192 event_args = arg_type;
144 } 193 }
diff --git a/src/bin/eolian_mono/eolian/mono/type_impl.hh b/src/bin/eolian_mono/eolian/mono/type_impl.hh
index 169ae18333..edd6cc80ed 100644
--- a/src/bin/eolian_mono/eolian/mono/type_impl.hh
+++ b/src/bin/eolian_mono/eolian/mono/type_impl.hh
@@ -115,7 +115,7 @@ struct visitor_generate
115 r.base_type = " void"; 115 r.base_type = " void";
116 return r; 116 return r;
117 }} 117 }}
118 , {"Error", nullptr, [&] // Eina.Error 118 , {"Eina.Error", nullptr, [&] // Eina.Error
119 { 119 {
120 return regular_type_def{" eina.Error", regular.base_qualifier, {}}; 120 return regular_type_def{" eina.Error", regular.base_qualifier, {}};
121 }} // TODO 121 }} // TODO
@@ -164,11 +164,12 @@ struct visitor_generate
164 // .generate(sink, attributes::unused, *context); 164 // .generate(sink, attributes::unused, *context);
165 // } 165 // }
166 // else 166 // else
167 std::string full_type_name = name_helpers::type_full_name(regular);
167 if(eina::optional<bool> b = call_match 168 if(eina::optional<bool> b = call_match
168 (match_table 169 (match_table
169 , [&] (match const& m) 170 , [&] (match const& m)
170 { 171 {
171 return (!m.name || *m.name == regular.base_type) 172 return (!m.name || *m.name == regular.base_type || *m.name == full_type_name)
172 && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own)) 173 && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own))
173 ; 174 ;
174 } 175 }