summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-09-02 20:29:30 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-09-02 20:29:30 -0300
commitb53666fed90f45a12d3f87e83efe2d46dbcf7bb8 (patch)
tree4b4d364f7b0f46486344b3ea51c26ebfe24c8d1a
parentfeab8e7a51959d8e1ecbed69a3c86bc2f25d1409 (diff)
downloadefl-devs/lauromoura/csharp-interface-protected.tar.gz
WIP - Fixing property extensionsdevs/lauromoura/csharp-interface-protected
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_definition.hh15
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_helpers.hh6
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh6
-rw-r--r--src/tests/efl_mono/Eo.cs58
-rw-r--r--src/tests/efl_mono/dummy_test_iface.eo16
5 files changed, 81 insertions, 20 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh b/src/bin/eolian_mono/eolian/mono/function_definition.hh
index 653b818799..bb62a293d7 100644
--- a/src/bin/eolian_mono/eolian/mono/function_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh
@@ -307,12 +307,12 @@ struct property_wrapper_definition_generator
if (blacklist::is_property_blacklisted(property, *implementing_klass, context))
return true;
- bool interface = context_find_tag<class_context>(context).current_wrapper_kind == class_context::interface;
+ bool is_interface = context_find_tag<class_context>(context).current_wrapper_kind == class_context::interface;
bool is_static = (property.getter.is_engaged() && property.getter->is_static)
|| (property.setter.is_engaged() && property.setter->is_static);
- if (interface && is_static)
+ if (is_interface && is_static)
return true;
auto get_params = property.getter.is_engaged() ? property.getter->parameters.size() : 0;
@@ -394,7 +394,12 @@ struct property_wrapper_definition_generator
std::string scope = "public ";
std::string get_scope = property.getter.is_engaged() ? eolian_mono::function_scope_get(*property.getter) : "";
std::string set_scope = property.setter.is_engaged() ? eolian_mono::function_scope_get(*property.setter) : "";
- if (interface)
+
+ // No need to generate this wrapper as no accessor is public.
+ if (is_interface && (get_scope != "public " && set_scope != "public "))
+ return true;
+
+ if (is_interface)
{
scope = "";
get_scope = "";
@@ -443,7 +448,7 @@ struct property_wrapper_definition_generator
return false;
}
- if (property.getter.is_engaged() && interface)
+ if (property.getter.is_engaged() && is_interface)
{
if (!as_generator(scope_tab << scope_tab << set_scope << "get;\n"
).generate(sink, attributes::unused, context))
@@ -487,7 +492,7 @@ struct property_wrapper_definition_generator
// return false;
// }
- if (property.setter.is_engaged() && interface)
+ if (property.setter.is_engaged() && is_interface)
{
if (!as_generator(scope_tab << scope_tab << set_scope << "set;\n"
).generate(sink, attributes::unused, context))
diff --git a/src/bin/eolian_mono/eolian/mono/function_helpers.hh b/src/bin/eolian_mono/eolian/mono/function_helpers.hh
index 0ea25da536..3703cf88b9 100644
--- a/src/bin/eolian_mono/eolian/mono/function_helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_helpers.hh
@@ -165,9 +165,9 @@ function_definition_epilogue_generator const as_generator(function_definition_ep
inline std::string function_scope_get(attributes::function_def const& f)
{
- if ((f.klass.type == attributes::class_type::mixin) ||
- (f.klass.type == attributes::class_type::interface_))
- return "public ";
+ /* if ((f.klass.type == attributes::class_type::mixin) || */
+ /* (f.klass.type == attributes::class_type::interface_)) */
+ /* return "public "; */
switch (f.scope)
{
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index c86aec18aa..7a71951d58 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -227,6 +227,9 @@ struct klass
if (!generate_events(sink, cls, concrete_cxt))
return false;
+ if (!as_generator(lit("#pragma warning disable CS0628\n")).generate(sink, attributes::unused, concrete_cxt))
+ return false;
+
// Parts
if(!as_generator(*(part_definition))
.generate(sink, cls.parts, concrete_cxt)) return false;
@@ -251,6 +254,9 @@ struct klass
return false;
}
+ if (!as_generator(lit("#pragma warning restore CS0628\n")).generate(sink, attributes::unused, concrete_cxt))
+ return false;
+
// Copied from nativeinherit class, used when setting up providers.
if(!as_generator(
scope_tab << "private static IntPtr GetEflClassStatic()\n"
diff --git a/src/tests/efl_mono/Eo.cs b/src/tests/efl_mono/Eo.cs
index 71bb6deed0..efb1faa306 100644
--- a/src/tests/efl_mono/Eo.cs
+++ b/src/tests/efl_mono/Eo.cs
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Collections.Generic;
+using System.Reflection;
namespace TestSuite
{
@@ -542,34 +543,67 @@ class TestProtectedInterfaceMembers
{
}
- public override int MethodProtected(int x)
+ protected override int MethodProtected(int x)
{
return x * x;
}
}
- public static void test_protected_interface_in_generated_class()
- {
- var obj = new Dummy.TestObject();
- Test.AssertEquals(obj.MethodProtected(42), -42);
- }
-
public static void test_protected_interface_in_generated_class_called_from_c()
{
var obj = new Dummy.TestObject();
Test.AssertEquals(obj.CallMethodProtected(42), -42);
}
- public static void test_protected_interface_in_inherited_class()
+ public static void test_protected_interface_in_inherited_class_called_from_c()
{
var obj = new MyObject();
- Test.AssertEquals(obj.MethodProtected(42), 42 * 42);
+ Test.AssertEquals(obj.CallMethodProtected(42), 42 * 42);
}
- public static void test_protected_interface_in_inherited_class_called_from_c()
+ public static void test_interface_skipped_protected()
{
- var obj = new MyObject();
- Test.AssertEquals(obj.CallMethodProtected(42), 42 * 42);
+ var type = typeof(Dummy.ITestIface);
+ var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
+
+ // Fully protected property
+ Test.AssertNull(methods.SingleOrDefault(m => m.Name == "GetProtectedProp"));
+ Test.AssertNull(methods.SingleOrDefault(m => m.Name == "SetProtectedProp"));
+
+ // Partially protected property
+ Test.AssertNotNull(methods.SingleOrDefault(m => m.Name == "GetPublicGetterPrivateSetter"));
+ Test.AssertNull(methods.SingleOrDefault(m => m.Name == "SetPublicGetterPrivateSetter"));
+
+ var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
+ Test.AssertNull(properties.SingleOrDefault(m => m.Name == "ProtectedProp"));
+ Test.AssertNotNull(properties.SingleOrDefault(m => m.Name == "PublicGetterPrivateSetter"));
+ }
+
+ public static void test_interface_skipped_protected_in_implementation()
+ {
+ var type = typeof(Dummy.TestObject);
+
+ // Fully protected property
+ var protected_methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(m => m.IsFamily);
+ Test.AssertNotNull(protected_methods.SingleOrDefault(m => m.Name == "GetProtectedProp"));
+ Test.AssertNotNull(protected_methods.SingleOrDefault(m => m.Name == "SetProtectedProp"));
+
+ // Partially protected property
+ var public_methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
+ Test.AssertNotNull(public_methods.SingleOrDefault(m => m.Name == "GetPublicGetterPrivateSetter"));
+ Test.AssertNotNull(protected_methods.SingleOrDefault(m => m.Name == "SetPublicGetterPrivateSetter"));
+
+ var protected_properties = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance);
+ var prop = protected_properties.SingleOrDefault(m => m.Name == "ProtectedProp");
+ Test.AssertNotNull(prop);
+ Test.Assert(prop.GetMethod.IsFamily);
+ Test.Assert(prop.SetMethod.IsFamily);
+
+ var public_properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
+ prop = public_properties.SingleOrDefault(m => m.Name == "PublicGetterPrivateSetter");
+ Test.AssertNotNull(prop);
+ Test.Assert(prop.GetMethod.IsPublic);
+ Test.Assert(prop.SetMethod.IsFamily);
}
}
diff --git a/src/tests/efl_mono/dummy_test_iface.eo b/src/tests/efl_mono/dummy_test_iface.eo
index a7a761fef7..068b1352bd 100644
--- a/src/tests/efl_mono/dummy_test_iface.eo
+++ b/src/tests/efl_mono/dummy_test_iface.eo
@@ -25,6 +25,22 @@ interface Dummy.Test_Iface
return: int;
}
+ @property protected_prop @protected {
+ get {}
+ set {}
+ values {
+ data: int;
+ }
+ }
+
+ @property public_getter_private_setter {
+ get {}
+ set @protected {}
+ values {
+ data: int;
+ }
+ }
+
}
events {
nonconflicted: void;