diff --git a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh index 081145144c..90da376a73 100644 --- a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh +++ b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh @@ -28,15 +28,15 @@ namespace eina = efl::eina; namespace detail { -template -eina::optional call_annotation_match(Array const (&array)[N], F f, A a) +template +eina::optional call_annotation_match(Array const (&array)[N], SelectionPredicate predicate, AcceptFunc acceptFunc) { typedef Array const* iterator_type; iterator_type match_iterator = &array[0], match_last = match_iterator + N; - match_iterator = std::find_if(match_iterator, match_last, f); + match_iterator = std::find_if(match_iterator, match_last, predicate); if(match_iterator != match_last) { - return a(match_iterator->function()); + return acceptFunc(match_iterator->function()); } return {nullptr}; } @@ -63,103 +63,108 @@ struct marshall_annotation_visitor_generate eina::optional has_own; std::function function; }; + // These two tables are currently the same but will hold different marshallers + // for @in and @out/return semantics in a future commit. match const parameter_match_table[] = { // signed primitives - {"bool", nullptr, [&] { return "[MarshalAs(UnmanagedType.U1)]"; }}, - {"string", true, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; + {"bool", nullptr, [] { return "MarshalAs(UnmanagedType.U1)"; }}, + {"string", true, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))"; }}, - {"string", false, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; + {"string", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))"; }}, - {"mstring", true, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; + {"mstring", true, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))"; }}, - {"mstring", false, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; + {"mstring", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))"; }}, - {"stringshare", true, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))]"; + {"stringshare", true, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))"; }}, - {"stringshare", false, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))]"; + {"stringshare", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))"; }}, - {"any_value_ref", true, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))]"; + {"any_value_ref", true, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))"; }}, - {"any_value_ref", false, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))]"; + {"any_value_ref", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))"; }}, - {"strbuf", true, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))]"; + {"strbuf", true, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))"; }}, - {"strbuf", false, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]"; + {"strbuf", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))"; }}, - {"Value_Type", false, [&] { - return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))]"; + {"Value_Type", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))"; }}, }; match const return_match_table[] = { // signed primitives - {"bool", nullptr, [&] { return "[return: MarshalAs(UnmanagedType.U1)]"; }}, - {"string", true, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; + {"bool", nullptr, [] { return "MarshalAs(UnmanagedType.U1)"; }}, + {"string", true, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))"; }}, - {"string", nullptr, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; + {"string", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))"; }}, - {"mstring", true, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; + {"mstring", true, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))"; }}, - {"mstring", false, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; + {"mstring", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))"; }}, - {"stringshare", true, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))]"; + {"stringshare", true, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))"; }}, - {"stringshare", false, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))]"; + {"stringshare", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))"; }}, - {"any_value_ref", true, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))]"; + {"any_value_ref", true, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))"; }}, - {"any_value_ref", false, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))]"; + {"any_value_ref", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))"; }}, - {"strbuf", true, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))]"; + {"strbuf", true, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))"; }}, - {"strbuf", false, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]"; + {"strbuf", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))"; }}, - {"Value_Type", false, [&] { - return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))]"; + {"Value_Type", false, [] { + return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))"; }}, }; - if(eina::optional b = call_annotation_match - ((is_return ? return_match_table : parameter_match_table) - , [&] (match const& m) + auto predicate = [®ular] (match const& m) { return (!m.name || *m.name == regular.base_type) && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own)) ; - } - , [&] (std::string const& string) + }; + + auto acceptCb = [this] (std::string const& marshalTag) { - std::copy(string.begin(), string.end(), sink); - return true; - })) - { - return *b; - } - else - { - return true; - } + std::string prefix = is_return ? "return: " : ""; + return as_generator("[" << prefix << marshalTag << "]").generate(sink, nullptr, *context); + }; + + const auto& match_table = is_return ? return_match_table : parameter_match_table; + + if(eina::optional b = call_annotation_match(match_table, predicate, acceptCb)) + { + return *b; + } + else + { + return true; + } } bool operator()(attributes::klass_name const& klass_name) const {