efl-mono: Make override of methods only for methods that are defined by the user
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>
Tue, 9 Apr 2019 14:16:17 +0000 (11:16 -0300)
committerShinwoo Kim <cinoo.kim@samsung.com>
Wed, 17 Apr 2019 01:03:25 +0000 (10:03 +0900)
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

src/bin/eolian_mono/eolian/mono/function_registration.hh
src/bin/eolian_mono/eolian/mono/klass.hh
src/bindings/mono/eo_mono/iwrapper.cs

index 5898af9c275e20a7e0da49b95696a033f6dcf955..fc044e6b7296cc11d7dffe4a99e29386c31e97bc 100644 (file)
@@ -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;
       }
index e34a126321b4baf3e7b667ea4d48ee15636043bf..87ad1bd5a72f185ffcf796d8aace94a8064f9a9f 100644 (file)
@@ -369,6 +369,7 @@ struct klass
              << scope_tab << "public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)\n"
              << scope_tab << "{\n"
              << scope_tab << scope_tab << "var descs = new System.Collections.Generic.List<Efl_Op_Description>();\n"
+             << scope_tab << scope_tab << "var methods = Efl.Eo.Globals.GetUserMethods(type);\n"
             )
             .generate(sink, attributes::unused, inative_cxt))
            return false;
index 1aab776f26c5ff20c574cbf88f759ceb20c69a05..f3696606d2704c13b2455be5528cf1f775c2eaf1 100644 (file)
@@ -302,6 +302,29 @@ public class Globals
         return null;
     }
 
+    public static System.Collections.Generic.List<System.Reflection.MethodInfo>
+        GetUserMethods(System.Type type)
+    {
+        var r = new System.Collections.Generic.List<System.Reflection.MethodInfo>();
+        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}");