Change unit map api signature for C# Generator 04/297804/1
authorjusung son <jusung07.son@samsung.com>
Thu, 24 Aug 2023 10:56:35 +0000 (19:56 +0900)
committerjusung son <jusung07.son@samsung.com>
Thu, 24 Aug 2023 10:56:35 +0000 (19:56 +0900)
internal void Read(string name, string type, out <PARAM_TYPE> value) =>
internal void Read(string name, out <PARAM_TYPE> value)

internal void Write(string name, string type, <PARAM_TYPE> value) =>
internal void Write(string name, <PARAM_TYPE> value)

Change-Id: I630fc3aac82cbe89ad217fba01ab2008f736fd22
Signed-off-by: jusung son <jusung07.son@samsung.com>
idlc/gen/version2/cs_generator_base.cc
idlc/gen/version2/cs_generator_base.h
idlc/gen/version2/cs_generator_base_cb.h
idlc/gen/version2/cs_group_generator.cc
idlc/gen/version2/cs_proxy_generator.cc
idlc/gen/version2/cs_proxy_generator_cb.h
idlc/gen/version2/cs_stub_generator.cc
idlc/gen/version2/cs_stub_generator.h
idlc/gen/version2/cs_stub_generator_cb.h

index 90027f7..c20d3bc 100644 (file)
@@ -124,17 +124,9 @@ std::string CsGeneratorBase::GetSerializer(const Structure& st) {
                       .Change("<TYPE>", st.GetID())
                       .Change("<BODY>", [&]() {
                         std::string ret;
-                        std::string type_str;
                         for (const auto& i : st.GetElements()) {
-                          auto& t = i->GetType();
-                          if (t.IsEnumType())
-                            type_str = "int";
-                          else
-                            type_str = GetTypeString(t);
-
-                          ret += Tab(4) + "map.Write(\"" + i->GetID() +
-                                 "\", \"" + type_str + "\"" + ", param." +
-                                 i->GetID() + ");" + NLine(1);
+                            ret += Tab(4) + "map.Write(\"" + i->GetID() +
+                                 "\", param." + i->GetID() + ");" + NLine(1);
                         }
                         return ret;
                       }));
