summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/struct_definition.hh
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/eolian/mono/struct_definition.hh
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/eolian/mono/struct_definition.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/struct_definition.hh22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/struct_definition.hh b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
index 99347ed1dc..0eda387668 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 )