lauromoura pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=f793939315b37a6a8332af0ec870a0af1b6ad434
commit f793939315b37a6a8332af0ec870a0af1b6ad434 Author: Lauro Moura <lauromo...@expertisesolutions.com.br> Date: Mon Dec 9 16:40:13 2019 -0300 csharp: Refactor annotation selection function Summary: Better names to convey their intent and formatting. Removing the hardcoded `return` from them will also free the return list to be used for `@out` parameters as they have similar semantics to `return`, different from regular `@in` parameters. This change in behavior will come in a future commit, and explains why are are keeping both lists for now despite being essentially the same. Ref T8515 Test Plan: Run existing tests Reviewers: felipealmeida, brunobelo, jptiz, YOhoho Reviewed By: jptiz Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8515 Differential Revision: https://phab.enlightenment.org/D10827 --- .../eolian_mono/eolian/mono/marshall_annotation.hh | 133 +++++++++++---------- 1 file changed, 69 insertions(+), 64 deletions(-) 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 <typename Array, typename F, int N, typename A> -eina::optional<bool> call_annotation_match(Array const (&array)[N], F f, A a) +template <typename Array, typename SelectionPredicate, int N, typename AcceptFunc> +eina::optional<bool> 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<bool> has_own; std::function<std::string()> 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<bool> 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)) ; + }; + + auto acceptCb = [this] (std::string const& marshalTag) + { + 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<bool> b = call_annotation_match(match_table, predicate, acceptCb)) + { + return *b; } - , [&] (std::string const& string) + else { - std::copy(string.begin(), string.end(), sink); - return true; - })) - { - return *b; - } - else - { - return true; - } + return true; + } } bool operator()(attributes::klass_name const& klass_name) const { --