summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-03-21 22:39:17 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2018-04-03 17:29:41 -0300
commitbffe42e71ba12292d4969bba729e67ddf03cc111 (patch)
tree629e3f9cf0381fcdd8e2e2c97cf22eb9ea2a4985 /src/bin/eolian_mono
parent3fd1566a088f167759703bdc0a099eeb907d3181 (diff)
csharp: Support argument marshalling in func ptrs
Function pointers now go through the same argument marshalling pipeline as normal functions. This will enable interfaces like Efl.Ui.Format to work properly.
Diffstat (limited to 'src/bin/eolian_mono')
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_blacklist.hh1
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_helpers.hh10
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_pointer.hh40
-rw-r--r--src/bin/eolian_mono/eolian/mono/generation_contexts.hh1
4 files changed, 34 insertions, 18 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/function_blacklist.hh b/src/bin/eolian_mono/eolian/mono/function_blacklist.hh
index b2d712c6ac..f3ec3011d5 100644
--- a/src/bin/eolian_mono/eolian/mono/function_blacklist.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_blacklist.hh
@@ -27,7 +27,6 @@ inline bool is_function_blacklisted(std::string const& c_name)
27 || c_name == "efl_ui_focus_user_parent_get" 27 || c_name == "efl_ui_focus_user_parent_get"
28 || c_name == "efl_canvas_object_scale_get" // duplicated signature 28 || c_name == "efl_canvas_object_scale_get" // duplicated signature
29 || c_name == "efl_canvas_object_scale_set" // duplicated signature 29 || c_name == "efl_canvas_object_scale_set" // duplicated signature
30 || c_name == "efl_ui_format_cb_set"
31 || c_name == "efl_access_parent_get" 30 || c_name == "efl_access_parent_get"
32 || c_name == "efl_access_name_get" 31 || c_name == "efl_access_name_get"
33 || c_name == "efl_access_name_set" 32 || c_name == "efl_access_name_set"
diff --git a/src/bin/eolian_mono/eolian/mono/function_helpers.hh b/src/bin/eolian_mono/eolian/mono/function_helpers.hh
index 2b8c912d44..acfe850032 100644
--- a/src/bin/eolian_mono/eolian/mono/function_helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_helpers.hh
@@ -10,13 +10,7 @@
10#include "grammar/list.hpp" 10#include "grammar/list.hpp"
11#include "grammar/alternative.hpp" 11#include "grammar/alternative.hpp"
12#include "grammar/attribute_reorder.hpp" 12#include "grammar/attribute_reorder.hpp"
13/* #include "type.hh" */
14/* #include "marshall_type.hh" */
15#include "parameter.hh" 13#include "parameter.hh"
16#include "function_pointer.hh"
17/* #include "keyword.hh" */
18/* #include "using_decl.hh" */
19/* #include "generation_contexts.hh" */
20 14
21namespace eolian_mono { 15namespace eolian_mono {
22 16
@@ -164,6 +158,10 @@ struct native_function_definition_epilogue_parameterized
164 { 158 {
165 return {&klass}; 159 return {&klass};
166 } 160 }
161 native_function_definition_epilogue_generator const operator()(attributes::klass_def const* klass=nullptr) const
162 {
163 return {klass};
164 }
167} const native_function_definition_epilogue; 165} const native_function_definition_epilogue;
168 166
169struct function_definition_epilogue_terminal 167struct function_definition_epilogue_terminal
diff --git a/src/bin/eolian_mono/eolian/mono/function_pointer.hh b/src/bin/eolian_mono/eolian/mono/function_pointer.hh
index 0890edcb51..2c0c193c33 100644
--- a/src/bin/eolian_mono/eolian/mono/function_pointer.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_pointer.hh
@@ -6,7 +6,9 @@
6#include <vector> 6#include <vector>
7#include <string> 7#include <string>
8 8
9#include "function_helpers.hh"
9#include "documentation.hh" 10#include "documentation.hh"
11#include "generation_contexts.hh"
10 12
11namespace eolian_mono { 13namespace eolian_mono {
12 14
@@ -21,7 +23,7 @@ static bool is_function_ptr_blacklisted(attributes::function_def const& func, st
21 23
22 std::string name = full_name.str(); 24 std::string name = full_name.str();
23 25
24 return name == "Efl.Ui.Format_Func_Cb"; 26 return false;
25} 27}
26 28
27struct function_pointer { 29struct function_pointer {
@@ -30,23 +32,29 @@ struct function_pointer {
30 { 32 {
31 // FIXME export Typedecl in eolian_cxx API 33 // FIXME export Typedecl in eolian_cxx API
32 std::vector<std::string> namespaces = escape_namespace(namesp); 34 std::vector<std::string> namespaces = escape_namespace(namesp);
35 auto funcptr_ctx = context_add_tag(class_context{class_context::function_ptr}, context);
36
37 std::string return_type;
38 if(!as_generator(eolian_mono::type(true)).generate(std::back_inserter(return_type), f.return_type, context))
39 return false;
33 40
34 if (is_function_ptr_blacklisted(f, namesp)) 41 if (is_function_ptr_blacklisted(f, namesp))
35 return true; 42 return true;
36 43
37 auto open_namespace = *("namespace " << string << " {") << "\n"; 44 auto open_namespace = *("namespace " << string << " {") << "\n";
38 if(!as_generator(open_namespace).generate(sink, namespaces, add_lower_case_context(context))) return false; 45 if(!as_generator(open_namespace).generate(sink, namespaces, add_lower_case_context(funcptr_ctx))) return false;
39 46
40 // C# visible delegate 47 // C# visible delegate
41 if (!as_generator(documentation 48 if (!as_generator(documentation
42 << "public delegate " << type << " " << string 49 << "public delegate " << type << " " << string
43 << "(" << (parameter % ", ") << ");\n") 50 << "(" << (parameter % ", ") << ");\n")
44 .generate(sink, std::make_tuple(f, f.return_type, escape_keyword(f.name), f.parameters), context)) 51 .generate(sink, std::make_tuple(f, f.return_type, escape_keyword(f.name), f.parameters), funcptr_ctx))
45 return false; 52 return false;
46 // "Internal" delegate, 1-to-1 with the Unamaged function type 53 // "Internal" delegate, 1-to-1 with the Unamaged function type
47 if (!as_generator("internal delegate " << type << " " << string // public? 54 if (!as_generator(marshall_native_annotation(true)
48 << "Internal(IntPtr data, " << (parameter % ", ") << ");\n") 55 << "internal delegate " << marshall_type(true) << " " << string // public?
49 .generate(sink, std::make_tuple(f.return_type, escape_keyword(f.name), f.parameters), context)) 56 << "Internal(IntPtr data" << *grammar::attribute_reorder<-1, -1>((", " << marshall_native_annotation << " " << marshall_parameter)) << ");\n")
57 .generate(sink, std::make_tuple(f.return_type, f.return_type, escape_keyword(f.name), f.parameters), funcptr_ctx))
50 return false; 58 return false;
51 59
52 std::string f_name = escape_keyword(f.name); 60 std::string f_name = escape_keyword(f.name);
@@ -72,21 +80,31 @@ struct function_pointer {
72 80
73 << scope_tab << "internal " << type << " ManagedCb(" << (parameter % ",") << ")\n" 81 << scope_tab << "internal " << type << " ManagedCb(" << (parameter % ",") << ")\n"
74 << scope_tab << "{\n" 82 << scope_tab << "{\n"
75 << scope_tab << scope_tab << (f.return_type.c_type != "void" ? "return ": "") << "_cb(_cb_data, " << (argument_invocation_no_conversion % ", ") << ");\n" 83 << function_definition_preamble << "_cb(_cb_data, " << (argument_invocation % ", ") << ");\n"
84 << function_definition_epilogue
76 << scope_tab << "}\n\n" 85 << scope_tab << "}\n\n"
77 86
78 << scope_tab << "internal static " << type << " Cb(IntPtr cb_data, " << (parameter % ", ") << ")\n" 87
88 << scope_tab << marshall_native_annotation(true)
89 << scope_tab << "internal static " << marshall_type(true) << " Cb(IntPtr cb_data" << *grammar::attribute_reorder<-1, -1>((", " << marshall_native_annotation << " " << marshall_parameter)) << ")\n"
79 << scope_tab << "{\n" 90 << scope_tab << "{\n"
80 << scope_tab << scope_tab << "GCHandle handle = GCHandle.FromIntPtr(cb_data);\n" 91 << scope_tab << scope_tab << "GCHandle handle = GCHandle.FromIntPtr(cb_data);\n"
81 << scope_tab << scope_tab << string << " cb = (" << string << ")handle.Target;\n" 92 << scope_tab << scope_tab << string << " cb = (" << string << ")handle.Target;\n"
82 << scope_tab << scope_tab << (f.return_type.c_type != "void" ? "return " : "") << "cb(" << (argument_invocation_no_conversion % ", ") << ");\n" 93 << native_function_definition_preamble
94 << scope_tab << scope_tab << "try {\n"
95 << scope_tab << scope_tab << scope_tab << (return_type != " void" ? "_ret_var = " : "") << "cb(" << (native_argument_invocation % ", ") << ");\n"
96 << scope_tab << scope_tab << "} catch (Exception e) {\n"
97 << scope_tab << scope_tab << scope_tab << "eina.Log.Warning($\"Callback error: {e.ToString()}\");\n"
98 << scope_tab << scope_tab << scope_tab << "eina.Error.Set(eina.Error.EFL_ERROR);\n"
99 << scope_tab << scope_tab << "}\n"
100 << native_function_definition_epilogue(nullptr)
83 << scope_tab << "}\n" 101 << scope_tab << "}\n"
84 << "}\n" 102 << "}\n"
85 ).generate(sink, std::make_tuple(f.return_type, f.parameters, f.parameters, f.return_type, f.parameters, f_name, f_name, f.parameters), context)) 103 ).generate(sink, std::make_tuple(f.return_type, f.parameters, f, f.parameters, f, f.return_type, f.return_type, f.parameters, f_name, f_name, f, f.parameters, f), funcptr_ctx))
86 return false; 104 return false;
87 105
88 auto close_namespace = *(lit("} ")) << "\n"; 106 auto close_namespace = *(lit("} ")) << "\n";
89 if(!as_generator(close_namespace).generate(sink, namespaces, context)) return false; 107 if(!as_generator(close_namespace).generate(sink, namespaces, funcptr_ctx)) return false;
90 108
91 return true; 109 return true;
92 } 110 }
diff --git a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
index 8563afcb12..d7e31ddae2 100644
--- a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
+++ b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
@@ -11,6 +11,7 @@ struct class_context
11 inherit, 11 inherit,
12 inherit_native, 12 inherit_native,
13 structs, 13 structs,
14 function_ptr,
14 }; 15 };
15 wrapper_kind current_wrapper_kind; 16 wrapper_kind current_wrapper_kind;
16}; 17};