@@ -145,14 +137,8 @@ std::string CsGeneratorBase::GetSerializer(const Structure& st) {
                std::string ret;
                std::string type_str;
                for (const auto& i : st.GetElements()) {
-                 auto& t = i->GetType();
-                 if (t.IsEnumType())
-                   type_str = "int";
-                 else
-                   type_str = GetTypeString(t);
-
-                 ret += Tab(4) + "map.Read(\"" + i->GetID() + "\", \"" +
-                        type_str + "\"" + ", out param." + i->GetID() + ");" +
+                 ret += Tab(4) + "map.Read(\"" + i->GetID() +
+                        "\", out param." + i->GetID() + ");" +
                         NLine(1);
                }
                return ret;
@@ -215,24 +201,13 @@ void CsGeneratorBase::AddSerializerList(const BaseType& type,
 std::string CsGeneratorBase::GenListWrite(const BaseType& type,
                                           const std::string& type_str) {
   std::string ret;
-  std::string type_string;
-  if (type.ToString() == "map") {
-    if (type.GetValueType()->IsEnumType())
-      type_string = "int";
-    else
-      type_string = ConvertTypeToString(*type.GetValueType());
 
-    ret = ReplaceAll(CB_LIST_MAP_WRITE)
-              .Change("<KEY_TYPE>", ConvertTypeToString(*type.GetKeyType()))
-              .Change("<VALUE_TYPE>", type_string);
+  if (type.ToString() == "map") {
+    ret = CB_LIST_MAP_WRITE;
   } else if (type.ToString() == "set") {
-    ret = ReplaceAll(CB_LIST_SET_WRITE)
-              .Change("<VALUE_TYPE>", ConvertTypeToString(*type.GetMetaType()));
-  } else if (type.GetMetaType()->IsEnumType()) {
-    ret = ReplaceAll(CB_LIST_WRITE).Change("<VALUE_TYPE>", std::string("int"));
+    ret = CB_LIST_SET_WRITE;
   } else {
-    ret = ReplaceAll(CB_LIST_WRITE)
-              .Change("<VALUE_TYPE>", ConvertTypeToString(*type.GetMetaType()));
+    ret = CB_LIST_WRITE;
   }
 
   return ret;
@@ -246,13 +221,11 @@ std::string CsGeneratorBase::GenListRead(const BaseType& type,
     if (type.GetValueType()->IsEnumType()) {
       ret = ReplaceAll(CB_LIST_MAP_READ)
                 .Change("<KEY_TYPE>", ConvertTypeToString(*type.GetKeyType()))
-                .Change("<TYPE_STRING>", std::string("int"))
                 .Change("<VALUE_TYPE>", type.GetValueType()->ToString());
     } else {
       ret =
           ReplaceAll(CB_LIST_MAP_READ)
               .Change("<KEY_TYPE>", ConvertTypeToString(*type.GetKeyType()))
-              .Change("<TYPE_STRING>", ConvertTypeToString(*type.GetKeyType()))
               .Change("<VALUE_TYPE>",
                       ConvertTypeToString(*type.GetValueType()));
     }
@@ -265,7 +238,6 @@ std::string CsGeneratorBase::GenListRead(const BaseType& type,
       list_method = "Last";
 
     ret = ReplaceAll(CB_LIST_READ)
-              .Change("<TYPE_STRING>", std::string("int"))
               .Change("<LIST_METHOD>", list_method)
               .Change("<VALUE_TYPE>", type.GetMetaType()->ToString());
   } else {
@@ -274,7 +246,6 @@ std::string CsGeneratorBase::GenListRead(const BaseType& type,
       list_method = "Last";
 
     ret = ReplaceAll(CB_LIST_READ)
-              .Change("<TYPE_STRING>", ConvertTypeToString(*type.GetMetaType()))
               .Change("<LIST_METHOD>", list_method)
               .Change("<VALUE_TYPE>", ConvertTypeToString(*type.GetMetaType()));
   }
@@ -384,13 +355,7 @@ std::string CsGeneratorBase::ConvertTypeToDeserializer(
     }
   }
 
-  std::string type_str;
-
-  if (type.GetUserDefinedType() == BaseType::UserType::ENUM)
-    type_str = "int";
-  else
-    type_str = GetTypeString(type);
-  ret += map + ".Read(" + "\"" + param_id + "\", \"" + type_str + "\", out ";
+  ret += map + ".Read(" + "\"" + param_id + "\", out ";
   if (IsDelegateType(type)) {
     ret += "CallbackBase del_" + gen_id + ");\n";
     ret +=
@@ -411,20 +376,9 @@ std::string CsGeneratorBase::ConvertTypeToDeserializer(
 
 std::string CsGeneratorBase::ConvertTypeToSerializer(std::string gen_id,
                                                      std::string param_id,
-                                                     std::string param_type,
                                                      std::string map) {
-  return map + ".Write(\"" + param_id + "\", \"" + param_type + "\", " +
-         gen_id + ");\n";
-}
 
-std::string CsGeneratorBase::ConvertTypeToSerializer(std::string gen_id,
-                                                     std::string param_id,
-                                                     const BaseType& type,
-                                                     std::string map) {
-  if (type.GetUserDefinedType() == BaseType::UserType::ENUM)
-    return ConvertTypeToSerializer(gen_id, param_id, "int", map);
-  else
-    return ConvertTypeToSerializer(gen_id, param_id, GetTypeString(type), map);
+  return map + ".Write(\"" + param_id + "\", " + gen_id + ");\n";
 }
 
 std::string CsGeneratorBase::Tab(int cnt) {
@@ -708,16 +662,25 @@ std::string CsGeneratorBase::GenUnitMapReadWrite(const Interface& iface) {
   for (const auto& iter : types) {
     auto& type_str = iter.first;
     auto& base_type = iter.second;
+
+    std::string unit_type;
+    if (base_type.IsEnumType())
+      unit_type = "int";
+    else
+      unit_type = GetTypeString(base_type);
+
     code +=
         ReplaceAll(CB_UNITMAP_READ_READ_BASE)
             .Change("<PARAM_TYPE>", GenUnitMapParamType(base_type, type_str))
             .Change("<PARAM_INIT>",
                     GenUnitMapParamInit(iface, base_type, type_str))
+            .Change("<UNIT_TYPE>", unit_type)
             .Change("<UINT_READ>",
                     GenUnitMaUintRead(iface, base_type, type_str));
     code +=
         ReplaceAll(CB_UNITMAP_READ_WRITE_BASE)
             .Change("<PARAM_TYPE>", GenUnitMapParamType(base_type, type_str))
+            .Change("<UNIT_TYPE>", unit_type)
             .Change("<UINT_WRITE>", GenUnitMaUintWrite(iface, base_type));
   }
 
@@ -823,9 +786,7 @@ void CsGeneratorBase::GenInvokeMethod(std::ofstream& stream,
       [&]() -> std::string {
         std::string m;
         for (const auto& i : decl.GetParameters()) {
-          m += ConvertTypeToSerializer(
-              i->GetID(), i->GetID(),
-              GetTypeString(i->GetParameterType().GetBaseType()), "map");
+          m += ConvertTypeToSerializer(i->GetID(), i->GetID(), "map");
         }
         return AddIndent(TAB_SIZE * 6, m);
       });
index 58df4bc..59d5552 100644 (file)
@@ -63,9 +63,7 @@ class CsGeneratorBase : public Generator {
                                         bool make_new_type = true,
                                         const std::string iface_id = "");
   std::string ConvertTypeToSerializer(std::string gen_id, std::string param_id,
-                                      const BaseType& type, std::string map);
-  std::string ConvertTypeToSerializer(std::string gen_id, std::string param_id,
-                                      std::string param_type, std::string map);
+                                      std::string map);
   std::string ConvertTypeToParcelType(const std::string& key);
   std::string GetParameters(const Parameters& ps);
   std::string Tab(int cnt);
index 432fcbd..638438f 100644 (file)
@@ -57,8 +57,8 @@ R"__cs_cb(
             private static void Serialize(Parcel h, RemoteException param)
             {
                 UnitMap map = new UnitMap();
-                map.Write("cause", "int", param.Cause);
-                map.Write("message", "string", param.Message);
+                map.Write("cause", param.Cause);
+                map.Write("message", param.Message);
 
                 map.Serialize(h);
             }
@@ -67,9 +67,9 @@ R"__cs_cb(
             {
                 UnitMap map = new UnitMap();
                 map.Deserialize(h);
-                map.Read("cause", "int", out int cause);
+                map.Read("cause", out int cause);
                 param.Cause = cause;
-                map.Read("message", "string", out string message);
+                map.Read("message", out string message);
                 param.Message = message;
             }
 )__cs_cb";
@@ -112,7 +112,7 @@ internal class Unit
 
 const char CB_UNITMAP_READ_READ_BASE[] =
 R"__cs_cb(
-internal void Read(string name, string type, out <PARAM_TYPE> value)
+internal void Read(string name, out <PARAM_TYPE> value)
 {
     <PARAM_INIT>
     if (map.ContainsKey(name) == false)
@@ -122,9 +122,9 @@ internal void Read(string name, string type, out <PARAM_TYPE> value)
     }
 
     Unit unit = map[name];
-    if (unit.type != type)
+    if (unit.type != "<UNIT_TYPE>")
     {
-        Tizen.Log.Error("RPC_PORT", "type is not " + type + " : " + unit.type);
+        Tizen.Log.Error("RPC_PORT", "type is not <UNIT_TYPE> : " + unit.type);
         return;
     }
     <UINT_READ>
@@ -133,11 +133,11 @@ internal void Read(string name, string type, out <PARAM_TYPE> value)
 
 const char CB_UNITMAP_READ_WRITE_BASE[] =
 R"__cs_cb(
-internal void Write(string name, string type, <PARAM_TYPE> value)
+internal void Write(string name, <PARAM_TYPE> value)
 {
     Unit unit = new Unit();
     unit.name = name;
-    unit.type = type;
+    unit.type = "<UNIT_TYPE>";
     <UINT_WRITE>
     map[name] = unit;
 }
@@ -210,9 +210,9 @@ R"__cs_cb(
                 internal static void Serialize(Parcel h, CallbackBase param)
                 {
                     UnitMap map = new UnitMap();
-                    map.Write("id", "int", param.Id);
-                    map.Write("seq_id", "int", param.SeqId);
-                    map.Write("once", "bool", param.Once);
+                    map.Write("id", param.Id);
+                    map.Write("seq_id", param.SeqId);
+                    map.Write("once", param.Once);
                     map.Serialize(h);
                 }
 
@@ -220,9 +220,9 @@ R"__cs_cb(
                 {
                     UnitMap map = new UnitMap();
                     map.Deserialize(h);
-                    map.Read("id", "int", out param.Id);
-                    map.Read("seq_id", "int", out param.SeqId);
-                    map.Read("once", "bool", out param.Once);
+                    map.Read("id", out param.Id);
+                    map.Read("seq_id", out param.SeqId);
+                    map.Read("once", out param.Once);
                 }
             }
 
@@ -271,8 +271,8 @@ R"__cs_cb(
                     {
                         UnitMap map = new UnitMap();
 
-                        map.Write("[METHOD]", "int", (int)MethodId.__Callback);
-                        map.Write("delegate", "delegate", this);
+                        map.Write("[METHOD]", (int)MethodId.__Callback);
+                        map.Write("delegate", this);
 
 $$
                         map.Serialize(p);
@@ -336,26 +336,26 @@ R"__cs_cb(
 )__cs_cb";
 
 constexpr const char CB_LIST_MAP_WRITE[] =
-R"__cs_cb(                    map.Write("key-" + index.ToString(), "<KEY_TYPE>", i.Key);
-                    map.Write("value-" + index.ToString(), "<VALUE_TYPE>", i.Value);)__cs_cb";
+R"__cs_cb(                    map.Write("key-" + index.ToString(), i.Key);
+                    map.Write("value-" + index.ToString(), i.Value);)__cs_cb";
 
 constexpr const char CB_LIST_SET_WRITE[] =
-R"__cs_cb(                    map.Write("key-" + index.ToString(), "<VALUE_TYPE>", i);)__cs_cb";
+R"__cs_cb(                    map.Write("key-" + index.ToString(), i);)__cs_cb";
 
 constexpr const char CB_LIST_WRITE[] =
-R"__cs_cb(                    map.Write(index.ToString(), "<VALUE_TYPE>", i);)__cs_cb";
+R"__cs_cb(                    map.Write(index.ToString(), i);)__cs_cb";
 
 constexpr const char CB_LIST_MAP_READ[] =
-R"__cs_cb(                    map.Read("key-" + index.ToString(), "<KEY_TYPE>", out <KEY_TYPE> key);
-                    map.Read("value-" + index.ToString(), "<TYPE_STRING>", out <VALUE_TYPE> value);
+R"__cs_cb(                    map.Read("key-" + index.ToString(), out <KEY_TYPE> key);
+                    map.Read("value-" + index.ToString(), out <VALUE_TYPE> value);
                     param[key] = value;)__cs_cb";
 
 constexpr const char CB_LIST_SET_READ[] =
-R"__cs_cb(                    map.Read("key-" + index.ToString(), "<VALUE_TYPE>", out <VALUE_TYPE> value);
+R"__cs_cb(                    map.Read("key-" + index.ToString(), out <VALUE_TYPE> value);
                      param.Add(value);)__cs_cb";
 
 constexpr const char CB_LIST_READ[] =
-R"__cs_cb(                    map.Read("key-" + index.ToString(), "<TYPE_STRING>", out <VALUE_TYPE> value);
+R"__cs_cb(                    map.Read("key-" + index.ToString(), out <VALUE_TYPE> value);
                     param.Add<LIST_METHOD>(value);)__cs_cb";
 
 const char CB_LIST_SERIALIZER[] =
@@ -363,7 +363,7 @@ R"__cs_cb(
             private static void Serialize(Parcel h, <TYPE> param)
             {
                 UnitMap map = new UnitMap();
-                map.Write("<LENGTH_NAME>", "int", param.Count & int.MaxValue);
+                map.Write("<LENGTH_NAME>", param.Count & int.MaxValue);
                 int index = 0;
                 foreach (var i in param)
                 {
@@ -380,7 +380,7 @@ R"__cs_cb(
             {
                 UnitMap map = new UnitMap();
                 map.Deserialize(h);
-                map.Read("<LENGTH_NAME>", "int", out int length);
+                map.Read("<LENGTH_NAME>", out int length);
                 for (int index = 0; index < length; index++)
                 {
 <READ_LIST>
index 7da9e85..747062c 100644 (file)
@@ -111,9 +111,7 @@ std::string CsGroupGen::GetParamSerializer(const Declaration& decl) {
     auto& pt = i->GetParameterType();
     if (pt.GetDirection() == ParameterType::Direction::OUT)
       continue;
-    m += Tab(5) + ConvertTypeToSerializer(
-                     i->GetID(), i->GetID(),
-                     GetTypeString(i->GetParameterType().GetBaseType()), "map");
+    m += Tab(5) + ConvertTypeToSerializer(i->GetID(), i->GetID(), "map");
   }
 
   return m;
index 960eee5..bf8e5bd 100644 (file)
@@ -158,15 +158,14 @@ void CsProxyGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
 
     m += Tab(5) + NLine(1) + "UnitMap map = new UnitMap();" + NLine(1);
     m += ConvertTypeToSerializer("(int)MethodId." + decl.GetID(), "[METHOD]",
-                                 "int", "map");
+                                 "map");
 
     for (const auto& i : decl.GetParameters()) {
       auto& pt = i->GetParameterType();
       if (pt.GetDirection() == ParameterType::Direction::OUT)
         continue;
 
-      m += ConvertTypeToSerializer(i->GetID(), i->GetID(), pt.GetBaseType(),
-                                   "map");
+      m += ConvertTypeToSerializer(i->GetID(), i->GetID(), "map");
 
       if (IsDelegateType(pt.GetBaseType())) {
         l += "_delegateList.Add(" + i->GetID() + ");\n";
index 31c76c7..81d4955 100644 (file)
@@ -41,7 +41,7 @@ R"__cs_cb(
             private void ProcessReceivedEvent(UnitMap map)
             {
                 CallbackBase cb;
-                map.Read("delegate", "delegate", out cb);
+                map.Read("delegate", out cb);
 
                 foreach (var i in _delegateList)
                 {
@@ -74,7 +74,7 @@ R"__cs_cb(            Parcel parcelReceived;
                     map.Deserialize(parcelReceived);
 
                     int cmd;
-                    map.Read("[METHOD]", "int", out cmd);
+                    map.Read("[METHOD]", out cmd);
 
                     if (cmd != (int)MethodId.__Callback)
                     {
@@ -263,7 +263,7 @@ R"__cs_cb(    UnitMap mapReceived;
 const char CB_INVOCATION_REMOTE_EXCEPTION[] =
 R"__cs_cb(    if (mapReceived.ContainsName("[REMOTE_EXCEPTION]"))
     {
-        mapReceived.Read("[REMOTE_EXCEPTION]", "remote_exception", out RemoteException exception);
+        mapReceived.Read("[REMOTE_EXCEPTION]", out RemoteException exception);
         throw exception;
     }
 )__cs_cb";
index 31dbd8b..2e9aced 100644 (file)
@@ -116,15 +116,33 @@ void CsStubGen::GenReceivedEvent(std::ofstream& stream,
   stream << CB_ON_RECEIVED_EVENT_BACK;
 }
 
+
+std::string CsStubGen::GetWriteOutParam(const Declaration& decl) {
+  int cnt = 0;
+  std::string code;
+
+  for (const auto& i : decl.GetParameters()) {
+    auto& pt = i->GetParameterType();
+    cnt++;
+    if (pt.GetDirection() == ParameterType::Direction::IN)
+      continue;
+
+    code += ConvertTypeToSerializer("param" + std::to_string(cnt),
+                                i->GetID(), "result_map");
+  }
+
+  return code;
+}
+
 std::string CsStubGen::GetInvocationMethod(const Declaration& decl) {
   std::string code;
   if (decl.GetType().ToString() != "void") {
-    code = ReplaceAll(CB_INVOCATION_REMOTE_EXCEPTION)
-             .Change("<SYNC_INVOCATION>", GetInvocationMethodParam(decl, true))
-             .Change("<WRITE_RESULT>",
-                     ConvertTypeToSerializer("retVal", "[RESULT]",
-                                             GetTypeString(decl.GetType()),
-                                             "result_map"));
+    code =
+        ReplaceAll(CB_INVOCATION_REMOTE_EXCEPTION)
+            .Change("<SYNC_INVOCATION>", GetInvocationMethodParam(decl, true))
+            .Change("<WRITE_RESULT>", ConvertTypeToSerializer(
+                                          "retVal", "[RESULT]", "result_map"))
+            .Change("<WRITE_OUT_PARAM>", GetWriteOutParam(decl));
   } else {
     code = NLine(1) + GetInvocationMethodParam(decl, false);
   }
@@ -195,16 +213,6 @@ void CsStubGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
 
   cnt = 0;
   m = CB_INVOCATION_RESULT_PRE;
-  for (const auto& i : decl.GetParameters()) {
-    auto& pt = i->GetParameterType();
-    cnt++;
-    if (pt.GetDirection() == ParameterType::Direction::IN)
-      continue;
-
-    m += ConvertTypeToSerializer("param" + std::to_string(cnt), i->GetID(),
-                                 GetTypeString(pt.GetBaseType()), "result_map");
-  }
-
   m += "result_map.Serialize(result);\n";
   m += "result.Send(port);\n";
   stream << AddIndent(TAB_SIZE * 9, m);
index b6c9f6a..a04199a 100644 (file)
@@ -50,6 +50,7 @@ class CsStubGen : public CsGeneratorBase {
   void GenDisposable(std::ofstream& stream, const Interface& iface);
   std::string GetInvocationMethodParam(const Declaration& decl, bool hasRet);
   std::string GetInvocationMethod(const Declaration& decl);
+  std::string GetWriteOutParam(const Declaration& decl);
 };
 
 }  // namespace version2
index 5172901..3da305f 100644 (file)
@@ -163,7 +163,7 @@ R"__cs_cb(
                         UnitMap map = new UnitMap();
                         map.Deserialize(p);
 
-                        map.Read("[METHOD]", "int", out cmd);
+                        map.Read("[METHOD]", out cmd);
 
                         switch ((MethodId)cmd)
                         {
@@ -271,7 +271,7 @@ R"__cs_cb(
 if (b._is_app && CheckPrivilege((MethodId)cmd, b) == false)
 {
     RemoteException ex = new RemoteException("Permission denied", (int)Tizen.Internals.Errors.ErrorCode.PermissionDenied);
-    result_map.Write("[REMOTE_EXCEPTION]", "remote_exception", ex);
+    result_map.Write("[REMOTE_EXCEPTION]", ex);
 } else {
     <INVOCATION>
 }
@@ -282,9 +282,10 @@ R"__cs_cb(try
 {
     <SYNC_INVOCATION>
     <WRITE_RESULT>
+    <WRITE_OUT_PARAM>
 } catch (RemoteException ex)
 {
-    result_map.Write("[REMOTE_EXCEPTION]", "remote_exception", ex);
+    result_map.Write("[REMOTE_EXCEPTION]", ex);
 })__cs_cb";
 
 constexpr const char CB_INVOCATION_RESULT_PRE[] =
@@ -294,7 +295,7 @@ ParcelHeader resultHeader = result.GetHeader();
 resultHeader.SetTag(_tidlVersion);
 resultHeader.SetSequenceNumber(header.GetSequenceNumber());
 
-result_map.Write("[METHOD]", "int", (int)MethodId.__Result);
+result_map.Write("[METHOD]", (int)MethodId.__Result);
 )__cs_cb";
 
 #endif  // IDLC_CS_GEN_VERSION2_CS_STUB_GENRATOR_CB_H_
\ No newline at end of file