efl-csharp: Remove spaces from type strings in generator.
authorLauro Moura <lauromoura@expertisesolutions.com.br>
Tue, 26 Mar 2019 17:45:18 +0000 (14:45 -0300)
committerYeongjong Lee <yj34.lee@samsung.com>
Tue, 2 Apr 2019 03:45:17 +0000 (12:45 +0900)
Summary:
Previously, the type_impl and marshall_type_impl generators relied on a
type mismatch in the match table to fallback to the else branch in the
match check to actually print the type string. This was achieved by
adding the " " prefix to the type.

This commit changes this behavior to invoke a proper visitor just to
print and makes both generators return trimmed type strings.

This will help conforming to the C# coding conventions.

Test Plan: run test suite

Reviewers: felipealmeida, vitor.sousa

Reviewed By: felipealmeida, vitor.sousa

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D8441

src/bin/eolian_mono/eolian/mono/function_definition.hh
src/bin/eolian_mono/eolian/mono/function_pointer.hh
src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
src/bin/eolian_mono/eolian/mono/type_impl.hh

index 465a8fe..fe349ef 100644 (file)
@@ -107,7 +107,7 @@ struct native_function_definition_generator
         << scope_tab << scope_tab << "if(wrapper != null) {\n"
         << scope_tab << scope_tab << scope_tab << eolian_mono::native_function_definition_preamble()
         << scope_tab << scope_tab << scope_tab << "try {\n"
-        << scope_tab << scope_tab << scope_tab << scope_tab << (return_type != " void" ? "_ret_var = " : "")
+        << scope_tab << scope_tab << scope_tab << scope_tab << (return_type != "void" ? "_ret_var = " : "")
         << (f.is_static ? "" : "((") << klass_cast_name << (f.is_static ? "." : ")wrapper).") << string
         << "(" << (native_argument_invocation % ", ") << ");\n"
         << scope_tab << scope_tab << scope_tab << "} catch (Exception e) {\n"
@@ -116,7 +116,7 @@ struct native_function_definition_generator
         << scope_tab << scope_tab << scope_tab << "}\n"
         << eolian_mono::native_function_definition_epilogue(*klass)
         << scope_tab << scope_tab << "} else {\n"
-        << scope_tab << scope_tab << scope_tab << (return_type != " void" ? "return " : "") << string
+        << scope_tab << scope_tab << scope_tab << (return_type != "void" ? "return " : "") << string
         << "_ptr.Value.Delegate(" << self << ((!f.is_static && f.parameters.size() > 0) ? ", " : "") << (argument % ", ") << ");\n"
         << scope_tab << scope_tab << "}\n"
         << scope_tab << "}\n"
index f3918f1..d616f1d 100644 (file)
@@ -89,7 +89,7 @@ struct function_pointer {
                   << scope_tab << scope_tab << string << " cb = (" << string << ")handle.Target;\n"
                   << native_function_definition_preamble
                   << scope_tab << scope_tab << "try {\n"
-                  << scope_tab << scope_tab << scope_tab <<  (return_type != " void" ? "_ret_var = " : "") << "cb(" << (native_argument_invocation % ", ") << ");\n"
+                  << scope_tab << scope_tab << scope_tab <<  (return_type != "void" ? "_ret_var = " : "") << "cb(" << (native_argument_invocation % ", ") << ");\n"
                   << scope_tab << scope_tab << "} catch (Exception e) {\n"
                   << scope_tab << scope_tab << scope_tab << "Eina.Log.Warning($\"Callback error: {e.ToString()}\");\n"
                   << scope_tab << scope_tab << scope_tab << "Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);\n"
index 998ca0b..ae619ea 100644 (file)
@@ -46,55 +46,55 @@ struct marshall_type_visitor_generate
               {
                 regular_type_def r = regular;
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
-                return replace_base_type(r, " System.String");
+                return replace_base_type(r, "System.String");
               }}
            , {"string", false, [&]
               {
                 regular_type_def r = regular;
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
-                return replace_base_type(r, " System.String");
+                return replace_base_type(r, "System.String");
               }}
            , {"mstring", true, [&]
               {
                 regular_type_def r = regular;
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
-                return replace_base_type(r, " System.String");
+                return replace_base_type(r, "System.String");
               }}
            , {"mstring", false, [&]
               {
                 regular_type_def r = regular;
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
-                return replace_base_type(r, " System.String");
+                return replace_base_type(r, "System.String");
               }}
            , {"stringshare", true, [&]
               {
                 regular_type_def r = regular;
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
-                return replace_base_type(r, " System.String");
+                return replace_base_type(r, "System.String");
               }}
            , {"stringshare", false, [&]
               {
                 regular_type_def r = regular;
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
-                return replace_base_type(r, " System.String");
+                return replace_base_type(r, "System.String");
               }}
            , {"strbuf", nullptr, [&]
               {
                 regular_type_def r = regular;
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
-                return replace_base_type(r, " Eina.Strbuf");
+                return replace_base_type(r, "Eina.Strbuf");
               }}
            , {"Binbuf", true, [&]
               {
                 regular_type_def r = regular;
-                r.base_type = " System.IntPtr";
+                r.base_type = "System.IntPtr";
                 r.namespaces.clear();
                 return r;
               }}
            , {"Binbuf", false, [&]
               {
                 regular_type_def r = regular;
-                r.base_type = " System.IntPtr";
+                r.base_type = "System.IntPtr";
                 r.namespaces.clear();
                 return r;
               }}
