Fix bugs about C Generator 67/264967/2
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 6 Oct 2021 07:57:45 +0000 (16:57 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 6 Oct 2021 08:41:45 +0000 (17:41 +0900)
The generated codes make build break issues.

Change-Id: I1e0b687efff38d967e15c50ad241b5d8a4b41c89
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/gen/c_body_gen_base.cc
idlc/gen/c_gen_base.cc
idlc/gen/c_proxy_body_gen.cc
idlc/gen/c_proxy_body_gen.h
idlc/gen/c_proxy_body_gen_cb.h
idlc/gen/c_stub_body_gen.cc
idlc/gen/c_stub_body_gen_cb.h

index e1c3cf72a2f1b42ab80fb8deb35d5863c9b81fae..573a1c9144e8a7d263a41bd5e26d813df65f44a8 100644 (file)
@@ -213,15 +213,7 @@ std::string CBodyGeneratorBase::GenArrayParcelRead(
       type.ToString() == "array") {
     code = ReplaceAll(CB_STRUCTURE_ARRAY_USER_DEFINED_PARCEL_READ, "<PREFIX>",
         GetHandlePrefix());
-
-    std::string name;
-    auto* meta_type = type.GetMetaType();
-    if (meta_type == nullptr)
-      name = type.ToString();
-    else
-      name = GetFullNameFromType(*meta_type);
-
-    code = ReplaceAll(code, "<NAME>", name);
+    code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
   } else if (type.ToString() == "bundle") {
     code = std::string(CB_STRUCTURE_ARRAY_BUNDLE_PARCEL_READ);
   } else if (type.ToString() == "string" || type.ToString() == "file") {
@@ -247,15 +239,7 @@ std::string CBodyGeneratorBase::GenArrayElementsFree(
       type.ToString() == "array") {
     code = ReplaceAll(CB_STRUCTURE_ARRAY_USER_DEFINED_FREE, "<PREFIX>",
         GetHandlePrefix());
-
-    std::string name;
-    auto* meta_type = type.GetMetaType();
-    if (meta_type == nullptr)
-      name = type.ToString();
-    else
-      name = GetFullNameFromType(*meta_type);
-
-    code = ReplaceAll(code, "<NAME>", name);
+    code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
   } else if (type.ToString() == "bundle") {
     code = std::string(CB_STRUCTURE_ARRAY_BUNDLE_FREE);
   } else if (type.ToString() == "string" || type.ToString() == "file") {
@@ -307,15 +291,7 @@ std::string CBodyGeneratorBase::GenListDataFree(
       type.ToString() == "array") {
     code = ReplaceAll(CB_STRUCTURE_LIST_USER_DEFINED_FREE, "<PREFIX>",
         GetHandlePrefix());
-
-    std::string name;
-    auto* meta_type = type.GetMetaType();
-    if (meta_type == nullptr)
-      name = type.ToString();
-    else
-      name = GetFullNameFromType(*meta_type);
-
-    code = ReplaceAll(code, "<NAME>", name);
+    code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
   } else if (type.ToString() == "bundle") {
     code = std::string(CB_STRUCTURE_LIST_BUNDLE_FREE);
   } else if (type.ToString() == "string" || type.ToString() == "flie") {
@@ -364,15 +340,7 @@ std::string CBodyGeneratorBase::GenListParcelRead(
       type.ToString() == "array") {
     code = ReplaceAll(CB_STRUCTURE_LIST_USER_DEFINED_PARCEL_READ, "<PREFIX>",
         GetHandlePrefix());
-
-    std::string name;
-    auto* meta_type = type.GetMetaType();
-    if (meta_type == nullptr)
-      name = type.ToString();
-    else
-      name = GetFullNameFromType(*meta_type);
-
-    code = ReplaceAll(code, "<NAME>", name);
+    code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
   } else if (type.ToString() == "bundle") {
     code = std::string(CB_STRUCTURE_LIST_BUNDLE_PARCEL_READ);
   } else if (type.ToString() == "string" || type.ToString() == "file") {
@@ -401,15 +369,7 @@ std::string CBodyGeneratorBase::GenListAdd(
       type.ToString() == "array") {
     code = ReplaceAll(CB_STRUCTURE_LIST_USER_DEFINED_ADD, "<PREFIX>",
         GetHandlePrefix());
-
-    std::string name;
-    auto* meta_type = type.GetMetaType();
-    if (meta_type == nullptr)
-      name = type.ToString();
-    else
-      name = GetFullNameFromType(*meta_type);
-
-    code = ReplaceAll(code, "<NAME>", name);
+    code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
   } else if (type.ToString() == "bundle") {
     code = std::string(CB_STRUCTURE_LIST_BUNDLE_ADD);
   } else if (type.ToString() == "string" || type.ToString() == "file") {
@@ -489,9 +449,7 @@ std::string CBodyGeneratorBase::GenBaseElementFree(
       type.ToString() == "array") {
     code = ReplaceAll(CB_STRUCTURE_BASE_USER_DEFINED_FREE, "<PREFIX>",
         GetHandlePrefix());
-
-    std::string name = GetFullNameFromType(type);
-    code = ReplaceAll(code, "<NAME>", name);
+    code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
     code = ReplaceAll(code, "<ELEMENT_NAME>", elm->GetID());
   } else if (type.ToString() == "bundle") {
     code = ReplaceAll(CB_STRUCTURE_BASE_BUNDLE_FREE, "<ELEMENT_NAME>",
index b8b40cf6379768e919558641cf5dc9c8a2c690f1..1787130ac00d9b6a157d43e31921d7c1086c9229 100644 (file)
@@ -464,7 +464,7 @@ std::string CGeneratorBase::GetHandlePrefix() {
   if (!HasNamespace())
     return prefix;
 
-  return prefix + "_" + GetFileNamespace() + "_";
+  return prefix + "_" + GetFileNamespace();
 }
 
 const std::map<std::string, std::unique_ptr<Structure>>&
index d24488dc6c3f5727b40a869417c8f1855681ee12..b986ec3583cc250af0e7d849ff5e67e5d476e9a8 100644 (file)
@@ -225,7 +225,7 @@ std::string CProxyBodyGen::GenDelegateParcelRead(const Interface& iface,
 // @see CB_INTERFACE_DELEGATE_BUNDLE_ARG_FREE
 // @see CB_INTERFACE_DELEGATE_STRING_ARG_FREE
 std::string CProxyBodyGen::GenDelegateArgsFree(const Interface& iface,
-    const Declaration& decl) {
+    const Declaration& decl, bool& has_free) {
   std::string code;
   for (auto& p : decl.GetParameters().GetParams()) {
     std::string param_free_code;
@@ -242,12 +242,15 @@ std::string CProxyBodyGen::GenDelegateArgsFree(const Interface& iface,
       std::string name = GetFullNameFromType(type, iface);
       param_free_code = ReplaceAll(param_free_code, "<NAME>", name);
       param_free_code = ReplaceAll(param_free_code, "<ARG>", p->GetID());
+      has_free = true;
     } else if (type.ToString() == "bundle") {
       param_free_code = ReplaceAll(CB_INTERFACE_DELEGATE_BUNDLE_ARG_FREE,
           "<ARG>", p->GetID());
+      has_free = true;
     } else if (type.ToString() == "string" || type.ToString() == "file") {
       param_free_code = ReplaceAll(CB_INTERFACE_DELEGATE_STRING_ARG_FREE,
           "<ARG>", p->GetID());
+      has_free = true;
     }
 
     code += param_free_code;
@@ -281,10 +284,13 @@ void CProxyBodyGen::GenInterfaceDelegateBase(std::ofstream& stream,
       GenDelegateArgsDecl(iface, decl));
   code = ReplaceAll(code, "<DELEGATE_PARCEL_READ>",
       GenDelegateParcelRead(iface, decl));
-  code = ReplaceAll(code, "<DELEGATE_ARGS_FREE>",
-      GenDelegateArgsFree(iface, decl));
+  bool has_free = false;
+  std::string delegate_args_free = GenDelegateArgsFree(iface, decl, has_free);
+  code = ReplaceAll(code, "<DELEGATE_ARGS_FREE>", delegate_args_free);
   code = ReplaceAll(code, "<DELEGATE_CALLBACK_ARGS>",
       GenDelegateCallbackArgs(decl));
+  code = ReplaceAll(code, "<GOTO_STATEMENT>",
+      has_free ? "out:" + NLine(1) : "");
 
   stream << SmartIndent(code);
 }
index 3c4885af678bbc87fcc61580552e1cd46b24f403..7f940f385a7e8f383ec745c03b5bcc01f1506bb8 100644 (file)
@@ -62,7 +62,7 @@ class CProxyBodyGen : public CBodyGeneratorBase {
   std::string GenDelegateParcelRead(const Interface& iface,
       const Declaration& decl);
   std::string GenDelegateArgsFree(const Interface& iface,
-      const Declaration& decl);
+      const Declaration& decl, bool& has_free);
   std::string GenDelegateCallbackArgs(const Declaration& decl);
 
   std::string GenMethodAsyncBase(const Interface& iface,
index c6c9091b36bf810b83e243b04d068eea4ce545e9..3d2bb867c91d2c6063a5fee586cf5a937ccf580f 100644 (file)
@@ -60,6 +60,7 @@ typedef struct <PREFIX>_<NAME>_<DELEGATE_NAME>_s {
  * <DELEGATE_PARCEL_READ> The implementation to read the arguments from the parcel.
  * <DELEGATE_ARGS_FREE> The implementation to release the allocated arguments.
  * <DELEGATE_CALLBACK_ARGS> The arguments of the delegate callback.
+ * <GOTO_STATEMENT> The statement label.
  */
 constexpr const char CB_INTERFACE_DELEGATE_BASE[] =
 R"__c_cb(
@@ -320,7 +321,7 @@ static void __<PREFIX>_<NAME>_<DELEGATE_NAME>_delegate_handler(GList **delegates
     }
   }
 
-out:
+<GOTO_STATEMENT>
   <DELEGATE_ARGS_FREE>
 }
 )__c_cb";
@@ -414,7 +415,7 @@ if (<ARG>)
  */
 constexpr const char CB_INTERFACE_DELEGATE_TABLE[] =
 R"__c_cb(
-static <PREFIX>_delegate_cb __<PREFIX>_<NAME>_delegate_table[] = {
+static rpc_port_proxy_delegate_cb __<PREFIX>_<NAME>_delegate_table[] = {
   <DELEGATE_HANDLERS>
 };
 )__c_cb";
index 0d571cd756ebd02cd2024f2d49c03b72ddab70d8..60e168a4192b28fde210cd280bc67f87a023ce5d 100644 (file)
@@ -58,10 +58,7 @@ void CStubBodyGen::GenThreadEnableDefinition(std::ofstream& stream) {
 
 // @see #CB_INTERFACE_METHOD_HANDLER_TYPE
 void CStubBodyGen::GenInterfaceMethodHandlerType(std::ofstream& stream) {
-  std::string code = ReplaceAll(CB_INTERFACE_METHOD_HANDLER_TYPE, "<PREFIX>",
-      GetHandlePrefix());
-
-  stream << SmartIndent(code);
+  stream << SmartIndent(CB_INTERFACE_METHOD_HANDLER_TYPE);
 }
 
 void CStubBodyGen::GenInterfaceEnums(std::ofstream& stream) {
@@ -479,10 +476,14 @@ std::string CStubBodyGen::GenMethodHandlerParcelWrite(const Interface& iface,
   if (decl.GetMethodType() != Declaration::MethodType::SYNC)
     return code;
 
+  std::string prefix = GetHandlePrefix();
+  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
+  code = ReplaceAll(CB_INTERFACE_METHOD_PARCEL_WRITE_PRE, "<UPPERCASE_PREFIX>",
+      prefix);
+
   std::string name = iface.GetID();
   std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-  code = ReplaceAll(CB_INTERFACE_METHOD_PARCEL_WRITE_PRE, "<UPPERCASE_NAME>",
-      name);
+  code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
 
   std::string parcel_write_code;
   for (auto& p : decl.GetParameters().GetParams()) {
index 4d253118e9c8dd8877e1b526ae34330b46ce2a55..877485a0a11ae477582f23b8b3d116f542ce47a5 100644 (file)
@@ -22,12 +22,9 @@ R"__c_cb(
 #define TIDL_THREAD_ENABLE 1
 )__c_cb";
 
-/**
- * <PREFIX> The prefix of the interface.
- */
 constexpr const char CB_INTERFACE_METHOD_HANDLER_TYPE[] =
 R"__c_cb(
-typedef int (*<PREFIX>_method_handler)(rpc_port_h port, rpc_port_parcel_h parcel, void *data);
+typedef int (*rpc_port_stub_method_handler)(rpc_port_h port, rpc_port_parcel_h parcel, void *data);
 )__c_cb";
 
 /**
@@ -819,6 +816,7 @@ if (context_->callback.<METHOD_NAME>)
 )__c_cb";
 
 /**
+ * <UPPERCASE_PREFIX> The uppercase prefix of the interface.
  * <UPPERCASE_NAME> The uppercase name of the interface.
  */
 constexpr const char CB_INTERFACE_METHOD_PARCEL_WRITE_PRE[] =
@@ -833,7 +831,7 @@ rpc_port_parcel_get_header(parcel_, &header_);
 rpc_port_parcel_header_set_tag(header_, TIDL_VERSION);
 rpc_port_parcel_header_set_seq_num(header_, seq_num_);
 
-rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_<UPPERCASE_NAME>_METHOD_RESULT_);
+rpc_port_parcel_write_int32(parcel_, <UPPERCASE_PREFIX>_<UPPERCASE_NAME>_METHOD_RESULT_);
 )__c_cb";
 
 constexpr const char CB_INTERFACE_METHOD_PARCEL_WRITE_POST[] =
@@ -1024,7 +1022,7 @@ static int __<PREFIX>_<NAME>_set_access_control(void)
   return ret;
 }
 
-int <PREFIX>_<NAME>_register(rpc_port_stub_<NAME>_callback_s *callback, void *user_data)
+int <PREFIX>_<NAME>_register(<PREFIX>_<NAME>_callback_s *callback, void *user_data)
 {
   int ret;