Fix bugs of C Generator 51/261351/1
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 16 Jul 2021 01:30:34 +0000 (10:30 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 16 Jul 2021 01:30:34 +0000 (10:30 +0900)
If the type is built-in type, setting the result to an integer variable
is not needed.

Change-Id: I00106fcf8c8019b9b8c034b96fc9c48974ab81b5
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/gen/c_body_gen_base.cc

index 29b01e9..f555c26 100644 (file)
@@ -844,21 +844,30 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id,
     str += GenTemplateString(ReplaceAll(CB_SETTER_ARRAY_BLOCK, "##", id),
         [&]()->std::string {
           std::string s;
-          s += "int __ret = ";
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array")
+            s += "int __ret = ";
+
           s += GetSetterString(*type.GetMetaType(), "h->" + id + "[i]",
               id + "[i]");
-          s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-              [&]()->std::string {
-                return "__ret != 0";
-              },
-              [&]()->std::string {
-                std::string r;
-                r += "_E(\"Failed to clone " + id + "\");" + NLine(1);
-                r += GetFinalizeString(id, type, "h->") + NLine(1);
-                r += GetSetterString("h->" + id, "NULL") + NLine(1);
-                r += "return -1;";
-                return r;
-              });
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array") {
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "__ret != 0";
+                },
+                [&]()->std::string {
+                  std::string r;
+                  r += "_E(\"Failed to clone " + id + "\");" + NLine(1);
+                  r += GetFinalizeString(id, type, "h->") + NLine(1);
+                  r += GetSetterString("h->" + id, "NULL") + NLine(1);
+                  r += "return -1;";
+                  return r;
+                });
+          }
+
           s += NLine(1);
           return s;
         });
@@ -877,21 +886,31 @@ std::string CBodyGeneratorBase::GetGetterString(const std::string& id,
     str += GenTemplateString(ReplaceAll(CB_GETTER_ARRAY_BLOCK, "##", id),
         [&]()->std::string {
           std::string s;
-          s += "int __ret = ";
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array")
+            s += "int __ret = ";
+
           s += GetSetterString(*type.GetMetaType(),
               "(*" + id + ")[i]", "h->" + id + "[i]");
-          s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-              [&]()->std::string {
-                return "__ret != 0";
-              },
-              [&]()->std::string {
-                std::string r;
-                r += "_E(\"Failed to clone " + id + "\");" + NLine(1);
-                r += GetFinalizeString(id, type, "h->") + NLine(1);
-                r += GetSetterString("h->" + id, "NULL") + NLine(1);
-                r += "return -1;";
-                return r;
-              });
+
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array") {
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "__ret != 0";
+                },
+                [&]()->std::string {
+                  std::string r;
+                  r += "_E(\"Failed to clone " + id + "\");" + NLine(1);
+                  r += GetFinalizeString(id, type, "h->") + NLine(1);
+                  r += GetSetterString("h->" + id, "NULL") + NLine(1);
+                  r += "return -1;";
+                  return r;
+                });
+          }
+
           s += NLine(1);
           return s;
         });
@@ -1068,21 +1087,31 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
         },
         [&]()->std::string {
           std::string s;
-          s += "int __ret = ";
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array")
+            s += "int __ret = ";
+
           s += GetSetterString(*type.GetMetaType(),
               "handle->" + id + "[i]", "h->" + id + "[i]");
-          s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-              [&]()->std::string {
-                return "__ret != 0";
-              },
-              [&]()->std::string {
-                std::string tmp;
-                tmp += "_E(\"Failed to clone " + id + "\");" + NLine(1);
-                tmp += "rpc_port_" + GetStructIdWithNamespace(st) +
-                    "_destroy(handle);" + NLine(1);
-                tmp += "return -1;";
-                return tmp;
-              });
+
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array") {
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "__ret != 0";
+                },
+                [&]()->std::string {
+                  std::string tmp;
+                  tmp += "_E(\"Failed to clone " + id + "\");" + NLine(1);
+                  tmp += "rpc_port_" + GetStructIdWithNamespace(st) +
+                      "_destroy(handle);" + NLine(1);
+                  tmp += "return -1;";
+                  return tmp;
+                });
+          }
+
           s += NLine(1);
           return s;
         });