@@ -103,9 +103,9 @@ struct marshall_type_visitor_generate
                 regular_type_def r = regular;
                 r.namespaces.clear();
                 if (is_ptr)
-                    r.base_type = " Eina.Value";
+                    r.base_type = "Eina.Value";
                 else
-                    r.base_type = " Eina.ValueNative";
+                    r.base_type = "Eina.ValueNative";
                 return r;
                }}
            , {"any_value", false, [&]
@@ -113,23 +113,23 @@ struct marshall_type_visitor_generate
                 regular_type_def r = regular;
                 r.namespaces.clear();
                 if (is_ptr)
-                    r.base_type = " Eina.Value";
+                    r.base_type = "Eina.Value";
                 else
-                    r.base_type = " Eina.ValueNative";
+                    r.base_type = "Eina.ValueNative";
                 return r;
                }}
            , {"any_value_ptr", true, [&]
                {
                 regular_type_def r = regular;
                 r.namespaces.clear();
-                r.base_type = " Eina.Value";
+                r.base_type = "Eina.Value";
                 return r;
                }}
            , {"any_value_ptr", false, [&]
                {
                 regular_type_def r = regular;
                 r.namespaces.clear();
-                r.base_type = " Eina.Value";
+                r.base_type = "Eina.Value";
                 return r;
                }}
            , {"void", nullptr, [&]
@@ -137,9 +137,9 @@ struct marshall_type_visitor_generate
                 regular_type_def r = regular;
                 r.namespaces.clear();
                 if (is_out) // @inout too
-                    r.base_type = " System.IntPtr";
+                    r.base_type = "System.IntPtr";
                 else
-                    r.base_type = " void";
+                    r.base_type = "void";
                 return r;
                }}
         };
@@ -147,7 +147,7 @@ struct marshall_type_visitor_generate
         if (regular.is_struct() && !blacklist::is_struct_blacklisted(regular) && !(bool)(regular.base_qualifier & qualifier_info::is_own))
           {
              if ((is_out || is_return) && is_ptr)
-                 return as_generator(" System.IntPtr").generate(sink, attributes::unused, *context);
+                 return as_generator("System.IntPtr").generate(sink, attributes::unused, *context);
              return as_generator(string << "_StructInternal")
                     .generate(sink, name_helpers::type_full_managed_name(regular), *context);
           }
