forked from enlightenment/efl
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.
This commit is contained in:
parent
9472ec86ec
commit
590cd74906
|
@ -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#.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue