Revert "Modified C Generator" 95/187695/1
authorJunghoon Park <jh9216.park@samsung.com>
Tue, 28 Aug 2018 02:25:31 +0000 (02:25 +0000)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 28 Aug 2018 02:25:31 +0000 (02:25 +0000)
This reverts commit 282ec9b2ebba1827c3318ecbdc4b522e5f0086f6.

Change-Id: I328e32c48c5559a5c7c1c7cdd1b62bdf48c35d06

idlc/c_gen/c_body_gen_base.cc
idlc/c_gen/c_body_gen_base.h
idlc/c_gen/c_body_gen_base_cb.h
idlc/c_gen/c_header_gen_base.cc
idlc/c_gen/c_header_gen_base.h
idlc/c_gen/c_header_gen_base_cb.h

index 018e7d5..bc8eaea 100644 (file)
@@ -77,8 +77,6 @@ void CBodyGeneratorBase::GenStructure(std::ofstream& stream,
   GenStructureSetter(stream, st);
   GenStructureGetter(stream, st);
   GenStructureIterator(stream, st);
-  GenStructureRemover(stream, st);
-  GenStructureLengthGetter(stream, st);
 }
 
 void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
@@ -331,75 +329,6 @@ void CBodyGeneratorBase::GenStructureCloner(std::ofstream& stream,
         }));
 }
 
-void CBodyGeneratorBase::GenStructureRemover(std::ofstream& stream,
-                                             const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() != "list")
-      continue;
-
-    stream << SmartIndent(GenTemplateString(CB_STRUCT_REMOVER,
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            if (i->GetType().GetMetaType()->IsUserDefinedType() ||
-                i->GetType().GetMetaType()->ToString() == "list" ||
-                i->GetType().GetMetaType()->ToString() == "array")
-              return GetParcelParamTypeString(*i->GetType().GetMetaType());
-
-            return ConvertTypeToString(ParameterType::Direction::IN,
-                *i->GetType().GetMetaType());
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            std::string str;
-            str += NLine(1);
-            str += "h->" + i->GetID() + " = g_list_remove(h-> " +
-                i->GetID() + ", ";
-            if (i->GetType().GetMetaType()->IsUserDefinedType() ||
-                i->GetType().GetMetaType()->ToString() == "list" ||
-                i->GetType().GetMetaType()->ToString() == "array" ||
-                i->GetType().GetMetaType()->ToString() == "string" ||
-                i->GetType().GetMetaType()->ToString() == "bundle")
-              str += i->GetID() + ");";
-            else
-              str += "GUINT_TO_POINTER(" + i->GetID() + "));";
-            str += NLine(1);
-            return str;
-          }));
-  }
-}
-
-void CBodyGeneratorBase::GenStructureLengthGetter(std::ofstream& stream,
-                                                  const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() != "list")
-      continue;
-
-    stream << SmartIndent(GenTemplateString(CB_STRUCT_LENGTH_GETTER,
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          }));
-  }
-}
-
 std::string CBodyGeneratorBase::GetParcelTypeString(const BaseType& type,
                                                     bool meta_type) {
   if (type.IsUserDefinedType())
@@ -453,7 +382,7 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id,
           return "h->" + id;
         },
         [&]()->std::string {
-          return GetParcelParamTypeString(*type.GetMetaType(), true);
+          return GetParcelParamTypeString(*type.GetMetaType());
         },
         [&]()->std::string {
           return GenTemplateString(parcel,
@@ -469,7 +398,7 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id,
                   return "value";
                 if (type.GetMetaType()->ToString() == "string")
                   return ReplaceAll(ternary_operation, "##", "value");
-                return "GPOINTER_TO_UINT(value)";
+                return "*value";
               });
         });
   } else if (type.ToString() == "array") {
@@ -525,16 +454,7 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id,
               });
         },
         [&]()->std::string {
-          return GetParcelParamTypeString(*type.GetMetaType(), false);
-        },
-        [&]()->std::string {
-          if (type.GetMetaType()->IsUserDefinedType() ||
-              type.GetMetaType()->ToString() == "list" ||
-              type.GetMetaType()->ToString() == "array" ||
-              type.GetMetaType()->ToString() == "string" ||
-              type.GetMetaType()->ToString() == "bundle")
-            return "NULL;";
-          return "0;";
+          return GetParcelParamTypeString(*type.GetMetaType());
         },
         [&]()->std::string {
           std::string s;
@@ -571,12 +491,24 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id,
                   return "&value";
                 });
           } else {
+            s += "value = calloc(1, sizeof(*value));" + NLine(1);
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!value";
+                },
+                [&]()->std::string {
+                  std::string ss;
+                  ss += "_E(\"Out of memory\");" + NLine(1);
+                  ss += "return;";
+                  return ss;
+                });
+            s += NLine(1);
             s += GenTemplateString(parcel,
                 [&]()->std::string {
                   return GetParcelReadFunctionString(*type.GetMetaType());
                 },
                 [&]()->std::string {
-                  return "&value";
+                  return "value";
                 });
           }
 
