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)
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
307 if (blacklist::is_property_blacklisted(property, *implementing_klass, context)) 307 if (blacklist::is_property_blacklisted(property, *implementing_klass, context))
308 return true; 308 return true;
309 309
310 bool interface = context_find_tag<class_context>(context).current_wrapper_kind == class_context::interface; 310 bool is_interface = context_find_tag<class_context>(context).current_wrapper_kind == class_context::interface;
311 bool is_static = (property.getter.is_engaged() && property.getter->is_static) 311 bool is_static = (property.getter.is_engaged() && property.getter->is_static)
312 || (property.setter.is_engaged() && property.setter->is_static); 312 || (property.setter.is_engaged() && property.setter->is_static);
313 313
314 314
315 if (interface && is_static) 315 if (is_interface && is_static)
316 return true; 316 return true;
317 317
318 auto get_params = property.getter.is_engaged() ? property.getter->parameters.size() : 0; 318 auto get_params = property.getter.is_engaged() ? property.getter->parameters.size() : 0;
@@ -394,7 +394,12 @@ struct property_wrapper_definition_generator
394 std::string scope = "public "; 394 std::string scope = "public ";
395 std::string get_scope = property.getter.is_engaged() ? eolian_mono::function_scope_get(*property.getter) : ""; 395 std::string get_scope = property.getter.is_engaged() ? eolian_mono::function_scope_get(*property.getter) : "";
396 std::string set_scope = property.setter.is_engaged() ? eolian_mono::function_scope_get(*property.setter) : ""; 396 std::string set_scope = property.setter.is_engaged() ? eolian_mono::function_scope_get(*property.setter) : "";
397 if (interface) 397
398 // No need to generate this wrapper as no accessor is public.
399 if (is_interface && (get_scope != "public " && set_scope != "public "))
400 return true;
401
402 if (is_interface)
398 { 403 {
399 scope = ""; 404 scope = "";
400 get_scope = ""; 405 get_scope = "";
@@ -443,7 +448,7 @@ struct property_wrapper_definition_generator
443 return false; 448 return false;
444 } 449 }
445 450
446 if (property.getter.is_engaged() && interface) 451 if (property.getter.is_engaged() && is_interface)
447 { 452 {
448 if (!as_generator(scope_tab << scope_tab << set_scope << "get;\n" 453 if (!as_generator(scope_tab << scope_tab << set_scope << "get;\n"
449 ).generate(sink, attributes::unused, context)) 454 ).generate(sink, attributes::unused, context))
@@ -487,7 +492,7 @@ struct property_wrapper_definition_generator
487 // return false; 492 // return false;
488 // } 493 // }
489 494
490 if (property.setter.is_engaged() && interface) 495 if (property.setter.is_engaged() && is_interface)
491 { 496 {
492 if (!as_generator(scope_tab << scope_tab << set_scope << "set;\n" 497 if (!as_generator(scope_tab << scope_tab << set_scope << "set;\n"
493 ).generate(sink, attributes::unused, context)) 498 ).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
165 165
166inline std::string function_scope_get(attributes::function_def const& f) 166inline std::string function_scope_get(attributes::function_def const& f)
167{ 167{
168 if ((f.klass.type == attributes::class_type::mixin) || 168 /* if ((f.klass.type == attributes::class_type::mixin) || */
169 (f.klass.type == attributes::class_type::interface_)) 169 /* (f.klass.type == attributes::class_type::interface_)) */
170 return "public "; 170 /* return "public "; */
171 171
172 switch (f.scope) 172 switch (f.scope)
173 { 173 {
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
227 if (!generate_events(sink, cls, concrete_cxt)) 227 if (!generate_events(sink, cls, concrete_cxt))
228 return false; 228 return false;
229 229
230 if (!as_generator(lit("#pragma warning disable CS0628\n")).generate(sink, attributes::unused, concrete_cxt))
231 return false;
232
230 // Parts 233 // Parts
231 if(!as_generator(*(part_definition)) 234 if(!as_generator(*(part_definition))
232 .generate(sink, cls.parts, concrete_cxt)) return false; 235 .generate(sink, cls.parts, concrete_cxt)) return false;
@@ -251,6 +254,9 @@ struct klass
251 return false; 254 return false;
252 } 255 }
253 256
257 if (!as_generator(lit("#pragma warning restore CS0628\n")).generate(sink, attributes::unused, concrete_cxt))
258 return false;
259
254 // Copied from nativeinherit class, used when setting up providers. 260 // Copied from nativeinherit class, used when setting up providers.
255 if(!as_generator( 261 if(!as_generator(
256 scope_tab << "private static IntPtr GetEflClassStatic()\n" 262 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 @@
1using System; 1using System;
2using System.Linq; 2using System.Linq;
3using System.Collections.Generic; 3using System.Collections.Generic;
4using System.Reflection;
4 5
5namespace TestSuite 6namespace TestSuite
6{ 7{
@@ -542,34 +543,67 @@ class TestProtectedInterfaceMembers
542 { 543 {
543 } 544 }
544 545
545 public override int MethodProtected(int x) 546 protected override int MethodProtected(int x)
546 { 547 {
547 return x * x; 548 return x * x;
548 } 549 }
549 } 550 }
550 551
551 public static void test_protected_interface_in_generated_class()
552 {
553 var obj = new Dummy.TestObject();
554 Test.AssertEquals(obj.MethodProtected(42), -42);
555 }
556
557 public static void test_protected_interface_in_generated_class_called_from_c() 552 public static void test_protected_interface_in_generated_class_called_from_c()
558 { 553 {
559 var obj = new Dummy.TestObject(); 554 var obj = new Dummy.TestObject();
560 Test.AssertEquals(obj.CallMethodProtected(42), -42); 555 Test.AssertEquals(obj.CallMethodProtected(42), -42);
561 } 556 }
562 557
563 public static void test_protected_interface_in_inherited_class() 558 public static void test_protected_interface_in_inherited_class_called_from_c()
564 { 559 {
565 var obj = new MyObject(); 560 var obj = new MyObject();
566 Test.AssertEquals(obj.MethodProtected(42), 42 * 42); 561 Test.AssertEquals(obj.CallMethodProtected(42), 42 * 42);
567 } 562 }
568 563
569 public static void test_protected_interface_in_inherited_class_called_from_c() 564 public static void test_interface_skipped_protected()
570 { 565 {
571 var obj = new MyObject(); 566 var type = typeof(Dummy.ITestIface);
572 Test.AssertEquals(obj.CallMethodProtected(42), 42 * 42); 567 var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
568
569 // Fully protected property
570 Test.AssertNull(methods.SingleOrDefault(m => m.Name == "GetProtectedProp"));
571 Test.AssertNull(methods.SingleOrDefault(m => m.Name == "SetProtectedProp"));
572
573 // Partially protected property
574 Test.AssertNotNull(methods.SingleOrDefault(m => m.Name == "GetPublicGetterPrivateSetter"));
575 Test.AssertNull(methods.SingleOrDefault(m => m.Name == "SetPublicGetterPrivateSetter"));
576
577 var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
578 Test.AssertNull(properties.SingleOrDefault(m => m.Name == "ProtectedProp"));
579 Test.AssertNotNull(properties.SingleOrDefault(m => m.Name == "PublicGetterPrivateSetter"));
580 }
581
582 public static void test_interface_skipped_protected_in_implementation()
583 {
584 var type = typeof(Dummy.TestObject);
585
586 // Fully protected property
587 var protected_methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(m => m.IsFamily);
588 Test.AssertNotNull(protected_methods.SingleOrDefault(m => m.Name == "GetProtectedProp"));
589 Test.AssertNotNull(protected_methods.SingleOrDefault(m => m.Name == "SetProtectedProp"));
590
591 // Partially protected property
592 var public_methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
593 Test.AssertNotNull(public_methods.SingleOrDefault(m => m.Name == "GetPublicGetterPrivateSetter"));
594 Test.AssertNotNull(protected_methods.SingleOrDefault(m => m.Name == "SetPublicGetterPrivateSetter"));
595
596 var protected_properties = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance);
597 var prop = protected_properties.SingleOrDefault(m => m.Name == "ProtectedProp");
598 Test.AssertNotNull(prop);
599 Test.Assert(prop.GetMethod.IsFamily);
600 Test.Assert(prop.SetMethod.IsFamily);
601
602 var public_properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
603 prop = public_properties.SingleOrDefault(m => m.Name == "PublicGetterPrivateSetter");
604 Test.AssertNotNull(prop);
605 Test.Assert(prop.GetMethod.IsPublic);
606 Test.Assert(prop.SetMethod.IsFamily);
573 } 607 }
574} 608}
575 609
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
25 return: int; 25 return: int;
26 } 26 }
27 27
28 @property protected_prop @protected {
29 get {}
30 set {}
31 values {
32 data: int;
33 }
34 }
35
36 @property public_getter_private_setter {
37 get {}
38 set @protected {}
39 values {
40 data: int;
41 }
42 }
43
28 } 44 }
29 events { 45 events {
30 nonconflicted: void; 46 nonconflicted: void;