@@ -161,7 +161,7 @@ struct marshall_type_visitor_generate
           }
           , [&] (attributes::type_def::variant_type const& v)
           {
-            return v.visit(*this); // we want to keep is_out info
+            return v.visit(visitor_regular_type_def_printer<OutputIterator, Context>{sink, context}); // we want to keep is_out info
           }))
         {
            return *b;
@@ -169,7 +169,7 @@ struct marshall_type_visitor_generate
       else if (is_ptr && helpers::need_pointer_conversion(&regular))
         {
            regular_type_def r = regular;
-           r.base_type = " System.IntPtr";
+           r.base_type = "System.IntPtr";
            r.namespaces.clear();
            return visitor_generate<OutputIterator, Context>{sink, context, c_type, is_out, is_return, is_ptr}(r);
         }
@@ -196,27 +196,27 @@ struct marshall_type_visitor_generate
       {
         {"array", nullptr, nullptr, [&]
            {
-              return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
+              return regular_type_def{"System.IntPtr", complex.outer.base_qualifier, {}};
            }
         }
         ,{"list", nullptr, nullptr, [&]
            {
-              return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
+              return regular_type_def{"System.IntPtr", complex.outer.base_qualifier, {}};
            }
         }
         ,{"hash", nullptr, nullptr, [&]
            {
-              return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
+              return regular_type_def{"System.IntPtr", complex.outer.base_qualifier, {}};
            }
         }
         ,{"iterator", nullptr, nullptr, [&]
            {
-              return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
+              return regular_type_def{"System.IntPtr", complex.outer.base_qualifier, {}};
            }
         }
         ,{"accessor", nullptr, nullptr, [&]
            {
-              return regular_type_def{" System.IntPtr", complex.outer.base_qualifier, {}};
+              return regular_type_def{"System.IntPtr", complex.outer.base_qualifier, {}};
            }
         }
       };
index f34c479..4b3f097 100644 (file)
@@ -26,10 +26,10 @@ attributes::regular_type_def replace_base_integer(attributes::regular_type_def v
   bool s = std::is_signed<T>::value;
   switch (sizeof(T))
   {
-  case 1: return s ? replace_base_type(v, " sbyte") : replace_base_type(v, " byte");
-  case 2: return s ? replace_base_type(v, " short") : replace_base_type(v, " ushort");
-  case 4: return s ? replace_base_type(v, " int") : replace_base_type(v, " uint");
-  case 8: return s ? replace_base_type(v, " long") : replace_base_type(v, " ulong");
+  case 1: return s ? replace_base_type(v, "sbyte") : replace_base_type(v, "byte");
+  case 2: return s ? replace_base_type(v, "short") : replace_base_type(v, "ushort");
+  case 4: return s ? replace_base_type(v, "int") : replace_base_type(v, "uint");
+  case 8: return s ? replace_base_type(v, "long") : replace_base_type(v, "ulong");
   default: return v;
   }
 }
@@ -40,10 +40,10 @@ attributes::regular_type_def replace_base_opt_integer(attributes::regular_type_d
   bool s = std::is_signed<T>::value;
   switch (sizeof(T))
   {
-  case 1: return s ? replace_base_type(v, " sbyte?") : replace_base_type(v, " byte?");
-  case 2: return s ? replace_base_type(v, " short?") : replace_base_type(v, " ushort?");
-  case 4: return s ? replace_base_type(v, " int?") : replace_base_type(v, " uint?");
-  case 8: return s ? replace_base_type(v, " long?") : replace_base_type(v, " ulong?");
+  case 1: return s ? replace_base_type(v, "sbyte?") : replace_base_type(v, "byte?");
+  case 2: return s ? replace_base_type(v, "short?") : replace_base_type(v, "ushort?");
+  case 4: return s ? replace_base_type(v, "int?") : replace_base_type(v, "uint?");
+  case 8: return s ? replace_base_type(v, "long?") : replace_base_type(v, "ulong?");
   default: return v;
   }
 }
@@ -67,7 +67,28 @@ eina::optional<bool> call_match(Array const (&array)[N], F f, A a)
      }
    return {nullptr};
 }