@@ -587,15 +519,6 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id,
         },
         [&]()->std::string {
           return "h->" + id;
-        },
-        [&]()->std::string {
-          if (type.GetMetaType()->IsUserDefinedType() ||
-              type.GetMetaType()->ToString() == "list" ||
-              type.GetMetaType()->ToString() == "array" ||
-              type.GetMetaType()->ToString() == "string" ||
-              type.GetMetaType()->ToString() == "bundle")
-            return "value";
-          return "GUINT_TO_POINTER(value)";
         });
   } else if (type.ToString() == "array") {
     str += GenTemplateString(ReplaceAll(CB_READ_ARRAY_BLOCK, "##", id),
@@ -678,8 +601,26 @@ std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id,
     return str;
 
   if (type.ToString() == "list") {
-    str += "g_list_free(h->" + id + ");";
-    str += NLine(1);
+    str += GenTemplateString(CB_FINALIZE_LIST_BLOCK,
+        [&]()->std::string {
+          return "h->" + id;
+        },
+        [&]()->std::string {
+          return GetParcelParamTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          return GenTemplateString(CB_IF_STATEMENT,
+              [&]()->std::string {
+                return "value";
+              },
+              [&]()->std::string {
+                return GetDestructorString(*type.GetMetaType(),
+                    "value", true) + NLine(1);
+              });
+        },
+        [&]()->std::string {
+          return "h->" + id;
+        });
   } else if (type.ToString() == "array") {
     if (!type.GetMetaType()->IsUserDefinedType() &&
          type.GetMetaType()->ToString() != "list" &&
@@ -768,18 +709,36 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id,
             return "h->" + id;
           },
           [&]()->std::string {
+            if (type.GetMetaType()->ToString() == "string")
+              return "g_list_append(h->" + id + ", strdup(" + id + "))";
             return "g_list_append(h->" + id + ", " + id + ")";
           });
     } else {
       str += GenTemplateString(CB_SETTER_LIST_BLOCK,
           [&]()->std::string {
-            return id;
+            return GetParcelParamTypeString(*type.GetMetaType());
           },
           [&]()->std::string {
-            return "h->" + id;
+            std::string s;
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!value";
+                },
+                [&]()->std::string {
+                  std::string s;
+                  s += "_E(\"Out of memory\");" + NLine(1);
+                  s += "return -1;";
+                  return s;
+                });
+            s += NLine(1);
+            s += GetSetterString("*value", id);
+            return s;
           },
           [&]()->std::string {
             return "h->" + id;
+          },
+          [&]()->std::string {
+              return "h->" + id;
           });
     }
   } else if (type.ToString() == "array") {
@@ -870,7 +829,7 @@ std::string CBodyGeneratorBase::GetIteratorString(const std::string& id,
             type.GetMetaType()->ToString() == "bundle")
           return "value";
 
-        return "GPOINTER_TO_UINT(value)";
+        return "*value";
       });
 
   return str;
