summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2017-12-15 22:15:00 -0200
committerVitor Sousa <vitorsousasilva@gmail.com>2017-12-15 22:26:30 -0200
commit00fb5b228a0c7011381943eaa909b908336c8ff5 (patch)
treed28d58b8bc8bc9df9102e4d8219d56e7bf4e325a /src/bin
parentb55542889baaec9ae25ce13d2804d5123f040cc6 (diff)
eolian_mono: fix handling of regular ptr() types
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/eolian_mono/eolian/mono/helpers.hh25
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh15
-rw-r--r--src/bin/eolian_mono/eolian/mono/parameter.hh70
-rw-r--r--src/bin/eolian_mono/eolian/mono/struct_definition.hh14
-rw-r--r--src/bin/eolian_mono/eolian/mono/type.hh4
-rw-r--r--src/bin/eolian_mono/eolian/mono/type_impl.hh2
6 files changed, 115 insertions, 15 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/helpers.hh b/src/bin/eolian_mono/eolian/mono/helpers.hh
index 28b54a5aef..7d013bd6f5 100644
--- a/src/bin/eolian_mono/eolian/mono/helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/helpers.hh
@@ -33,7 +33,6 @@ inline std::string struct_full_name(attributes::struct_def const& struct_)
33inline bool is_struct_blacklisted(std::string const& full_name) 33inline bool is_struct_blacklisted(std::string const& full_name)
34{ 34{
35 return full_name == "Efl.Event.Description" 35 return full_name == "Efl.Event.Description"
36 // || full_name == "Eina.File"
37 || full_name == "Eina.Binbuf" 36 || full_name == "Eina.Binbuf"
38 || full_name == "Eina.Slice" 37 || full_name == "Eina.Slice"
39 || full_name == "Eina.Rw_Slice"; 38 || full_name == "Eina.Rw_Slice";
@@ -54,6 +53,30 @@ inline bool need_struct_conversion(attributes::regular_type_def const* regular)
54 return regular && regular->is_struct() && !is_struct_blacklisted(*regular); 53 return regular && regular->is_struct() && !is_struct_blacklisted(*regular);
55} 54}
56 55
56inline bool need_pointer_conversion(attributes::regular_type_def const* regular)
57{
58 if (!regular)
59 return false;
60
61 if (regular->is_enum()
62 || (regular->is_struct() && type_full_name(*regular) != "Eina.Binbuf")
63 )
64 return true;
65
66 std::set<std::string> const types {
67 "bool", "char"
68 , "byte" , "short" , "int" , "long" , "llong" , "int8" , "int16" , "int32" , "int64" , "ssize"
69 , "ubyte", "ushort", "uint", "ulong", "ullong", "uint8", "uint16", "uint32", "uint64", "size"
70 , "ptrdiff"
71 , "float", "double"
72 };
73 if (types.find(regular->base_type) != types.end())
74 return true;
75
76 return false;
77}
78
79
57} 80}
58 81
59#endif 82#endif
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
index 7950b31213..89efc7f3e2 100644
--- a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
+++ b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
@@ -149,7 +149,7 @@ struct marshall_type_visitor_generate
149 }} 149 }}
150 }; 150 };
151 151
152 if (regular.is_struct() && !is_struct_blacklisted(regular)) 152 if (!is_ptr && regular.is_struct() && !is_struct_blacklisted(regular))
153 { 153 {
154 return as_generator(*(lower_case[string] << ".") << string << "_StructInternal") 154 return as_generator(*(lower_case[string] << ".") << string << "_StructInternal")
155 .generate(sink, std::make_tuple(eolian_mono::escape_namespace(regular.namespaces), regular.base_type), *context); 155 .generate(sink, std::make_tuple(eolian_mono::escape_namespace(regular.namespaces), regular.base_type), *context);
@@ -169,14 +169,21 @@ struct marshall_type_visitor_generate
169 { 169 {
170 return *b; 170 return *b;
171 } 171 }
172 else if (is_ptr && need_pointer_conversion(&regular))
173 {
174 regular_type_def r = regular;
175 r.base_type = " System.IntPtr";
176 r.namespaces.clear();
177 return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return, is_ptr}(r);
178 }
172 else 179 else
173 { 180 {
174 return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return}(regular); 181 return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return, is_ptr}(regular);
175 } 182 }
176 } 183 }
177 bool operator()(attributes::klass_name klass_name) const 184 bool operator()(attributes::klass_name klass_name) const
178 { 185 {
179 return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return}(klass_name); 186 return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return, is_ptr}(klass_name);
180 // return as_generator(" System.IntPtr").generate(sink, attributes::unused, *context); 187 // return as_generator(" System.IntPtr").generate(sink, attributes::unused, *context);
181 } 188 }
182 bool operator()(attributes::complex_type_def const& complex) const 189 bool operator()(attributes::complex_type_def const& complex) const
@@ -259,7 +266,7 @@ struct marshall_type_visitor_generate
259 } 266 }
260 267
261 //return default_match(complex); 268 //return default_match(complex);
262 return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return}(complex); 269 return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return, is_ptr}(complex);
263 // return as_generator(" System.IntPtr").generate(sink, attributes::unused, *context); 270 // return as_generator(" System.IntPtr").generate(sink, attributes::unused, *context);
264 } 271 }
265}; 272};
diff --git a/src/bin/eolian_mono/eolian/mono/parameter.hh b/src/bin/eolian_mono/eolian/mono/parameter.hh
index 0e3fa326d5..834ca1248d 100644
--- a/src/bin/eolian_mono/eolian/mono/parameter.hh
+++ b/src/bin/eolian_mono/eolian/mono/parameter.hh
@@ -269,6 +269,9 @@ inline bool param_should_use_out_var(attributes::parameter_def const& param, boo
269 if (need_struct_conversion(regular)) 269 if (need_struct_conversion(regular))
270 return true; 270 return true;
271 271
272 if (param.type.is_ptr && need_pointer_conversion(regular))
273 return true;
274
272 return false; 275 return false;
273} 276}
274 277
@@ -314,6 +317,9 @@ inline bool param_should_use_in_var(attributes::parameter_def const& param, bool
314 if (need_struct_conversion(regular)) 317 if (need_struct_conversion(regular))
315 return true; 318 return true;
316 319
320 if (param.type.is_ptr && need_pointer_conversion(regular))
321 return true;
322
317 return false; 323 return false;
318} 324}
319 325
@@ -501,7 +507,13 @@ struct native_convert_in_variable_generator
501 return true; 507 return true;
502 508
503 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type); 509 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type);
504 if (need_struct_conversion(regular)) 510 if (param.type.is_ptr && need_pointer_conversion(regular))
511 {
512 return as_generator(
513 "var " << string << " = eina.PrimitiveConversion.PointerToManaged<" << type << ">(" << escape_keyword(param.param_name) << ");\n"
514 ).generate(sink, std::make_tuple(in_variable_name(param.param_name), param.type), context);
515 }
516 else if (need_struct_conversion(regular))
505 { 517 {
506 return as_generator( 518 return as_generator(
507 "var " << string << " = " << type << "_StructConvertion.ToExternal(" << escape_keyword(param.param_name) << ");\n" 519 "var " << string << " = " << type << "_StructConvertion.ToExternal(" << escape_keyword(param.param_name) << ");\n"
@@ -563,7 +575,13 @@ struct convert_in_variable_generator
563 return true; 575 return true;
564 576
565 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type); 577 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type);
566 if (need_struct_conversion(regular)) 578 if (param.type.is_ptr && need_pointer_conversion(regular))
579 {
580 return as_generator(
581 "var " << string << " = eina.PrimitiveConversion.ManagedToPointerAlloc(" << escape_keyword(param.param_name) << ");\n"
582 ).generate(sink, in_variable_name(param.param_name), context);
583 }
584 else if (need_struct_conversion(regular))
567 { 585 {
568 return as_generator( 586 return as_generator(
569 "var " << string << " = " << type << "_StructConvertion.ToInternal(" << escape_keyword(param.param_name) << ");\n" 587 "var " << string << " = " << type << "_StructConvertion.ToInternal(" << escape_keyword(param.param_name) << ");\n"
@@ -651,7 +669,13 @@ struct convert_out_variable_generator
651 return true; 669 return true;
652 670
653 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type); 671 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type);
654 if (need_struct_conversion(regular)) 672 if (param.type.is_ptr && need_pointer_conversion(regular))
673 {
674 return as_generator(
675 "System.IntPtr " << string << " = System.IntPtr.Zero;\n"
676 ).generate(sink, out_variable_name(param.param_name), context);
677 }
678 else if (need_struct_conversion(regular))
655 { 679 {
656 return as_generator( 680 return as_generator(
657 "var " << string << " = new " << marshall_type << "();\n" 681 "var " << string << " = new " << marshall_type << "();\n"
@@ -718,7 +742,13 @@ struct native_convert_out_variable_generator
718 return true; 742 return true;
719 743
720 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type); 744 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type);
721 if (need_struct_conversion(regular) 745 if (param.type.is_ptr && need_pointer_conversion(regular))
746 {
747 return as_generator(
748 type << " " << string << " = default(" << type << ");\n"
749 ).generate(sink, std::make_tuple(param, out_variable_name(param.param_name), param), context);
750 }
751 else if (need_struct_conversion(regular)
722 || param_is_acceptable(param, "const char *", !WANT_OWN, WANT_OUT) 752 || param_is_acceptable(param, "const char *", !WANT_OWN, WANT_OUT)
723 || param_is_acceptable(param, "Eina_Stringshare *", !WANT_OWN, WANT_OUT)) 753 || param_is_acceptable(param, "Eina_Stringshare *", !WANT_OWN, WANT_OUT))
724 { 754 {
@@ -798,7 +828,13 @@ struct convert_out_assign_generator
798 return true; 828 return true;
799 829
800 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type); 830 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type);
801 if (need_struct_conversion(regular)) 831 if (param.type.is_ptr && need_pointer_conversion(regular))
832 {
833 return as_generator(
834 string << " = eina.PrimitiveConversion.PointerToManaged<" << type << ">(" << out_variable_name(param.param_name) << ");\n"
835 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), param.type), context);
836 }
837 else if (need_struct_conversion(regular))
802 { 838 {
803 return as_generator( 839 return as_generator(
804 string << " = " << type << "_StructConvertion.ToExternal(" << out_variable_name(param.param_name) << ");\n" 840 string << " = " << type << "_StructConvertion.ToExternal(" << out_variable_name(param.param_name) << ");\n"
@@ -894,7 +930,13 @@ struct convert_return_generator
894 bool generate(OutputIterator sink, attributes::type_def const& ret_type, Context const& context) const 930 bool generate(OutputIterator sink, attributes::type_def const& ret_type, Context const& context) const
895 { 931 {
896 auto regular = efl::eina::get<attributes::regular_type_def>(&ret_type.original_type); 932 auto regular = efl::eina::get<attributes::regular_type_def>(&ret_type.original_type);
897 if (need_struct_conversion(regular)) 933 if (ret_type.is_ptr && need_pointer_conversion(regular))
934 {
935 return as_generator(
936 "return eina.PrimitiveConversion.PointerToManaged<" << type << ">(_ret_var);\n"
937 ).generate(sink, ret_type, context);
938 }
939 else if (need_struct_conversion(regular))
898 { 940 {
899 return as_generator( 941 return as_generator(
900 "return " << type << "_StructConvertion.ToExternal(_ret_var);\n" 942 "return " << type << "_StructConvertion.ToExternal(_ret_var);\n"
@@ -956,7 +998,13 @@ struct native_convert_out_assign_generator
956 return true; 998 return true;
957 999
958 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type); 1000 auto regular = efl::eina::get<attributes::regular_type_def>(&param.type.original_type);
959 if (need_struct_conversion(regular)) 1001 if (param.type.is_ptr && need_pointer_conversion(regular))
1002 {
1003 return as_generator(
1004 string << " = eina.PrimitiveConversion.ManagedToPointerAlloc(" << string << ");\n"
1005 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), out_variable_name(param.param_name)), context);
1006 }
1007 else if (need_struct_conversion(regular))
960 { 1008 {
961 return as_generator( 1009 return as_generator(
962 string << " = " << type << "_StructConvertion.ToInternal(" << string << ");\n" 1010 string << " = " << type << "_StructConvertion.ToInternal(" << string << ");\n"
@@ -1083,7 +1131,13 @@ struct native_convert_return_generator
1083 bool generate(OutputIterator sink, attributes::type_def const& ret_type, Context const& context) const 1131 bool generate(OutputIterator sink, attributes::type_def const& ret_type, Context const& context) const
1084 { 1132 {
1085 auto regular = efl::eina::get<attributes::regular_type_def>(&ret_type.original_type); 1133 auto regular = efl::eina::get<attributes::regular_type_def>(&ret_type.original_type);
1086 if (need_struct_conversion(regular)) 1134 if (ret_type.is_ptr && need_pointer_conversion(regular))
1135 {
1136 return as_generator(
1137 "return eina.PrimitiveConversion.ManagedToPointerAlloc(_ret_var);\n"
1138 ).generate(sink, attributes::unused, context);
1139 }
1140 else if (need_struct_conversion(regular))
1087 { 1141 {
1088 return as_generator( 1142 return as_generator(
1089 "return " << type << "_StructConvertion.ToInternal(_ret_var);\n" 1143 "return " << type << "_StructConvertion.ToInternal(_ret_var);\n"
diff --git a/src/bin/eolian_mono/eolian/mono/struct_definition.hh b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
index 62992357f2..85cc14cc0d 100644
--- a/src/bin/eolian_mono/eolian/mono/struct_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
@@ -156,6 +156,13 @@ struct to_internal_field_convert_generator
156 .generate(sink, std::make_tuple(field_name, field_name), context)) 156 .generate(sink, std::make_tuple(field_name, field_name), context))
157 return false; 157 return false;
158 } 158 }
159 else if (field.type.is_ptr && need_pointer_conversion(regular))
160 {
161 if (!as_generator(
162 scope_tab << scope_tab << "_internal_struct." << string << " = eina.PrimitiveConversion.ManagedToPointerAlloc(_external_struct." << string << ");\n")
163 .generate(sink, std::make_tuple(field_name, field_name), context))
164 return false;
165 }
159 else if (need_struct_conversion(regular)) 166 else if (need_struct_conversion(regular))
160 { 167 {
161 if (!as_generator( 168 if (!as_generator(
@@ -259,6 +266,13 @@ struct to_external_field_convert_generator
259 .generate(sink, std::make_tuple(field_name, field.type, field_name), context)) 266 .generate(sink, std::make_tuple(field_name, field.type, field_name), context))
260 return false; 267 return false;
261 } 268 }
269 else if (field.type.is_ptr && need_pointer_conversion(regular))
270 {
271 if (!as_generator(
272 scope_tab << scope_tab << "_external_struct." << string << " = eina.PrimitiveConversion.PointerToManaged<" << type << ">(_internal_struct." << string << ");\n")
273 .generate(sink, std::make_tuple(field_name, field.type, field_name), context))
274 return false;
275 }
262 else if (need_struct_conversion(regular)) 276 else if (need_struct_conversion(regular))
263 { 277 {
264 if (!as_generator( 278 if (!as_generator(
diff --git a/src/bin/eolian_mono/eolian/mono/type.hh b/src/bin/eolian_mono/eolian/mono/type.hh
index b0e14516ce..b968d9e0bc 100644
--- a/src/bin/eolian_mono/eolian/mono/type.hh
+++ b/src/bin/eolian_mono/eolian/mono/type.hh
@@ -20,13 +20,13 @@ struct type_generator
20 template <typename OutputIterator, typename Context> 20 template <typename OutputIterator, typename Context>
21 bool generate(OutputIterator sink, attributes::type_def const& type, Context const& context) const 21 bool generate(OutputIterator sink, attributes::type_def const& type, Context const& context) const
22 { 22 {
23 return type.original_type.visit(visitor_generate<OutputIterator, Context>{sink, &context, type.c_type, false, is_return}); 23 return type.original_type.visit(visitor_generate<OutputIterator, Context>{sink, &context, type.c_type, false, is_return, type.is_ptr});
24 } 24 }
25 template <typename OutputIterator, typename Context> 25 template <typename OutputIterator, typename Context>
26 bool generate(OutputIterator sink, attributes::parameter_def const& param, Context const& context) const 26 bool generate(OutputIterator sink, attributes::parameter_def const& param, Context const& context) const
27 { 27 {
28 return param.type.original_type.visit(visitor_generate<OutputIterator, Context>{sink, &context, param.type.c_type 28 return param.type.original_type.visit(visitor_generate<OutputIterator, Context>{sink, &context, param.type.c_type
29 , param.direction != attributes::parameter_direction::in, false}); 29 , param.direction != attributes::parameter_direction::in, false, param.type.is_ptr});
30 } 30 }
31 31
32 bool is_return; 32 bool is_return;
diff --git a/src/bin/eolian_mono/eolian/mono/type_impl.hh b/src/bin/eolian_mono/eolian/mono/type_impl.hh
index 3d3950c172..9b56805b99 100644
--- a/src/bin/eolian_mono/eolian/mono/type_impl.hh
+++ b/src/bin/eolian_mono/eolian/mono/type_impl.hh
@@ -62,6 +62,7 @@ struct visitor_generate
62 std::string c_type; 62 std::string c_type;
63 bool is_out; 63 bool is_out;
64 bool is_return; 64 bool is_return;
65 bool is_ptr;
65 66
66 typedef visitor_generate<OutputIterator, Context> visitor_type; 67 typedef visitor_generate<OutputIterator, Context> visitor_type;
67 typedef bool result_type; 68 typedef bool result_type;
@@ -102,6 +103,7 @@ struct visitor_generate
102 103
103 , {"ptrdiff", nullptr, [&] { return replace_base_integer<ptrdiff_t>(regular); }} 104 , {"ptrdiff", nullptr, [&] { return replace_base_integer<ptrdiff_t>(regular); }}
104 , {"intptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr"); }} 105 , {"intptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr"); }}
106 , {"uintptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr"); }}
105 , {"void_ptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr"); }} 107 , {"void_ptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr"); }}
106 , {"void", nullptr, [&] 108 , {"void", nullptr, [&]
107 { 109 {