-      
+
+template <typename OutputIterator, typename Context>
+struct visitor_regular_type_def_printer
+{
+   typedef visitor_regular_type_def_printer visitor_type;
+   typedef bool result_type;
+
+   mutable OutputIterator sink;
+   Context const* context;
+
+   bool operator()(grammar::attributes::regular_type_def const &regular) const
+   {
+     return as_generator(string).generate(sink, name_helpers::type_full_managed_name(regular), *context);
+   }
+
+   template<typename T>
+   bool operator()(T const&) const
+   {
+     return true;
+   }
+};
+
 template <typename OutputIterator, typename Context>
 struct visitor_generate
 {
@@ -94,110 +115,110 @@ struct visitor_generate
       const optional_match_table[] =
         {
            // signed primitives
-             {"byte", nullptr, [&] { return replace_base_type(regular, " sbyte?"); }}
-           , {"float", nullptr, [&] { return replace_base_type(regular, " float?"); }}
-           , {"double", nullptr, [&] { return replace_base_type(regular, " double?"); }}
-           , {"bool", nullptr, [&] { return replace_base_type(regular, " bool?"); }}
+             {"byte", nullptr, [&] { return replace_base_type(regular, "sbyte?"); }}
+           , {"float", nullptr, [&] { return replace_base_type(regular, "float?"); }}
+           , {"double", nullptr, [&] { return replace_base_type(regular, "double?"); }}
+           , {"bool", nullptr, [&] { return replace_base_type(regular, "bool?"); }}
            , {"short", nullptr, [&] { return replace_base_opt_integer<short>(regular); }}
            , {"int", nullptr, [&] { return replace_base_opt_integer<int>(regular); }}
            , {"long", nullptr, [&] { return replace_base_opt_integer<long>(regular); }}
            , {"llong", nullptr, [&] { return replace_base_opt_integer<long long>(regular); }}
-           , {"int8", nullptr, [&] { return replace_base_type(regular, " sbyte?"); }}
-           , {"int16", nullptr, [&] { return replace_base_type(regular, " short?"); }}
-           , {"int32", nullptr, [&] { return replace_base_type(regular, " int?"); }}
-           , {"int64", nullptr, [&] { return replace_base_type(regular, " long?"); }}
+           , {"int8", nullptr, [&] { return replace_base_type(regular, "sbyte?"); }}
+           , {"int16", nullptr, [&] { return replace_base_type(regular, "short?"); }}
+           , {"int32", nullptr, [&] { return replace_base_type(regular, "int?"); }}
+           , {"int64", nullptr, [&] { return replace_base_type(regular, "long?"); }}
            , {"ssize", nullptr, [&] { return replace_base_opt_integer<ssize_t>(regular); }}
            // unsigned primitives
-           , {"ubyte", nullptr, [&] { return replace_base_type(regular, " byte?"); }}
+           , {"ubyte", nullptr, [&] { return replace_base_type(regular, "byte?"); }}
            , {"ushort", nullptr, [&] { return replace_base_opt_integer<unsigned short>(regular); }}
            , {"uint", nullptr, [&] { return replace_base_opt_integer<unsigned int>(regular); }}
            , {"ulong", nullptr, [&] { return replace_base_opt_integer<unsigned long>(regular); }}
            , {"ullong", nullptr, [&] { return replace_base_opt_integer<unsigned long long>(regular); }}
-           , {"uint8", nullptr, [&] { return replace_base_type(regular, " byte?"); }}
-           , {"uint16", nullptr, [&] { return replace_base_type(regular, " ushort?"); }}
-           , {"uint32", nullptr, [&] { return replace_base_type(regular, " uint?"); }}
-           , {"uint64", nullptr, [&] { return replace_base_type(regular, " ulong?"); }}
+           , {"uint8", nullptr, [&] { return replace_base_type(regular, "byte?"); }}
+           , {"uint16", nullptr, [&] { return replace_base_type(regular, "ushort?"); }}
+           , {"uint32", nullptr, [&] { return replace_base_type(regular, "uint?"); }}
+           , {"uint64", nullptr, [&] { return replace_base_type(regular, "ulong?"); }}
            , {"size", nullptr, [&] { return replace_base_opt_integer<size_t>(regular); }}
            
            , {"ptrdiff", nullptr, [&] { return replace_base_opt_integer<ptrdiff_t>(regular); }}
-           , {"intptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr?"); }}
-           , {"uintptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr?"); }}
-           , {"void_ptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr?"); }}
+           , {"intptr", nullptr, [&] { return replace_base_type(regular, "System.IntPtr?"); }}
+           , {"uintptr", nullptr, [&] { return replace_base_type(regular, "System.IntPtr?"); }}
+           , {"void_ptr", nullptr, [&] { return replace_base_type(regular, "System.IntPtr?"); }}
         };
       struct match
       const match_table[] =
         {
            // signed primitives
-             {"byte", nullptr, [&] { return replace_base_type(regular, " sbyte"); }}
+             {"byte", nullptr, [&] { return replace_base_type(regular, "sbyte"); }}
            , {"short", nullptr, [&] { return replace_base_integer<short>(regular); }}
            , {"int", nullptr, [&] { return replace_base_integer<int>(regular); }}
            , {"long", nullptr, [&] { return replace_base_integer<long>(regular); }}
            , {"llong", nullptr, [&] { return replace_base_integer<long long>(regular); }}
-           , {"int8", nullptr, [&] { return replace_base_type(regular, " sbyte"); }}
-           , {"int16", nullptr, [&] { return replace_base_type(regular, " short"); }}
-           , {"int32", nullptr, [&] { return replace_base_type(regular, " int"); }}
-           , {"int64", nullptr, [&] { return replace_base_type(regular, " long"); }}
+           , {"int8", nullptr, [&] { return replace_base_type(regular, "sbyte"); }}
+           , {"int16", nullptr, [&] { return replace_base_type(regular, "short"); }}
+           , {"int32", nullptr, [&] { return replace_base_type(regular, "int"); }}
+           , {"int64", nullptr, [&] { return replace_base_type(regular, "long"); }}
            , {"ssize", nullptr, [&] { return replace_base_integer<ssize_t>(regular); }}
            // unsigned primitives
-           , {"ubyte", nullptr, [&] { return replace_base_type(regular, " byte"); }}
+           , {"ubyte", nullptr, [&] { return replace_base_type(regular, "byte"); }}
            , {"ushort", nullptr, [&] { return replace_base_integer<unsigned short>(regular); }}
            , {"uint", nullptr, [&] { return replace_base_integer<unsigned int>(regular); }}
            , {"ulong", nullptr, [&] { return replace_base_integer<unsigned long>(regular); }}
            , {"ullong", nullptr, [&] { return replace_base_integer<unsigned long long>(regular); }}
-           , {"uint8", nullptr, [&] { return replace_base_type(regular, " byte"); }}
-           , {"uint16", nullptr, [&] { return replace_base_type(regular, " ushort"); }}
-           , {"uint32", nullptr, [&] { return replace_base_type(regular, " uint"); }}
-           , {"uint64", nullptr, [&] { return replace_base_type(regular, " ulong"); }}
+           , {"uint8", nullptr, [&] { return replace_base_type(regular, "byte"); }}
+           , {"uint16", nullptr, [&] { return replace_base_type(regular, "ushort"); }}
+           , {"uint32", nullptr, [&] { return replace_base_type(regular, "uint"); }}
+           , {"uint64", nullptr, [&] { return replace_base_type(regular, "ulong"); }}
            , {"size", nullptr, [&] { return replace_base_integer<size_t>(regular); }}
            
            , {"ptrdiff", nullptr, [&] { return replace_base_integer<ptrdiff_t>(regular); }}
-           , {"intptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr"); }}
-           , {"uintptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr"); }}
-           , {"void_ptr", nullptr, [&] { return replace_base_type(regular, " System.IntPtr"); }}
+           , {"intptr", nullptr, [&] { return replace_base_type(regular, "System.IntPtr"); }}
+           , {"uintptr", nullptr, [&] { return replace_base_type(regular, "System.IntPtr"); }}
+           , {"void_ptr", nullptr, [&] { return replace_base_type(regular, "System.IntPtr"); }}
            , {"void", nullptr, [&]
                {
                   regular_type_def r = regular;
                   r.namespaces.clear();
                   if (is_out) // @inout too
-                      r.base_type = " System.IntPtr";
+                      r.base_type = "System.IntPtr";
                   else
-                      r.base_type = " void";
+                      r.base_type = "void";
                   return r;
               }}
            , {"Eina.Error", nullptr, [&] // Eina.Error
               {
-                return regular_type_def{" Eina.Error", regular.base_qualifier, {}};
+                return regular_type_def{"Eina.Error", regular.base_qualifier, {}};
               }} // TODO
            , {"string", nullptr, [&]
               {
                 regular_type_def r = regular;
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
-                return replace_base_type(r, " System.String");
+                return replace_base_type(r, "System.String");
               }}
            , {"mstring", nullptr, [&]
               {
                 regular_type_def r = regular;
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
-                return replace_base_type(r, " System.String");
+                return replace_base_type(r, "System.String");
               }}
            , {"stringshare", nullptr, [&]
               {
                 regular_type_def r = regular;
                 r.base_qualifier.qualifier ^= qualifier_info::is_ref;
-                return replace_base_type(r, " System.String");
+                return replace_base_type(r, "System.String");
               }}
            , {"strbuf", nullptr, [&]
               {
-                return regular_type_def{" Eina.Strbuf", regular.base_qualifier, {}};
+                return regular_type_def{"Eina.Strbuf", regular.base_qualifier, {}};
               }}
            , {"any_value", true, [&]
-              { return regular_type_def{" Eina.Value", regular.base_qualifier, {}};
+              { return regular_type_def{"Eina.Value", regular.base_qualifier, {}};
               }}
            , {"any_value", false, [&]
-              { return regular_type_def{" Eina.Value", regular.base_qualifier, {}};
+              { return regular_type_def{"Eina.Value", regular.base_qualifier, {}};
               }}
            , {"any_value_ptr", nullptr, [&] 
-              { return regular_type_def{" Eina.Value", regular.base_qualifier, {}};
+              { return regular_type_def{"Eina.Value", regular.base_qualifier, {}};
               }} // FIXME add proper support for any_value_ptr
         };
         std::string full_type_name = name_helpers::type_full_eolian_name(regular);
@@ -234,7 +255,7 @@ struct visitor_generate
           }
           , [&] (attributes::type_def::variant_type const& v)
           {
-            return v.visit(*this); // we want to keep is_out info
+            return v.visit(visitor_regular_type_def_printer<OutputIterator, Context>{sink, context}); // we want to keep is_out info
           }))
         {
            return *b;