From accdb878a613e03bbbb3e7f2d5b1f50473181d29 Mon Sep 17 00:00:00 2001 From: Lauro Moura Date: Mon, 15 Apr 2019 15:58:30 -0300 Subject: [PATCH] csharp: Remove warning about clashing GetType() methods Summary: This changes the naming scheme to replace `GetType`/`SetType` methods with `GetType`/`SetType`. Like `GetGestureType`. Avoids cs compiler complaining of clashing with `System.Object.GetType`. Fixes T7727 Reviewers: segfaultxavi, felipealmeida, vitor.sousa Reviewed By: vitor.sousa Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T7727 Differential Revision: https://phab.enlightenment.org/D8609 --- src/bin/eolian_mono/eolian/mono/documentation.hh | 10 ++++++--- .../eolian_mono/eolian/mono/function_definition.hh | 4 ++-- src/bin/eolian_mono/eolian/mono/name_helpers.hh | 25 +++++++++++++++++++--- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/bin/eolian_mono/eolian/mono/documentation.hh b/src/bin/eolian_mono/eolian/mono/documentation.hh index 1cea16e..9646fd3 100644 --- a/src/bin/eolian_mono/eolian/mono/documentation.hh +++ b/src/bin/eolian_mono/eolian/mono/documentation.hh @@ -64,6 +64,10 @@ struct documentation_generator ::Eolian_Function_Type ftype = ::eolian_function_type_get(function); const char* eo_name = ::eolian_function_name_get(function); std::string name = object_ref_conversion(klass); + + // Klass is needed to check the property naming rulles + attributes::klass_def klass_d((const ::Eolian_Class *)klass, eolian_object_unit_get(klass)); + switch(ftype) { case ::EOLIAN_METHOD: @@ -75,17 +79,17 @@ struct documentation_generator break; case ::EOLIAN_PROP_SET: name += ".Set"; - name += name_helpers::property_managed_name(eo_name); + name += name_helpers::property_managed_name(klass_d, eo_name); break; case ::EOLIAN_PROP_GET: name += ".Get"; - name += name_helpers::property_managed_name(eo_name); + name += name_helpers::property_managed_name(klass_d, eo_name); break; case ::EOLIAN_PROPERTY: { int getter_params = property_num_parameters(function, ::EOLIAN_PROP_GET); int setter_params = property_num_parameters(function, ::EOLIAN_PROP_SET); - std::string short_name = name_helpers::property_managed_name(eo_name); + std::string short_name = name_helpers::property_managed_name(klass_d, eo_name); bool blacklisted = blacklist::is_property_blacklisted(name + "." + short_name); // EO properties with keys, with more than one value, or blacklisted, are not // converted into C# properties. diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh b/src/bin/eolian_mono/eolian/mono/function_definition.hh index 3abf82f..2302548 100644 --- a/src/bin/eolian_mono/eolian/mono/function_definition.hh +++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh @@ -267,12 +267,12 @@ struct property_wrapper_definition_generator return false; if (property.getter.is_engaged()) - if (!as_generator(scope_tab << scope_tab << "get " << (interface ? ";" : "{ return Get" + managed_name + "(); }") << "\n" + if (!as_generator(scope_tab << scope_tab << "get " << (interface ? ";" : "{ return " + name_helpers::managed_method_name(*property.getter) + "(); }") << "\n" ).generate(sink, attributes::unused, context)) return false; if (property.setter.is_engaged()) - if (!as_generator(scope_tab << scope_tab << "set " << (interface ? ";" : "{ Set" + managed_name + "(" + dir_mod + "value); }") << "\n" + if (!as_generator(scope_tab << scope_tab << "set " << (interface ? ";" : "{ " + name_helpers::managed_method_name(*property.setter) + "(" + dir_mod + "value); }") << "\n" ).generate(sink, attributes::unused, context)) return false; diff --git a/src/bin/eolian_mono/eolian/mono/name_helpers.hh b/src/bin/eolian_mono/eolian/mono/name_helpers.hh index 2ff2b47..6e91355 100644 --- a/src/bin/eolian_mono/eolian/mono/name_helpers.hh +++ b/src/bin/eolian_mono/eolian/mono/name_helpers.hh @@ -38,6 +38,10 @@ inline bool is_equal(std::string const& lhs, std::string const& rhs) } } +// Forward declarations +template +inline std::string klass_concrete_or_interface_name(T const& klass); + inline std::string identity(std::string const& str) { return str; @@ -184,6 +188,12 @@ inline std::string managed_method_name(std::string const& klass, std::string con if (candidate == klass) candidate = "Do" + candidate; + // Avoid clashing with System.Object.GetType + if (candidate == "GetType" || candidate == "SetType") + { + candidate.insert(3, klass); + } + return candidate; } @@ -252,17 +262,26 @@ inline std::string to_field_name(std::string const& in) return utils::capitalize(in); } -inline std::string property_managed_name(const std::string name) + + +template +inline std::string property_managed_name(T const& klass, std::string const& name) { auto names = utils::split(name, '_'); // No need to escape keyword here as it will be capitalized and already // namespaced inside the owner class. - return utils::to_pascal_case(names); + auto managed_name = utils::to_pascal_case(names); + auto managed_klass_name = klass_concrete_or_interface_name(klass); + + if (managed_name == "Type") + managed_name = managed_klass_name + managed_name; + + return managed_name; } inline std::string property_managed_name(attributes::property_def const& property) { - return property_managed_name(property.name); + return property_managed_name(property.klass, property.name); } inline std::string managed_part_name(attributes::part_def const& part) -- 2.7.4