diff options
author | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-12-10 18:18:45 -0300 |
---|---|---|
committer | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-12-11 00:20:44 -0300 |
commit | 590cd749060a1f2135fecf346fc120b2a0ce8a44 (patch) | |
tree | 69c4f30db35deca316b16e507c1b955113175908 | |
parent | 9472ec86ecc6f43f35591f4a5817bbd9b5a1f3b3 (diff) | |
download | efl-590cd749060a1f2135fecf346fc120b2a0ce8a44.tar.gz |
csharp: Add context information about marshaling direction
This will be used to differentiate annotations between calls from C# to
C functions (DllImport-like) and delegates C# gives to C to be called
back (virtual methods and callbacks).
By default, the root context assumes the managed code calling the native
code.
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/function_definition.hh | 4 | ||||
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/generation_contexts.hh | 32 | ||||
-rw-r--r-- | src/bin/eolian_mono/eolian_mono.cc | 3 |
3 files changed, 37 insertions, 2 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh b/src/bin/eolian_mono/eolian/mono/function_definition.hh index cded973d23..5259437e18 100644 --- a/src/bin/eolian_mono/eolian/mono/function_definition.hh +++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh @@ -54,6 +54,8 @@ struct native_function_definition_generator auto const& indent = current_indentation(context); + auto native_to_managed_context = marshall_direction::from_native_to_managed(context); + // Delegate for the C# method we will export to EO as a method implementation. if(!as_generator ( @@ -69,7 +71,7 @@ struct native_function_definition_generator (marshall_annotation << " " << marshall_parameter) ) % ", ") << ");\n\n") - .generate(sink, std::make_tuple(f.return_type, f.return_type, f.c_name, f.parameters), context)) + .generate(sink, std::make_tuple(f.return_type, f.return_type, f.c_name, f.parameters), native_to_managed_context)) return false; // API delegate is the wrapper for the Eo methods exported from C that we will use from C#. diff --git a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh index f7376f056a..a433d942b7 100644 --- a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh +++ b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh @@ -50,6 +50,38 @@ struct class_context {} }; +struct marshall_direction +{ + enum direction { + managed_to_native, // Used for DllImport'd methods + native_to_managed, // Used for delegates of functions passed to C to be called back + }; + + direction current_dir; + + constexpr marshall_direction(direction direction) + : current_dir(direction) + {} + + template<typename Context> + static inline constexpr Context from_native_to_managed(Context const& context) + { + return efl::eolian::grammar::context_replace_tag(marshall_direction(marshall_direction::native_to_managed), context); + } + + template<typename Context> + static inline constexpr Context from_managed_to_native(Context const& context) + { + return efl::eolian::grammar::context_replace_tag(marshall_direction(marshall_direction::managed_to_native), context); + } + + template<typename Context> + static inline constexpr marshall_direction::direction current_direction(Context const& context) + { + return efl::eolian::grammar::context_find_tag<marshall_direction>(context).current_dir; + } +}; + struct indentation_context { constexpr indentation_context(indentation_context const& other) = default; diff --git a/src/bin/eolian_mono/eolian_mono.cc b/src/bin/eolian_mono/eolian_mono.cc index 62eed11b2a..0d4e58616c 100644 --- a/src/bin/eolian_mono/eolian_mono.cc +++ b/src/bin/eolian_mono/eolian_mono.cc @@ -181,6 +181,7 @@ run(options_type const& opts) using efl::eolian::grammar::context_add_tag; auto context = context_add_tag(eolian_mono::indentation_context{0}, + context_add_tag(eolian_mono::marshall_direction{eolian_mono::marshall_direction::managed_to_native}, context_add_tag(eolian_mono::eolian_state_context{opts.state}, context_add_tag(eolian_mono::options_context{opts.want_beta, opts.examples_dir}, @@ -188,7 +189,7 @@ run(options_type const& opts) opts.v_major, opts.v_minor, opts.references_map}, - efl::eolian::grammar::context_null())))); + efl::eolian::grammar::context_null()))))); EINA_ITERATOR_FOREACH(aliases, tp) { |