Fix C Generator 79/171679/7
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 6 Mar 2018 10:25:55 +0000 (19:25 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 7 Mar 2018 00:58:40 +0000 (09:58 +0900)
- Fixes wrong exceptions
- Adjusts coding style(Fix naming rules)
"rpc_port_create_<name>()" => "rpc_port_<name>_create()"

Change-Id: Iff0d6ca50a4eb1f3a58e2a143050de6ca00f8495
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/c_gen/c_body_gen_base.cc
idlc/c_gen/c_body_gen_base.h
idlc/c_gen/c_gen_base.cc
idlc/c_gen/c_header_gen_base.cc
idlc/c_gen/c_proxy_body_gen.cc
idlc/c_gen/c_proxy_header_gen.cc
idlc/c_gen/c_stub_body_gen.cc
idlc/c_gen/c_stub_header_gen.cc

index 3eb5f18..0c020bd 100644 (file)
@@ -148,7 +148,7 @@ void CBodyGeneratorBase::GenStructureParcelDeserializer(std::ofstream& stream,
 void CBodyGeneratorBase::GenStructureConstructor(std::ofstream& stream,
                                                  const Structure& st) {
   const char block[] =
-      "int rpc_port_create_##(rpc_port_##_h *h)\n" \
+      "int rpc_port_##_create(rpc_port_##_h *h)\n" \
       "{\n" \
       "    struct ##_s *handle;\n" \
       "\n" \
@@ -178,7 +178,7 @@ void CBodyGeneratorBase::GenStructureConstructor(std::ofstream& stream,
 void CBodyGeneratorBase::GenStructureDestructor(std::ofstream& stream,
                                                 const Structure& st) {
   const char block[] =
-      "int rpc_port_destroy_##(rpc_port_##_h h)\n" \
+      "int rpc_port_##_destroy(rpc_port_##_h h)\n" \
       "{\n" \
       "    if (!h) {\n" \
       "        LOGE(\"Invalid parameter\");\n" \
@@ -223,15 +223,15 @@ void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream,
     stream << NLine(1);
     stream << SmartIndent(GenTemplateString(block,
           [&]()->std::string {
+            return st.GetID();
+          },
+          [&]()->std::string {
             if (i->GetType().ToString() == "list" ||
                 i->GetType().ToString() == "array")
               return "add";
             return "set";
           },
           [&]()->std::string {
-            return st.GetID();
-          },
-          [&]()->std::string {
             return i->GetID();
           },
           [&]()->std::string {
@@ -288,7 +288,7 @@ void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream,
 void CBodyGeneratorBase::GenStructureGetter(std::ofstream& stream,
                                             const Structure& st) {
   const char block[] =
-      "int rpc_port_get_$$_$$(rpc_port_$$_h h, $$$$)\n" \
+      "int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$)\n" \
       "{\n" \
       "    if (!h || $$) {\n" \
       "        LOGE(\"Invalid parameter\");\n" \
@@ -342,7 +342,7 @@ void CBodyGeneratorBase::GenStructureGetter(std::ofstream& stream,
 void CBodyGeneratorBase::GenStructureIterator(std::ofstream& stream,
                                               const Structure& st) {
   const char block[] =
-      "int rpc_port_foreach_$$_$$(rpc_port_$$_h h, " \
+      "int rpc_port_$$_foreach_$$(rpc_port_$$_h h, " \
       "void (*callback)($$$$, void *user_data), void *user_data)\n" \
       "{\n" \
       "    if (!h || !callback) {\n" \
@@ -396,7 +396,7 @@ void CBodyGeneratorBase::GenStructureIterator(std::ofstream& stream,
 void CBodyGeneratorBase::GenStructureCloner(std::ofstream& stream,
                                             const Structure& st) {
   const char block[] =
-      "int rpc_port_clone_##(rpc_port_##_h h, rpc_port_##_h *clone)\n" \
+      "int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone)\n" \
       "{\n" \
       "    rpc_port_##_h handle = NULL;\n" \
       "\n" \
@@ -405,7 +405,7 @@ void CBodyGeneratorBase::GenStructureCloner(std::ofstream& stream,
       "        return -1;\n" \
       "    }\n" \
       "\n" \
-      "    rpc_port_create_##(&handle);\n" \
+      "    rpc_port_##_create(&handle);\n" \
       "    if (!handle) {\n" \
       "        LOGE(\"Failed to create ## handle\");\n" \
       "        return -1;\n" \
@@ -423,7 +423,7 @@ void CBodyGeneratorBase::GenStructureCloner(std::ofstream& stream,
           std::string str;
           for (auto& i : st.GetElements().GetElms()) {
             str += NLine(1);
-            str += GetClonerString(i->GetID(), i->GetType());
+            str += GetClonerString(i->GetID(), i->GetType(), st);
           }
           return str;
         }
@@ -871,7 +871,7 @@ std::string CBodyGeneratorBase::GetGetterString(const std::string& id,
       type.ToString() == "bundle") {
     str += GenTemplateString(if_statement_with_braces,
         [&]()->std::string {
-          return "!" + id;
+          return "*" + id + " == NULL";
         },
         [&]()->std::string {
           std::string s;
@@ -927,7 +927,8 @@ std::string CBodyGeneratorBase::GetIteratorString(const std::string& id,
 }
 
 std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
-                                                const BaseType& type) {
+                                                const BaseType& type,
+                                                const Structure& st) {
   std::string str;
   const char if_statement_with_braces[] =
       "if ($$) {\n" \
@@ -942,7 +943,8 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
       "\n" \
       "        if (!value) {\n" \
       "            LOGE(\"Error: value is NULL\");\n" \
-      "            break;\n" \
+      "            rpc_port_$$_destroy(handle);\n"
+      "            return -1;\n" \
       "        }\n" \
       "\n" \
       "        $$" \
@@ -969,6 +971,8 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
                 std::string ss;
                 ss += "LOGE(\"Failed to duplicate h->" + id + "\");" +
                     NLine(1);
+                ss += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+                    NLine(1);
                 ss += "return -1;" + NLine(1);
                 return ss;
               }
@@ -989,6 +993,9 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
           return GetParcelParamTypeString(*type.GetMetaType());
         },
         [&]()->std::string {
+          return st.GetID();
+        },
+        [&]()->std::string {
           std::string s;
           if (type.GetMetaType()->IsUserDefinedType() ||
               type.GetMetaType()->ToString() == "list" ||
@@ -1005,6 +1012,8 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
                 std::string ss;
                 ss += "LOGE(\"Failed to duplicate value\");" +
                     NLine(1);
+                ss += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+                      NLine(1);
                 ss += "return -1;" + NLine(1);
                 return ss;
               }
@@ -1018,13 +1027,15 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
                 [&]()->std::string {
                   std::string tmp;
                   tmp += "LOGE(\"Out of memory\");" + NLine(1);
+                  tmp += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+                      NLine(1);
                   tmp += "return -1;" + NLine(1);
                   return tmp;
                 }
                 );
             s += NLine(1);
             s += GetSetterString(*type.GetMetaType(),
-                "*new_value", "value");
+                "*new_value", "*value");
           }
           s += NLine(1);
           return s;
@@ -1051,8 +1062,8 @@ std::string CBodyGeneratorBase::GetDestructorString(const BaseType& type,
   if (type.IsUserDefinedType() ||
       type.ToString() == "list" ||
       type.ToString() == "array") {
-    str += "rpc_port_destroy_" + GetFullNameFromType(type) +
-        "(" + value + ");" + NLine(1);
+    str += "rpc_port_" + GetFullNameFromType(type) +
+        "_destroy(" + value + ");" + NLine(1);
   } else if (type.ToString() == "bundle") {
     str += "bundle_free(" + value + ");" + NLine(1);
   } else if (type.ToString() == "string" || container_value) {
@@ -1065,8 +1076,8 @@ std::string CBodyGeneratorBase::GetDestructorString(const BaseType& type,
 std::string CBodyGeneratorBase::GetConstructorString(const BaseType& type,
                                                      const std::string& value) {
   std::string str;
-  str += "rpc_port_create_" + GetFullNameFromType(type) +
-      "(&" + value + ");" + NLine(1);
+  str += "rpc_port_" + GetFullNameFromType(type) +
+      "_create(&" + value + ");" + NLine(1);
   return str;
 }
 
@@ -1078,8 +1089,8 @@ std::string CBodyGeneratorBase::GetSetterString(const BaseType& type,
   if (type.IsUserDefinedType() ||
       type.ToString() == "list" ||
       type.ToString() == "array") {
-    str += "rpc_port_clone_" + GetFullNameFromType(type) +
-        "(" + rvalue + ", &" + lvalue +");" + NLine(1);
+    str += "rpc_port_" + GetFullNameFromType(type) +
+        "_clone(" + rvalue + ", &" + lvalue +");" + NLine(1);
   } else if (type.ToString() == "string")  {
     str += lvalue + " = strdup(" + rvalue + ");" + NLine(1);
   } else if (type.ToString() == "bundle") {
index 55d6b0f..985419e 100644 (file)
@@ -71,7 +71,8 @@ class CBodyGeneratorBase : public CGeneratorBase {
   std::string GetSetterString(const std::string& id, const BaseType& type);
   std::string GetGetterString(const std::string& id, const BaseType& type);
   std::string GetIteratorString(const std::string& id, const BaseType& type);
-  std::string GetClonerString(const std::string& id, const BaseType& type);
+  std::string GetClonerString(const std::string& id, const BaseType& type,
+                              const Structure& st);
   std::string GetSetterString(const BaseType& type, const std::string& lvalue,
                               const std::string& rvalue);
   std::string GetSetterString(const std::string& lvalue,
index a0f9f15..839dc97 100644 (file)
@@ -121,6 +121,9 @@ std::string CGeneratorBase::GetReturnTypeString(const BaseType& type) {
   if (type.ToString() == "string")
     return "char *";
 
+  if (type.ToString() == "bundle")
+    return "bundle *";
+
   return type.ToString() + " ";
 }
 
index 47b6c26..55cae34 100644 (file)
@@ -105,7 +105,7 @@ void CHeaderGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
 
 void CHeaderGeneratorBase::GenStructureConstructor(std::ofstream& stream,
                                                    const Structure& st) {
-  const char format[] = "int rpc_port_create_$$(rpc_port_$$_h *h);\n";
+  const char format[] = "int rpc_port_$$_create(rpc_port_$$_h *h);\n";
 
   stream << NLine(1);
   GenTemplate(format, stream,
@@ -120,7 +120,7 @@ void CHeaderGeneratorBase::GenStructureConstructor(std::ofstream& stream,
 
 void CHeaderGeneratorBase::GenStructureDestructor(std::ofstream& stream,
                                                   const Structure& st) {
-  const char format[] = "int rpc_port_destroy_$$(rpc_port_$$_h h);\n";
+  const char format[] = "int rpc_port_$$_destroy(rpc_port_$$_h h);\n";
 
   stream << NLine(1);
   GenTemplate(format, stream,
@@ -141,15 +141,15 @@ void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream,
     stream << NLine(1);
     GenTemplate(format, stream,
           [&]()->std::string {
+            return st.GetID();
+          },
+          [&]()->std::string {
             if (i->GetType().ToString() == "list" ||
                 i->GetType().ToString() == "array")
               return "add";
             return "set";
           },
           [&]()->std::string {
-            return st.GetID();
-          },
-          [&]()->std::string {
             return i->GetID();
           },
           [&]()->std::string {
@@ -183,7 +183,7 @@ void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream,
 
 void CHeaderGeneratorBase::GenStructureGetter(std::ofstream& stream,
                                               const Structure& st) {
-  const char format[] = "int rpc_port_get_$$_$$(rpc_port_$$_h h, $$$$);\n";
+  const char format[] = "int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$);\n";
 
   for (auto& i : st.GetElements().GetElms()) {
     if (i->GetType().ToString() == "list" ||
@@ -218,7 +218,7 @@ void CHeaderGeneratorBase::GenStructureGetter(std::ofstream& stream,
 void CHeaderGeneratorBase::GenStructureIterator(std::ofstream& stream,
                                                 const Structure& st) {
   const char format[] =
-      "int rpc_port_foreach_$$_$$(rpc_port_$$_h h, " \
+      "int rpc_port_$$_foreach_$$(rpc_port_$$_h h, " \
       "void (*callback)($$$$, void *user_data), void *user_data);\n";
 
   for (auto& i : st.GetElements().GetElms()) {
@@ -256,7 +256,7 @@ void CHeaderGeneratorBase::GenStructureIterator(std::ofstream& stream,
 void CHeaderGeneratorBase::GenStructureCloner(std::ofstream& stream,
                                               const Structure& st) {
   const char format[] =
-      "int rpc_port_clone_$$(rpc_port_$$_h h, rpc_port_$$_h *clone);\n";
+      "int rpc_port_$$_clone(rpc_port_$$_h h, rpc_port_$$_h *clone);\n";
 
   stream << NLine(1);
   GenTemplate(format, stream,
index 74cbe0b..9e85d3d 100644 (file)
@@ -114,7 +114,7 @@ void CProxyBodyGen::GenInterfaceDelegatorDeclaration(
       "    ## callback;\n" \
       "};\n";
   stream << NLine(1);
-  stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+  stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
 }
 
 void CProxyBodyGen::GenInterfaceDelegatorSerializer(
@@ -133,7 +133,7 @@ void CProxyBodyGen::GenInterfaceDelegatorSerializer(
       "    rpc_port_parcel_write_int32(parcel, handle->seq_id);\n" \
       "}\n";
   stream << NLine(1);
-  stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+  stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
 }
 
 void CProxyBodyGen::GenInterfaceDelegatorDeserializer(
@@ -152,7 +152,7 @@ void CProxyBodyGen::GenInterfaceDelegatorDeserializer(
       "    rpc_port_parcel_read_int32(parcel, &handle->seq_id);\n" \
       "}\n";
   stream << NLine(1);
-  stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+  stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
 }
 
 void CProxyBodyGen::GenInterfaceDelegatorConstructor(
@@ -171,16 +171,20 @@ void CProxyBodyGen::GenInterfaceDelegatorConstructor(
       "\n" \
       "    handle->parcelable.to = __##_to;\n" \
       "    handle->parcelable.from= __##_from;\n" \
-      "    handle->id = $$_DELEGATE_##;\n" \
+      "    handle->id = $$_DELEGATE_$$;\n" \
       "    handle->seq_id = seq_num++;\n" \
       "    handle->callback = callback;\n" \
       "\n" \
       "    return handle;\n" \
       "}\n";
   stream << NLine(1);
-  stream << SmartIndent(GenTemplateString(ReplaceAll(block, "##", decl.GetID()),
+  stream << SmartIndent(GenTemplateString(
+        ReplaceAll(block, "##", id + "_" + decl.GetID()),
         [&]()->std::string {
           return id;
+        },
+        [&]()->std::string {
+          return decl.GetID();
         }
         )
       );
@@ -190,7 +194,7 @@ void CProxyBodyGen::GenInterfaceDelegatorInvoker(
     std::ofstream& stream, const std::string& id, const Declaration& decl) {
   const char parcel[] = "$$(parcel, $$);\n";
   const char block[] =
-      "static void __$$_delegate_##(GList *list, rpc_port_parcel_h parcel, int seq_id)\n" \
+      "static void __$$_delegate_$$(GList *list, rpc_port_parcel_h parcel, int seq_id)\n" \
       "{\n" \
       "$$" \
       "    do {\n" \
@@ -210,11 +214,15 @@ void CProxyBodyGen::GenInterfaceDelegatorInvoker(
       "$$" \
       "}\n";
   stream << NLine(1);
-  stream << SmartIndent(GenTemplateString(ReplaceAll(block, "##", decl.GetID()),
+  stream << SmartIndent(GenTemplateString(
+        ReplaceAll(block, "##", id + "_" + decl.GetID()),
         [&]()->std::string {
           return id;
         },
         [&]()->std::string {
+          return decl.GetID();
+        },
+        [&]()->std::string {
           std::string str;
           int cnt = 0;
           for (auto& i : decl.GetParameters().GetParams()) {
@@ -518,8 +526,9 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
             for (auto& p : i->GetParameters().GetParams()) {
               str += ", ";
               if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
-                str += p->GetParameterType().GetBaseType().ToString() + " " +
-                     p->GetID();
+                str += inf.GetID() + "_" +
+                    p->GetParameterType().GetBaseType().ToString() +
+                    " " + p->GetID();
               } else {
                 str += ConvertTypeToString(p->GetParameterType().GetDirection(),
                     p->GetParameterType().GetBaseType()) + p->GetID();
@@ -566,7 +575,7 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
                 continue;
               if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
                 str += GenTemplateString(ReplaceAll(delegate_block,
-                    "##", p->GetParameterType().GetBaseType().ToString()),
+                    "##", inf.GetID() + "_" + p->GetParameterType().GetBaseType().ToString()),
                     [&]()->std::string {
                       return p->GetID();
                     }
index f30dca0..582d648 100644 (file)
@@ -65,14 +65,14 @@ void CProxyHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
 void CProxyHeaderGen::GenInterfaceDelegator(std::ofstream& stream,
                                             const std::string& id,
                                             const Declaration& decl) {
-  const char format[] = "typedef $$ (*$$)($$);\n";
+  const char format[] = "typedef $$(*$$)($$);\n";
   stream << NLine(1);
   stream << GenTemplateString(format,
       [&]()->std::string {
         return GetReturnTypeString(decl.GetType());
       },
       [&]()->std::string {
-        return decl.GetID();
+        return id + "_" + decl.GetID();
       },
       [&]()->std::string {
         std::string str;
@@ -106,7 +106,7 @@ void CProxyHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
 void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
                                           const Interface& inf) {
   const char format[] =
-      "$$ rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$);\n";
+      "$$rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$);\n";
   for (auto& i : inf.GetDeclarations().GetDecls()) {
     if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
       continue;
@@ -123,8 +123,9 @@ void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
           for (auto& p : i->GetParameters().GetParams()) {
             str += ", ";
             if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
-              str += p->GetParameterType().GetBaseType().ToString() + " " +
-                  p->GetID();
+              str += inf.GetID() + "_" +
+                  p->GetParameterType().GetBaseType().ToString() +
+                  " " + p->GetID();
             } else {
               str += ConvertTypeToString(p->GetParameterType().GetDirection(),
                   p->GetParameterType().GetBaseType()) + p->GetID();
index d178f98..521341e 100644 (file)
@@ -328,7 +328,7 @@ void CStubBodyGen::GenInterfaceGlobalVariables(std::ofstream& stream,
 std::string CStubBodyGen::GetMethodString(const Interface& inf,
                                           const Declaration& decl) {
   std::string str;
-  const char port_setter[] = "rpc_port_set_$$_port($$, port);\n";
+  const char port_setter[] = "rpc_port_$$_set_port($$, port);\n";
   const char parcel[] = "$$(parcel, $$);\n";
   const char do_while_block[] =
       "do {\n" \
@@ -342,8 +342,14 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf,
       "} while (0);\n";
   int cnt = 0;
   for (auto& i : decl.GetParameters().GetParams()) {
-    str += GetParcelParamTypeString(i->GetParameterType().GetBaseType()) +
-        i->GetID() + ";" + NLine(1);
+    if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
+      str += "rpc_port_" + inf.GetID() + "_" +
+          i->GetParameterType().GetBaseType().ToString() + "_h " +
+          i->GetID() + ";" + NLine(1);
+    } else {
+      str += GetReturnTypeString(i->GetParameterType().GetBaseType()) +
+          i->GetID() + ";" + NLine(1);
+    }
     if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN)
       cnt++;
   }
@@ -356,17 +362,22 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf,
     if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
         i->GetParameterType().GetBaseType().ToString() == "list" ||
         i->GetParameterType().GetBaseType().ToString() == "array") {
-      str += GetConstructorString(i->GetParameterType().GetBaseType(),
-          i->GetID());
       if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
+        str += "rpc_port_" + inf.GetID() + "_" +
+            i->GetParameterType().GetBaseType().ToString() +
+            "_create(&" + i->GetID() + ");" + NLine(1);
         str += GenTemplateString(port_setter,
             [&]()->std::string {
-              return i->GetParameterType().GetBaseType().ToString();
+              return inf.GetID() + "_" +
+                  i->GetParameterType().GetBaseType().ToString();
             },
             [&]()->std::string {
               return i->GetID();
             }
             );
+      } else {
+         str += GetConstructorString(i->GetParameterType().GetBaseType(),
+          i->GetID());
       }
     }
 
@@ -446,8 +457,14 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf,
     }
 
   for (auto& i: decl.GetParameters().GetParams()) {
-    str += GetDestructorString(i->GetParameterType().GetBaseType(),
-        i->GetID());
+    if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
+      str += "rpc_port_" + inf.GetID() + "_" +
+          i->GetParameterType().GetBaseType().ToString() +
+          "_destroy(" + i->GetID() + ");" + NLine(1);
+    } else {
+      str += GetDestructorString(i->GetParameterType().GetBaseType(),
+          i->GetID());
+    }
   }
 
   return str;
@@ -510,7 +527,7 @@ void CStubBodyGen::GenInterfaceDelegatorDeclaration(std::ofstream& stream,
   stream << NLine(1);
   stream << SmartIndent(GenTemplateString(block,
         [&]()->std::string {
-          return decl.GetID();
+          return id + "_" + decl.GetID();
         }
         )
       );
@@ -520,7 +537,7 @@ void CStubBodyGen::GenInterfaceDelegatorConstructor(std::ofstream& stream,
                                                     const std::string& id,
                                                     const Declaration& decl) {
   const char block[] =
-      "int rpc_port_create_##(rpc_port_##_h *h)\n" \
+      "int rpc_port_##_create(rpc_port_##_h *h)\n" \
       "{\n" \
       "    struct ##_s *handle;\n" \
       "    static int seq_num;\n" \
@@ -538,7 +555,7 @@ void CStubBodyGen::GenInterfaceDelegatorConstructor(std::ofstream& stream,
       "\n" \
       "    handle->parcelable.to = __##_to;\n" \
       "    handle->parcelable.from = __##_from;\n" \
-      "    handle->id = $$_DELEGATE_##;\n" \
+      "    handle->id = $$_DELEGATE_$$;\n" \
       "    handle->seq_id = seq_num++;\n" \
       "\n" \
       "    *h = handle;\n" \
@@ -548,9 +565,12 @@ void CStubBodyGen::GenInterfaceDelegatorConstructor(std::ofstream& stream,
 
   stream << NLine(1);
   stream << SmartIndent(GenTemplateString(
-        ReplaceAll(block, "##", decl.GetID()),
+        ReplaceAll(block, "##", id + "_" + decl.GetID()),
         [&]()->std::string {
           return id;
+        },
+        [&]()->std::string {
+          return decl.GetID();
         }
         )
       );
@@ -560,7 +580,7 @@ void CStubBodyGen::GenInterfaceDelegatorDestructor(std::ofstream& stream,
                                                    const std::string& id,
                                                    const Declaration& decl) {
   const char block[] =
-      "int rpc_port_destroy_##(rpc_port_##_h h)\n" \
+      "int rpc_port_##_destroy(rpc_port_##_h h)\n" \
       "{\n" \
       "    if (!h) {\n" \
       "        LOGE(\"Invalid parameter\");\n" \
@@ -573,7 +593,7 @@ void CStubBodyGen::GenInterfaceDelegatorDestructor(std::ofstream& stream,
       "}\n";
 
   stream << NLine(1);
-  stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+  stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
 }
 
 void CStubBodyGen::GenInterfaceDelegatorSerializer(std::ofstream& stream,
@@ -594,7 +614,7 @@ void CStubBodyGen::GenInterfaceDelegatorSerializer(std::ofstream& stream,
       "}\n";
 
     stream << NLine(1);
-    stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+    stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
 }
 
 void CStubBodyGen::GenInterfaceDelegatorDeserializer(std::ofstream& stream,
@@ -615,14 +635,14 @@ void CStubBodyGen::GenInterfaceDelegatorDeserializer(std::ofstream& stream,
       "}\n";
 
   stream << NLine(1);
-  stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+  stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
 }
 
 void CStubBodyGen::GenInterfaceDelegatorCloner(std::ofstream& stream,
                                                const std::string& id,
                                                const Declaration& decl) {
   const char block[] =
-      "int rpc_port_clone_##(rpc_port_##_h h, rpc_port_##_h *clone)\n" \
+      "int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone)\n" \
       "{\n" \
       "    rpc_port_##_h handle;\n" \
       "\n" \
@@ -648,7 +668,7 @@ void CStubBodyGen::GenInterfaceDelegatorCloner(std::ofstream& stream,
       "}\n";
 
   stream << NLine(1);
-  stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+  stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
 }
 
 void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream,
@@ -656,7 +676,7 @@ void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream,
                                                 const Declaration& decl) {
   const char parcel[] = "$$(parcel, $$);\n";
   const char block[] =
-      "int rpc_port_invoke_$$($$)\n" \
+      "int rpc_port_$$_invoke($$)\n" \
       "{\n" \
       "    rpc_port_parcel_h parcel = NULL;\n" \
       "\n" \
@@ -688,11 +708,11 @@ void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream,
   stream << NLine(1);
   stream << SmartIndent(GenTemplateString(block,
         [&]()->std::string {
-          return decl.GetID();
+          return id + "_" + decl.GetID();
         },
         [&]()->std::string {
           std::string str;
-          str += "rpc_port_" + decl.GetID() + "_h h";
+          str += "rpc_port_" + id + "_" + decl.GetID() + "_h h";
           for (auto& i : decl.GetParameters().GetParams()) {
             str += ", ";
             str += GetParamTypeString(i->GetParameterType().GetDirection(),
@@ -712,7 +732,7 @@ void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream,
             str += GenTemplateString(parcel,
                 [&]()->std::string {
                   return GetParcelWriteFunctionString(
-                      i->GetParameterType().GetBaseType());
+                      i->GetParameterType().GetBaseType(), true);
                 },
                 [&]()->std::string {
                   if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
@@ -733,7 +753,7 @@ void CStubBodyGen::GenInterfaceDelegatorPortSetter(std::ofstream& stream,
                                                    const std::string& id,
                                                    const Declaration& decl) {
   const char block[] =
-      "int rpc_port_set_##_port(rpc_port_##_h h, rpc_port_h port)\n" \
+      "int rpc_port_##_set_port(rpc_port_##_h h, rpc_port_h port)\n" \
       "{\n" \
       "    if (!h || !port) {\n" \
       "        LOGE(\"Invalid parameter\");\n" \
@@ -746,7 +766,7 @@ void CStubBodyGen::GenInterfaceDelegatorPortSetter(std::ofstream& stream,
       "}\n";
 
   stream << NLine(1);
-  stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+  stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
 }
 
 void CStubBodyGen::GenInterfaceContext(std::ofstream& stream,
index d13b8f1..ca8847b 100644 (file)
@@ -55,7 +55,7 @@ void CStubHeaderGen::GenInterface(std::ofstream& stream,
 
 void CStubHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
                                              const Interface& inf) {
-  const char callback[] = "$$ (*$$)(rpc_port_stub_$$_context_h context, $$void *user_data);\n";
+  const char callback[] = "$$(*$$)(rpc_port_stub_$$_context_h context, $$void *user_data);\n";
   const char block[] =
       "typedef struct {\n" \
       "    void (*create)(rpc_port_stub_##_context_h context, void *user_data);\n" \
@@ -83,7 +83,8 @@ void CStubHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
                   std::string s;
                   for (auto& p : i->GetParameters().GetParams()) {
                     if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
-                      s += GetParcelParamTypeString(p->GetParameterType().GetBaseType()) +
+                      s += "rpc_port_" + inf.GetID() + "_" +
+                          p->GetParameterType().GetBaseType().ToString() + "_h " +
                           p->GetID();
                     } else {
                       s += GetParamTypeString(p->GetParameterType().GetDirection(),
@@ -162,31 +163,31 @@ void CStubHeaderGen::GenInterfaceDelegatorDeclaration(
     std::ofstream& stream, const std::string& id, const Declaration& decl) {
   const char format[] = "typedef struct ##_s *rpc_port_##_h;\n";
   stream << NLine(1);
-  stream << ReplaceAll(format, "##", decl.GetID());
+  stream << ReplaceAll(format, "##", id + "_" + decl.GetID());
 }
 
 void CStubHeaderGen::GenInterfaceDelegatorDestructor(
     std::ofstream& stream, const std::string& id, const Declaration& decl) {
   const char format[] =
-      "int rpc_port_destroy_##(rpc_port_##_h h);\n";
+      "int rpc_port_##_destroy(rpc_port_##_h h);\n";
   stream << NLine(1);
-  stream << ReplaceAll(format, "##", decl.GetID());
+  stream << ReplaceAll(format, "##", id + "_" + decl.GetID());
 }
 
 void CStubHeaderGen::GenInterfaceDelegatorCloner(
     std::ofstream& stream, const std::string& id, const Declaration& decl) {
   const char format[] =
-      "int rpc_port_clone_##(rpc_port_##_h h, rpc_port_##_h *clone);\n";
+      "int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone);\n";
   stream << NLine(1);
-  stream << ReplaceAll(format, "##", decl.GetID());
+  stream << ReplaceAll(format, "##", id + "_" + decl.GetID());
 }
 
 void CStubHeaderGen::GenInterfaceDelegatorInvoker(
     std::ofstream& stream, const std::string& id, const Declaration& decl) {
   const char format[] =
-      "int rpc_port_invoke_##(rpc_port_##_h h$$);\n";
+      "int rpc_port_##_invoke(rpc_port_##_h h$$);\n";
   stream << NLine(1);
-  stream << GenTemplateString(ReplaceAll(format, "##", decl.GetID()),
+  stream << GenTemplateString(ReplaceAll(format, "##", id + "_" + decl.GetID()),
       [&]()->std::string {
         std::string str;
         for (auto& i : decl.GetParameters().GetParams()) {