summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-12-21 00:15:17 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2019-01-14 16:18:05 +0900
commitede219c45334afe88f4f6e08a05ac67dd289ac28 (patch)
treec6cde107a1fb50adabb0c5dd17bc3c5978646568 /src/bin/eolian_mono
parent49d4d44926ee6bc7aeaefed53553f414dae4d0c4 (diff)
efl-mono: Fix marshalling of struct in event data.
Summary: Previously, we just converted through PtrToStructure, which didn't have the full marshalling info converting from the internal one to the external. This fixes the usage of the Efl.Loop.arguments event. Also renamed the ToExternal methods to ToManaged, to make clearer that the output struct is the one intended to be used from the managed code. Also fixed a minor styling in the generated code (making it easier to be inspected). Depends on D7538 Reviewers: segfaultxavi, felipealmeida, bu5hm4n Reviewed By: bu5hm4n Subscribers: bu5hm4n, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D7539
Diffstat (limited to 'src/bin/eolian_mono')
-rw-r--r--src/bin/eolian_mono/eolian/mono/events.hh25
-rw-r--r--src/bin/eolian_mono/eolian/mono/parameter.hh8
-rw-r--r--src/bin/eolian_mono/eolian/mono/struct_definition.hh22
3 files changed, 35 insertions, 20 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh
index 6e02765..22849a9 100644
--- a/src/bin/eolian_mono/eolian/mono/events.hh
+++ b/src/bin/eolian_mono/eolian/mono/events.hh
@@ -25,10 +25,19 @@ struct unpack_event_args_visitor
25 std::string const& arg = "evt.Info"; 25 std::string const& arg = "evt.Info";
26 std::string arg_type = name_helpers::type_full_managed_name(regular); 26 std::string arg_type = name_helpers::type_full_managed_name(regular);
27 27
28 // Structs are usually passed by pointer to events, like having a ptr<> modifier 28 if (regular.is_struct())
29 if (type.is_ptr || regular.is_struct()) 29 {
30 return as_generator("(" + arg_type + ")Marshal.PtrToStructure(" + arg + ", typeof(" + arg_type + "))") 30 // Structs are usually passed by pointer to events, like having a ptr<> modifier
31 // Uses implicit conversion from IntPtr
32 return as_generator(
33 " evt.Info;"
34 ).generate(sink, attributes::unused, *context);
35 }
36 else if (type.is_ptr)
37 {
38 return as_generator("(" + arg_type + ")Marshal.PtrToStructure(" + arg + ", typeof(" + arg_type + "))")
31 .generate(sink, attributes::unused, *context); 39 .generate(sink, attributes::unused, *context);
40 }
32 41
33 using attributes::regular_type_def; 42 using attributes::regular_type_def;
34 struct match 43 struct match
@@ -84,21 +93,15 @@ struct event_argument_wrapper_generator
84 return true; 93 return true;
85 94
86 std::string evt_name = name_helpers::managed_event_name(evt.name); 95 std::string evt_name = name_helpers::managed_event_name(evt.name);
87 std::string arg_type;
88 if (!as_generator(type).generate(std::back_inserter(arg_type), *etype, efl::eolian::grammar::context_null()))
89 {
90 EINA_CXX_DOM_LOG_ERR(eolian_mono::domain) << "Failed to get argument type for event " << evt.name;
91 return false;
92 }
93 96
94 return as_generator("///<summary>Event argument wrapper for event <see cref=\"" 97 return as_generator("///<summary>Event argument wrapper for event <see cref=\""
95 << join_namespaces(evt.klass.namespaces, '.', managed_namespace) 98 << join_namespaces(evt.klass.namespaces, '.', managed_namespace)
96 << klass_interface_name(evt.klass) << "." << evt_name << "\"/>.</summary>\n" 99 << klass_interface_name(evt.klass) << "." << evt_name << "\"/>.</summary>\n"
97 << "public class " << name_helpers::managed_event_args_short_name(evt) << " : EventArgs {\n" 100 << "public class " << name_helpers::managed_event_args_short_name(evt) << " : EventArgs {\n"
98 << scope_tab << "///<summary>Actual event payload.</summary>\n" 101 << scope_tab << "///<summary>Actual event payload.</summary>\n"
99 << scope_tab << "public " << arg_type << " arg { get; set; }\n" 102 << scope_tab << "public " << type << " arg { get; set; }\n"
100 << "}\n" 103 << "}\n"
101 ).generate(sink, attributes::unused, context); 104 ).generate(sink, *etype, context);
102 } 105 }
103} const event_argument_wrapper {}; 106} const event_argument_wrapper {};
104 107
diff --git a/src/bin/eolian_mono/eolian/mono/parameter.hh b/src/bin/eolian_mono/eolian/mono/parameter.hh
index 70d22fb..416cacb 100644
--- a/src/bin/eolian_mono/eolian/mono/parameter.hh
+++ b/src/bin/eolian_mono/eolian/mono/parameter.hh
@@ -559,7 +559,7 @@ struct native_convert_in_variable_generator
559 else if (helpers::need_struct_conversion(regular)) 559 else if (helpers::need_struct_conversion(regular))
560 { 560 {
561 return as_generator( 561 return as_generator(
562 "var " << string << " = " << type << "_StructConversion.ToExternal(" << escape_keyword(param.param_name) << ");\n" 562 "var " << string << " = " << type << "_StructConversion.ToManaged(" << escape_keyword(param.param_name) << ");\n"
563 ).generate(sink, std::make_tuple(in_variable_name(param.param_name), param.type), context); 563 ).generate(sink, std::make_tuple(in_variable_name(param.param_name), param.type), context);
564 } 564 }
565 else if (param.type.c_type == "Eina_Binbuf *" || param.type.c_type == "const Eina_Binbuf *") 565 else if (param.type.c_type == "Eina_Binbuf *" || param.type.c_type == "const Eina_Binbuf *")
@@ -898,7 +898,7 @@ struct convert_out_assign_generator
898 else if (helpers::need_struct_conversion(regular)) 898 else if (helpers::need_struct_conversion(regular))
899 { 899 {
900 return as_generator( 900 return as_generator(
901 string << " = " << type << "_StructConversion.ToExternal(" << out_variable_name(param.param_name) << ");\n" 901 string << " = " << type << "_StructConversion.ToManaged(" << out_variable_name(param.param_name) << ");\n"
902 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), param.type), context); 902 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), param.type), context);
903 } 903 }
904 else if (param_is_acceptable(param, "Eina_Binbuf *", WANT_OWN, WANT_OUT) 904 else if (param_is_acceptable(param, "Eina_Binbuf *", WANT_OWN, WANT_OUT)
@@ -1002,7 +1002,7 @@ struct convert_in_ptr_assign_generator
1002 if (param_should_use_in_var(param, true) && param.type.is_ptr && !param.type.has_own && helpers::need_struct_conversion(regular)) 1002 if (param_should_use_in_var(param, true) && param.type.is_ptr && !param.type.has_own && helpers::need_struct_conversion(regular))
1003 { 1003 {
1004 return as_generator( 1004 return as_generator(
1005 string << " = " << type << "_StructConversion.ToExternal(" << in_variable_name(param.param_name) << ");\n" 1005 string << " = " << type << "_StructConversion.ToManaged(" << in_variable_name(param.param_name) << ");\n"
1006 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), param.type), context); 1006 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), param.type), context);
1007 } 1007 }
1008 1008
@@ -1040,7 +1040,7 @@ struct convert_return_generator
1040 else if (helpers::need_struct_conversion(regular)) 1040 else if (helpers::need_struct_conversion(regular))
1041 { 1041 {
1042 return as_generator( 1042 return as_generator(
1043 "return " << type << "_StructConversion.ToExternal(_ret_var);\n" 1043 "return " << type << "_StructConversion.ToManaged(_ret_var);\n"
1044 ).generate(sink, ret_type, context); 1044 ).generate(sink, ret_type, context);
1045 } 1045 }
1046 else if (ret_type.c_type == "Eina_Binbuf *" || ret_type.c_type == "const Eina_Binbuf *") 1046 else if (ret_type.c_type == "Eina_Binbuf *" || ret_type.c_type == "const Eina_Binbuf *")
diff --git a/src/bin/eolian_mono/eolian/mono/struct_definition.hh b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
index 99347ed..0eda387 100644
--- a/src/bin/eolian_mono/eolian/mono/struct_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
@@ -56,6 +56,8 @@ struct struct_definition_generator
56 return false; 56 return false;
57 } 57 }
58 58
59 auto struct_name = binding_struct_name(struct_);
60
59 // Check whether this is an extern struct without declared fields in .eo file and generate a 61 // Check whether this is an extern struct without declared fields in .eo file and generate a
60 // placeholder field if positive. 62 // placeholder field if positive.
61 // Mono's JIT is picky when generating function pointer for delegates with empty structs, leading to 63 // Mono's JIT is picky when generating function pointer for delegates with empty structs, leading to
@@ -68,7 +70,6 @@ struct struct_definition_generator
68 else 70 else
69 { 71 {
70 // Constructor with default parameters for easy struct initialization 72 // Constructor with default parameters for easy struct initialization
71 auto struct_name = binding_struct_name(struct_);
72 if(!as_generator( 73 if(!as_generator(
73 scope_tab << "///<summary>Constructor for " << string << ".</summary>\n" 74 scope_tab << "///<summary>Constructor for " << string << ".</summary>\n"
74 << scope_tab << "public " << string << "(\n" 75 << scope_tab << "public " << string << "(\n"
@@ -81,6 +82,16 @@ struct struct_definition_generator
81 return false; 82 return false;
82 } 83 }
83 84
85 if(!as_generator(
86 "public static implicit operator " << struct_name << "(IntPtr ptr)\n"
87 << scope_tab << "{\n"
88 << scope_tab << scope_tab << "var tmp = (" << struct_name << "_StructInternal)Marshal.PtrToStructure(ptr, typeof(" << struct_name << "_StructInternal));\n"
89 << scope_tab << scope_tab << "return " << struct_name << "_StructConversion.ToManaged(tmp);\n"
90 << scope_tab << "}\n"
91 ).generate(sink, attributes::unused, context))
92 return false;
93
94
84 if(!as_generator("}\n").generate(sink, attributes::unused, context)) return false; 95 if(!as_generator("}\n").generate(sink, attributes::unused, context)) return false;
85 96
86 return true; 97 return true;
@@ -120,7 +131,8 @@ struct struct_internal_definition_generator
120 .generate(sink, nullptr, context)) 131 .generate(sink, nullptr, context))
121 return false; 132 return false;
122 } 133 }
123 else if (!as_generator(eolian_mono::marshall_annotation(false) << " public " << eolian_mono::marshall_type(false) << " " << string << ";\n") 134 else if (!as_generator(scope_tab << eolian_mono::marshall_annotation(false) << "\n"
135 << scope_tab << "public " << eolian_mono::marshall_type(false) << " " << string << ";\n")
124 .generate(sink, std::make_tuple(field.type, field.type, field_name), context)) 136 .generate(sink, std::make_tuple(field.type, field.type, field_name), context))
125 return false; 137 return false;
126 } 138 }
@@ -142,7 +154,7 @@ struct struct_internal_definition_generator
142 scope_tab << "///<summary>Implicit conversion to the internal/marshalling representation.</summary>\n" 154 scope_tab << "///<summary>Implicit conversion to the internal/marshalling representation.</summary>\n"
143 << scope_tab << "public static implicit operator " << string << "(" << string << " struct_)\n" 155 << scope_tab << "public static implicit operator " << string << "(" << string << " struct_)\n"
144 << scope_tab << "{\n" 156 << scope_tab << "{\n"
145 << scope_tab << scope_tab << "return " << string << "_StructConversion.ToExternal(struct_);\n" 157 << scope_tab << scope_tab << "return " << string << "_StructConversion.ToManaged(struct_);\n"
146 << scope_tab << "}\n" 158 << scope_tab << "}\n"
147 << scope_tab << "///<summary>Implicit conversion to the managed representation.</summary>\n" 159 << scope_tab << "///<summary>Implicit conversion to the managed representation.</summary>\n"
148 << scope_tab << "public static implicit operator " << string << "(" << string << " struct_)\n" 160 << scope_tab << "public static implicit operator " << string << "(" << string << " struct_)\n"
@@ -315,7 +327,7 @@ struct to_external_field_convert_generator
315 else if (helpers::need_struct_conversion(regular)) 327 else if (helpers::need_struct_conversion(regular))
316 { 328 {
317 if (!as_generator( 329 if (!as_generator(
318 scope_tab << scope_tab << "_external_struct." << string << " = " << type << "_StructConversion.ToExternal(_internal_struct." << string << ");\n") 330 scope_tab << scope_tab << "_external_struct." << string << " = " << type << "_StructConversion.ToManaged(_internal_struct." << string << ");\n")
319 .generate(sink, std::make_tuple(field_name, field.type, field_name), context)) 331 .generate(sink, std::make_tuple(field_name, field.type, field_name), context))
320 return false; 332 return false;
321 } 333 }
@@ -406,7 +418,7 @@ struct struct_binding_conversion_functions_generator
406 // to external 418 // to external
407 if (!as_generator 419 if (!as_generator
408 ( 420 (
409 scope_tab << "internal static " << string << " ToExternal(" << string << " _internal_struct)\n" 421 scope_tab << "internal static " << string << " ToManaged(" << string << " _internal_struct)\n"
410 << scope_tab << "{\n" 422 << scope_tab << "{\n"
411 << scope_tab << scope_tab << "var _external_struct = new " << string << "();\n\n" 423 << scope_tab << scope_tab << "var _external_struct = new " << string << "();\n\n"
412 ) 424 )