@@ -912,6 +871,57 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
           return "h->" + id;
         },
         [&]()->std::string {
+          return GetParcelParamTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          return GetParcelParamTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        },
+        [&]()->std::string {
+          std::string s;
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array" ||
+              type.GetMetaType()->ToString() == "string" ||
+              type.GetMetaType()->ToString() == "bundle") {
+            s += GetSetterString(*type.GetMetaType(),
+                "new_value", "value");
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!new_value";
+                },
+              [&]()->std::string {
+                std::string ss;
+                ss += "_E(\"Failed to duplicate value\");" + NLine(1);
+                ss += "rpc_port_" + GetStructIdWithNamespace(st)
+                   + "_destroy(handle);" + NLine(1);
+                ss += "return -1;";
+                return ss;
+              });
+          } else {
+            s += "new_value = calloc(1, sizeof(*new_value));" + NLine(1);
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!new_value";
+                },
+                [&]()->std::string {
+                  std::string tmp;
+                  tmp += "_E(\"Out of memory\");" + NLine(1);
+                  tmp += "rpc_port_" + GetStructIdWithNamespace(st)
+                      + "_destroy(handle);" + NLine(1);
+                  tmp += "return -1;";
+                  return tmp;
+                });
+            s += NLine(1);
+            s += GetSetterString(*type.GetMetaType(),
+                "*new_value", "*value");
+          }
+          s += NLine(1);
+          return s;
+        },
+        [&]()->std::string {
           return "handle->" + id;
         },
         [&]()->std::string {
index 35ff0fa..1126d5d 100644 (file)
@@ -64,8 +64,6 @@ class CBodyGeneratorBase : public CGeneratorBase {
   void GenStructureGetter(std::ofstream& stream, const Structure& st);
   void GenStructureIterator(std::ofstream& stream, const Structure& st);
   void GenStructureCloner(std::ofstream& stream, const Structure& st);
-  void GenStructureRemover(std::ofstream& stream, const Structure& st);
-  void GenStructureLengthGetter(std::ofstream& stream, const Structure& st);
 
  private:
   std::string GetParcelTypeString(const BaseType& type, bool meta_type);
index 1790b18..647e090 100644 (file)
@@ -167,42 +167,15 @@ do {
         $$value = iter->data;
 
         iter = g_list_next(iter);
-        if (!value)
-            _W("Warning: value is nullptr");
-
+        if (!value) {
+            _W("Warning: value is NULL");
+            continue;
+        }
         $$
     }
 } while (0);
 )__c_cb";
 
-const char CB_STRUCT_REMOVER[] =
-R"__c_cb(
-int rpc_port_$$_remove_$$(rpc_port_$$_h h, $$$$)
-{
-    if (!h) {
-        _E("Invalid parameter");
-        return -1;
-    }
-$$
-    return 0;
-}
-)__c_cb";
-
-const char CB_STRUCT_LENGTH_GETTER[] =
-R"__c_cb(
-int rpc_port_$$_get_$$_length(rpc_port_$$_h h, unsigned int *length)
-{
-    if (!h || !length) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    *length = g_list_length(h->$$);
-
-    return 0;
-}
-)__c_cb";
-
 const char CB_WRITE_ARRAY_BLOCK[] =
 R"__c_cb(
 do {
@@ -218,10 +191,10 @@ R"__c_cb(do {
 
     $$
     for (int i = 0; i < len; i++) {
-        $$value = $$;
+        $$value = NULL;
 
         $$
-        $$ = g_list_append($$, $$);
+        $$ = g_list_append($$, value);
     }
 } while (0);
 )__c_cb";
@@ -273,8 +246,10 @@ do {
 const char CB_SETTER_LIST_BLOCK[] =
 R"__c_cb(
 do {
-    gpointer value = GUINT_TO_POINTER($$);
+    $$value;
 
+    value = calloc(1, sizeof(*value));
+    $$
     $$ = g_list_append($$, value);
 } while (0);
 )__c_cb";
