summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-11-13 10:05:19 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-11-13 10:05:19 -0300
commitbdf4396dfefb0462605b741df674de764c9afaac (patch)
tree972e6d09a23ef8cfc3c2aaefdeae6acac2ecc7b5
parent790fa0e04b9760ee99ce33839191936159430df5 (diff)
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
-rw-r--r--src/bin/eolian_mono/eolian/mono/alias_definition.hh15
-rw-r--r--src/bin/eolian_mono/eolian/mono/name_helpers.hh26
-rw-r--r--src/bin/eolian_mono/eolian/mono/struct_definition.hh20
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 1f17d6b..7f3f258 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
78 << scope_tab << "{\n" 78 << scope_tab << "{\n"
79 << scope_tab << scope_tab << "return value.payload;\n" 79 << scope_tab << scope_tab << "return value.payload;\n"
80 << scope_tab << "}\n" 80 << scope_tab << "}\n"
81
82 << scope_tab << "/// <summary>Converts an instance of " << alias_type_doc << " to this struct.</summary>\n"
83 << scope_tab << "/// <param name=\"value\">The value to be converted.</param>\n"
84 << scope_tab << "/// <returns>A struct with the given value.</returns>\n"
85 << scope_tab << "public static " << alias_name << " From" << name_helpers::translate_value_type(alias_type) << "(" << alias_type << " value)\n"
86 << scope_tab << "{\n"
87 << scope_tab << scope_tab << "return value;\n"
88 << scope_tab << "}\n\n"
89
90 << scope_tab << "/// <summary>Converts an instance of this struct to " << alias_type_doc << ".</summary>\n"
91 << scope_tab << "/// <returns>The actual value the alias is wrapping.</returns>\n"
92 << scope_tab << "public " << alias_type << " To" << name_helpers::translate_value_type(alias_type) << "()\n"
93 << scope_tab << "{\n"
94 << scope_tab << scope_tab << "return this;\n"
95 << scope_tab << "}\n"
81 << "}\n" 96 << "}\n"
82 ).generate(sink, alias, context)) 97 ).generate(sink, alias, context))
83 return false; 98 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 d5f68b7..2f3026d 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)
537 return managed_name(tokens.at(tokens.size()-1)); 537 return managed_name(tokens.at(tokens.size()-1));
538} 538}
539 539
540std::string translate_value_type(std::string const& name)
541{
542 static std::map<std::string, std::string> table = {
543 {"sbyte", "SByte"},
544 {"byte","Byte"},
545 {"short","Int16"},
546 {"ushort","UInt16"},
547 {"int", "Int32"},
548 {"uint","UInt32"},
549 {"long","Int64"},
550 {"ulong","UInt64"},
551 {"char","Char"},
552 {"float","Single"},
553 {"double","Double"},
554 {"bool","Boolean"},
555 {"decimal","Decimal"},
556 };
557
558 auto found = table.find(name);
559
560 if (found != table.end())
561 return found->second;
562
563 return name;
564}
565
540} // namespace name_helpers 566} // namespace name_helpers
541 567
542} // namespace eolian_mono 568} // 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 c733432..b3b8d71 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
493 ).generate(sink, attributes::unused, context)) 493 ).generate(sink, attributes::unused, context))
494 return false; 494 return false;
495 495
496 if(!as_generator(
497 indent << scope_tab << "/// <summary>Conversion to the managed representation from a native pointer.\n"
498 ).generate(sink, attributes::unused, context))
499 return false;
500
501 if (!struct_.documentation.since.empty())
502 if (!as_generator(indent << scope_tab << "/// <para>Since EFL " + struct_.documentation.since + ".</para>\n"
503 ).generate(sink, attributes::unused, context))
504 return false;
505
506 if (!as_generator(
507 indent << scope_tab << "/// </summary>\n"
508 << indent << scope_tab << "/// <param name=\"ptr\">Native pointer to be converted.</param>\n"
509 << indent << scope_tab << "public static " << struct_name << " FromIntPtr(IntPtr ptr)\n"
510 << indent << scope_tab << "{\n"
511 << indent << scope_tab << scope_tab << "return ptr;\n"
512 << indent << scope_tab << "}\n\n"
513 ).generate(sink, attributes::unused, context))
514 return false;
515
496 if (!struct_internal_definition.generate(sink, struct_, change_indentation(indent.inc(), context))) 516 if (!struct_internal_definition.generate(sink, struct_, change_indentation(indent.inc(), context)))
497 return false; 517 return false;
498 518