diff options
author | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-11-13 10:05:19 -0300 |
---|---|---|
committer | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-11-13 10:05:19 -0300 |
commit | bdf4396dfefb0462605b741df674de764c9afaac (patch) | |
tree | 972e6d09a23ef8cfc3c2aaefdeae6acac2ecc7b5 /src/bin | |
parent | 790fa0e04b9760ee99ce33839191936159430df5 (diff) | |
download | efl-bdf4396dfefb0462605b741df674de764c9afaac.tar.gz |
csharp: Add conversion methods for generated types
Summary:
This also adds a helper method to convert from a value type name to the
reference type name. (e.g. int to Int32).
Ref T8430
Reviewers: felipealmeida, brunobelo, YOhoho
Reviewed By: brunobelo
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Maniphest Tasks: T8430
Differential Revision: https://phab.enlightenment.org/D10653
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/alias_definition.hh | 15 | ||||
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/name_helpers.hh | 26 | ||||
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/struct_definition.hh | 20 |
3 files changed, 61 insertions, 0 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/alias_definition.hh b/src/bin/eolian_mono/eolian/mono/alias_definition.hh index 1f17d6b368..7f3f2588f3 100644 --- a/src/bin/eolian_mono/eolian/mono/alias_definition.hh +++ b/src/bin/eolian_mono/eolian/mono/alias_definition.hh @@ -78,6 +78,21 @@ struct alias_definition_generator << scope_tab << "{\n" << scope_tab << scope_tab << "return value.payload;\n" << scope_tab << "}\n" + + << scope_tab << "/// <summary>Converts an instance of " << alias_type_doc << " to this struct.</summary>\n" + << scope_tab << "/// <param name=\"value\">The value to be converted.</param>\n" + << scope_tab << "/// <returns>A struct with the given value.</returns>\n" + << scope_tab << "public static " << alias_name << " From" << name_helpers::translate_value_type(alias_type) << "(" << alias_type << " value)\n" + << scope_tab << "{\n" + << scope_tab << scope_tab << "return value;\n" + << scope_tab << "}\n\n" + + << scope_tab << "/// <summary>Converts an instance of this struct to " << alias_type_doc << ".</summary>\n" + << scope_tab << "/// <returns>The actual value the alias is wrapping.</returns>\n" + << scope_tab << "public " << alias_type << " To" << name_helpers::translate_value_type(alias_type) << "()\n" + << scope_tab << "{\n" + << scope_tab << scope_tab << "return this;\n" + << scope_tab << "}\n" << "}\n" ).generate(sink, alias, 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 d5f68b7331..2f3026dfdc 100644 --- a/src/bin/eolian_mono/eolian/mono/name_helpers.hh +++ b/src/bin/eolian_mono/eolian/mono/name_helpers.hh @@ -537,6 +537,32 @@ std::string constructor_managed_name(std::string full_name) return managed_name(tokens.at(tokens.size()-1)); } +std::string translate_value_type(std::string const& name) +{ + static std::map<std::string, std::string> table = { + {"sbyte", "SByte"}, + {"byte","Byte"}, + {"short","Int16"}, + {"ushort","UInt16"}, + {"int", "Int32"}, + {"uint","UInt32"}, + {"long","Int64"}, + {"ulong","UInt64"}, + {"char","Char"}, + {"float","Single"}, + {"double","Double"}, + {"bool","Boolean"}, + {"decimal","Decimal"}, + }; + + auto found = table.find(name); + + if (found != table.end()) + return found->second; + + return name; +} + } // namespace name_helpers } // namespace eolian_mono diff --git a/src/bin/eolian_mono/eolian/mono/struct_definition.hh b/src/bin/eolian_mono/eolian/mono/struct_definition.hh index c733432465..b3b8d717f6 100644 --- a/src/bin/eolian_mono/eolian/mono/struct_definition.hh +++ b/src/bin/eolian_mono/eolian/mono/struct_definition.hh @@ -493,6 +493,26 @@ struct struct_definition_generator ).generate(sink, attributes::unused, context)) return false; + if(!as_generator( + indent << scope_tab << "/// <summary>Conversion to the managed representation from a native pointer.\n" + ).generate(sink, attributes::unused, context)) + return false; + + if (!struct_.documentation.since.empty()) + if (!as_generator(indent << scope_tab << "/// <para>Since EFL " + struct_.documentation.since + ".</para>\n" + ).generate(sink, attributes::unused, context)) + return false; + + if (!as_generator( + indent << scope_tab << "/// </summary>\n" + << indent << scope_tab << "/// <param name=\"ptr\">Native pointer to be converted.</param>\n" + << indent << scope_tab << "public static " << struct_name << " FromIntPtr(IntPtr ptr)\n" + << indent << scope_tab << "{\n" + << indent << scope_tab << scope_tab << "return ptr;\n" + << indent << scope_tab << "}\n\n" + ).generate(sink, attributes::unused, context)) + return false; + if (!struct_internal_definition.generate(sink, struct_, change_indentation(indent.inc(), context))) return false; |