@@ -326,8 +301,10 @@ do {
         $$value = iter->data;
 
         iter = g_list_next(iter);
-        if (!value)
-            _W("Warning: value is nullptr");
+        if (!value) {
+            _W("Warning: value is NULL");
+            continue;
+        }
 
         bool ret = callback($$, user_data);
         if (!ret)
@@ -343,7 +320,17 @@ do {
 
     iter = $$;
     while (iter) {
-        $$ = g_list_append($$, iter->data);
+        $$new_value;
+        $$value = iter->data;
+
+        if (!value) {
+            _E("Error: value is NULL");
+            rpc_port_$$_destroy(handle);
+            return -1;
+        }
+
+        $$
+        $$ = g_list_append($$, new_value);
         iter = g_list_next(iter);
     }
 } while (0);
index 347c8e4..8848fe4 100644 (file)
@@ -78,8 +78,6 @@ void CHeaderGeneratorBase::GenStructure(std::ofstream& stream,
   GenStructureSetter(stream, st);
   GenStructureGetter(stream, st);
   GenStructureIterator(stream, st);
-  GenStructureRemover(stream, st);
-  GenStructureLengthGetter(stream, st);
 }
 
 void CHeaderGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
@@ -252,54 +250,4 @@ void CHeaderGeneratorBase::GenStructureCloner(std::ofstream& stream,
       });
 }
 
-void CHeaderGeneratorBase::GenStructureRemover(std::ofstream& stream,
-                                               const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() != "list")
-      continue;
-
-    GenTemplate(CB_STRUCT_REMOVER, stream,
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          return i->GetID();
-        },
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          if (i->GetType().GetMetaType()->IsUserDefinedType() ||
-              i->GetType().GetMetaType()->ToString() == "list" ||
-              i->GetType().GetMetaType()->ToString() == "array")
-            return GetParcelParamTypeString(*i->GetType().GetMetaType());
-
-          return ConvertTypeToString(ParameterType::Direction::IN,
-              *i->GetType().GetMetaType());
-        },
-        [&]()->std::string {
-          return i->GetID();
-        });
-  }
-}
-
-void CHeaderGeneratorBase::GenStructureLengthGetter(std::ofstream& stream,
-                                                    const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() != "list")
-      continue;
-
-    GenTemplate(CB_STRUCT_LENGTH_GETTER, stream,
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          return i->GetID();
-        },
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        });
-  }
-}
-
 }  // namespace tidl
index f506c58..f9d0505 100644 (file)
@@ -46,8 +46,6 @@ class CHeaderGeneratorBase : public CGeneratorBase {
   void GenStructureGetter(std::ofstream& stream, const Structure& st);
   void GenStructureIterator(std::ofstream& stream, const Structure& st);
   void GenStructureCloner(std::ofstream& stream, const Structure& st);
-  void GenStructureRemover(std::ofstream& stream, const Structure& st);
-  void GenStructureLengthGetter(std::ofstream& stream, const Structure& st);
 };
 
 }  // namespace tidl
index c05aafb..d8e8e37 100644 (file)
@@ -67,14 +67,4 @@ R"__c_cb(
 int rpc_port_$$_clone(rpc_port_$$_h h, rpc_port_$$_h *clone);
 )__c_cb";
 
-const char CB_STRUCT_REMOVER[] =
-R"__c_cb(
-int rpc_port_$$_remove_$$(rpc_port_$$_h h, $$$$);
-)__c_cb";
-
-const char CB_STRUCT_LENGTH_GETTER[] =
-R"__c_cb(
-int rpc_port_$$_get_$$_length(rpc_port_$$_h h, unsigned int *length);
-)__c_cb";
-
 #endif  // IDLC_C_GEN_C_HEADER_GEN_BASE_CB_H_