From df3b28b0ab650beb5d0fede24b164d2cc9c40ba9 Mon Sep 17 00:00:00 2001 From: Felipe Magno de Almeida Date: Tue, 9 Apr 2019 11:16:17 -0300 Subject: [PATCH] efl-mono: Make override of methods only for methods that are defined by the user Summary: Instead of overriding every method and making the callback to C, we just override the methods that are found by reflection on the type. Reviewers: bu5hm4n, vitor.sousa, segfaultxavi, woohyun, Jaehyun_Cho, YOhoho, lauromoura Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8579 --- .../eolian/mono/function_registration.hh | 7 ++++-- src/bin/eolian_mono/eolian/mono/klass.hh | 1 + src/bindings/mono/eo_mono/iwrapper.cs | 23 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/bin/eolian_mono/eolian/mono/function_registration.hh b/src/bin/eolian_mono/eolian/mono/function_registration.hh index 5898af9c27..fc044e6b72 100644 --- a/src/bin/eolian_mono/eolian/mono/function_registration.hh +++ b/src/bin/eolian_mono/eolian/mono/function_registration.hh @@ -44,7 +44,10 @@ struct function_registration_generator return false; if(!as_generator - (scope_tab << scope_tab << "descs.Add(new Efl_Op_Description() {" + (scope_tab << scope_tab + << "if (methods.FirstOrDefault(m => m.Name == \"" << string << "\") != null)\n" + << scope_tab << scope_tab << scope_tab + << "descs.Add(new Efl_Op_Description() {" #ifdef _WIN32 << "api_func = Marshal.StringToHGlobalAnsi(\"" << string << "\")" #else @@ -52,7 +55,7 @@ struct function_registration_generator #endif << ", func = Marshal.GetFunctionPointerForDelegate(" << string << "_static_delegate)});\n" ) - .generate(sink, std::make_tuple(f.c_name, f.c_name), context)) + .generate(sink, std::make_tuple(name_helpers::managed_method_name(f), f.c_name, f.c_name), context)) return false; return true; } diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh index e34a126321..87ad1bd5a7 100644 --- a/src/bin/eolian_mono/eolian/mono/klass.hh +++ b/src/bin/eolian_mono/eolian/mono/klass.hh @@ -369,6 +369,7 @@ struct klass << scope_tab << "public override System.Collections.Generic.List GetEoOps(System.Type type)\n" << scope_tab << "{\n" << scope_tab << scope_tab << "var descs = new System.Collections.Generic.List();\n" + << scope_tab << scope_tab << "var methods = Efl.Eo.Globals.GetUserMethods(type);\n" ) .generate(sink, attributes::unused, inative_cxt)) return false; diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs index 1aab776f26..f3696606d2 100644 --- a/src/bindings/mono/eo_mono/iwrapper.cs +++ b/src/bindings/mono/eo_mono/iwrapper.cs @@ -302,6 +302,29 @@ public class Globals return null; } + public static System.Collections.Generic.List + GetUserMethods(System.Type type) + { + var r = new System.Collections.Generic.List(); + r.AddRange(type.GetMethods()); + var base_type = type.BaseType; + + for (;base_type != null; base_type = base_type.BaseType) + { + var attrs = System.Attribute.GetCustomAttributes(type); + foreach (var attr in attrs) + { + if (attr is Efl.Eo.NativeClass) + { + return r; + } + } + + r.AddRange(base_type.GetMethods()); + } + return r; + } + public static byte class_initializer_call(IntPtr klass, System.Type type) { Eina.Log.Debug($"called with 0x{klass.ToInt64():x} {type}");