From: Hwankyu Jhun Date: Wed, 28 Feb 2018 07:34:54 +0000 (+0900) Subject: Fix C Generator X-Git-Tag: accepted/tizen/unified/20180302.061550~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5457484c9fa54664a60f987f64b8c7652e7809ac;p=platform%2Fcore%2Fappfw%2Ftidl.git Fix C Generator - Adjusts coding style e.g. "void* value;" => "void *value;" Change-Id: I53288bdb591d5ea9296f276cb60eb5b104dad440 Signed-off-by: Hwankyu Jhun --- diff --git a/idlc/c_gen/c_body_gen_base.cc b/idlc/c_gen/c_body_gen_base.cc index c47cbd7..3eb5f18 100644 --- a/idlc/c_gen/c_body_gen_base.cc +++ b/idlc/c_gen/c_body_gen_base.cc @@ -73,7 +73,6 @@ void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream, stream << NLine(1); stream << st.GetComments(); - stream << SmartIndent(GenTemplateString(block, [&]()->std::string { return st.GetID(); @@ -82,8 +81,7 @@ void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream, std::string str; for (auto& i : st.GetElements().GetElms()) { str += GetStringFromElementType(i->GetType()) + - " " + i->GetID() + ";"; - str += NLine(1); + i->GetID() + ";" + NLine(1); } return str; } @@ -94,7 +92,7 @@ void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream, void CBodyGeneratorBase::GenStructureParcelSerializer(std::ofstream& stream, const Structure& st) { const char block[] = - "static void __##_to(rpc_port_parcel_h parcel, void* data)\n" \ + "static void __##_to(rpc_port_parcel_h parcel, void *data)\n" \ "{\n" \ " rpc_port_##_h h = data;\n" \ "\n" \ @@ -122,7 +120,7 @@ void CBodyGeneratorBase::GenStructureParcelSerializer(std::ofstream& stream, void CBodyGeneratorBase::GenStructureParcelDeserializer(std::ofstream& stream, const Structure& st) { const char block[] = - "static void __##_from(rpc_port_parcel_h parcel, void* data)\n" \ + "static void __##_from(rpc_port_parcel_h parcel, void *data)\n" \ "{\n" \ " rpc_port_##_h h = data;\n" \ "\n" @@ -150,9 +148,9 @@ 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" \ + " struct ##_s *handle;\n" \ "\n" \ " if (!h) {\n" \ " LOGE(\"Invalid parameter\");\n" \ @@ -210,7 +208,7 @@ void CBodyGeneratorBase::GenStructureDestructor(std::ofstream& stream, void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream, const Structure& st) { const char block[] = - "int rpc_port_$$_$$_$$(rpc_port_$$_h h, $$ $$)\n" \ + "int rpc_port_$$_$$_$$(rpc_port_$$_h h, $$$$)\n" \ "{\n" \ " if ($$) {\n" \ " LOGE(\"Invalid parameter\");\n" \ @@ -290,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" \ @@ -345,7 +343,7 @@ void CBodyGeneratorBase::GenStructureIterator(std::ofstream& stream, const Structure& st) { const char block[] = "int rpc_port_foreach_$$_$$(rpc_port_$$_h h, " \ - "void (*callback)($$ $$, void* user_data), void* user_data)\n" \ + "void (*callback)($$$$, void *user_data), void *user_data)\n" \ "{\n" \ " if (!h || !callback) {\n" \ " LOGE(\"Invalid parameter\");\n" \ @@ -398,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" \ @@ -459,16 +457,16 @@ std::string CBodyGeneratorBase::GetParcelTypeString(const BaseType& type, std::string CBodyGeneratorBase::GetStringFromElementType(const BaseType& type) { if (type.IsUserDefinedType()) - return "rpc_port_" + type.ToString() + "_h"; + return "rpc_port_" + type.ToString() + "_h "; if (type.ToString() == "list" || type.ToString() == "array") - return "GList*"; + return "GList *"; if (type.ToString() == "string") - return "char*"; + return "char *"; if (type.ToString() == "bundle") - return "bundle*"; + return "bundle *"; - return type.ToString(); + return type.ToString() + " "; } std::string CBodyGeneratorBase::GetParcelWriteFunctionString( @@ -487,9 +485,9 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, const char parcel[] = "$$(parcel, $$);\n"; const char do_while[] = "do {\n" \ - " GList* iter = $$;\n" + " GList *iter = $$;\n" " while (iter) {\n" \ - " $$ value = iter->data;\n" \ + " $$value = iter->data;\n" \ "\n" \ " iter = g_list_next(iter);\n" \ " if (!value) {\n" \ @@ -508,7 +506,8 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, [&]()->std::string { if (type.IsUserDefinedType()) return "&h->" + id + ", h->" + id; - if (type.ToString() == "list") + if (type.ToString() == "list" || + type.ToString() == "array") return "g_list_length(h->" + id + ")"; return "h->" + id; } @@ -571,7 +570,7 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id, "\n" \ " $$" \ " for (int i = 0; i < len; i++) {\n" \ - " $$ value = NULL;\n" \ + " $$value = NULL;\n" \ "\n" \ " $$" \ " $$ = g_list_append($$, value);\n" \ @@ -688,9 +687,9 @@ std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id, " $$"; const char do_while[] = "do {\n" \ - " GList* iter = $$;\n" \ + " GList *iter = $$;\n" \ " while (iter) {\n" \ - " $$ value = iter->data;\n" \ + " $$value = iter->data;\n" \ " $$" \ " iter = g_list_next(iter);\n" \ " }\n" \ @@ -749,7 +748,7 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, "}\n"; const char do_while[] = "do {\n" \ - " $$ value;\n" \ + " $$value;\n" \ "\n" \ " value = calloc(1, sizeof(*value));\n" \ " $$" \ @@ -891,9 +890,9 @@ std::string CBodyGeneratorBase::GetIteratorString(const std::string& id, std::string str; const char iterator[] = "do {\n" \ - " GList* iter = $$;\n" \ + " GList *iter = $$;\n" \ " while (iter) {\n" \ - " $$ value = iter->data;\n" \ + " $$value = iter->data;\n" \ "\n" \ " iter = g_list_next(iter);\n" \ " if (!value) {\n" \ @@ -936,10 +935,10 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, "}\n"; const char do_while[] = "do {\n" \ - " GList* iter = $$;\n" \ + " GList *iter = $$;\n" \ " while (iter) {\n" \ - " $$ new_value;\n" \ - " $$ value = iter->data;\n" \ + " $$new_value;\n" \ + " $$value = iter->data;\n" \ "\n" \ " if (!value) {\n" \ " LOGE(\"Error: value is NULL\");\n" \ diff --git a/idlc/c_gen/c_gen_base.cc b/idlc/c_gen/c_gen_base.cc index ce0bce9..055519b 100644 --- a/idlc/c_gen/c_gen_base.cc +++ b/idlc/c_gen/c_gen_base.cc @@ -52,37 +52,37 @@ std::string CGeneratorBase::ConvertTypeToString( ParameterType::Direction direction, const BaseType& type) { if (type.IsUserDefinedType()) { if (direction == ParameterType::Direction::IN) - return "rpc_port_" + type.ToString() + "_h"; + return "rpc_port_" + type.ToString() + "_h "; else - return "rpc_port_" + type.ToString() + "_h" + "*"; + return "rpc_port_" + type.ToString() + "_h *"; } if (type.ToString() == "list" || type.ToString() == "array") { if (direction == ParameterType::Direction::IN) - return "GList*"; + return "GList *"; else - return "GList**"; + return "GList **"; } if (type.ToString() == "string") { if (direction == ParameterType::Direction::IN) - return "const char*"; + return "const char *"; else - return "char**"; + return "char **"; } if (type.ToString() == "bundle") { if (direction == ParameterType::Direction::IN) - return "bundle*"; + return "bundle *"; else - return "bundle**"; + return "bundle **"; } if (direction == ParameterType::Direction::IN) - return type.ToString(); + return type.ToString() + " "; - return type.ToString() + "*"; + return type.ToString() + " *"; } std::string CGeneratorBase::GetFullNameFromType(const BaseType& type) { @@ -98,30 +98,30 @@ std::string CGeneratorBase::GetFullNameFromType(const BaseType& type) { std::string CGeneratorBase::GetParcelParamTypeString(const BaseType& type) { if (type.IsUserDefinedType()) - return "rpc_port_" + type.ToString() + "_h"; + return "rpc_port_" + type.ToString() + "_h "; if (type.ToString() == "list" || type.ToString() == "array") - return "rpc_port_" + GetFullNameFromType(type) + "_h"; + return "rpc_port_" + GetFullNameFromType(type) + "_h "; if (type.ToString() == "string") - return "char*"; + return "char *"; - return type.ToString() + "*"; + return type.ToString() + " *"; } std::string CGeneratorBase::GetReturnTypeString(const BaseType& type) { if (type.IsUserDefinedType()) - return "rpc_port_" + type.ToString() + "_h"; + return "rpc_port_" + type.ToString() + "_h "; if (type.ToString() == "list" || type.ToString() == "array") - return "rpc_port_" + GetFullNameFromType(type) + "_h"; + return "rpc_port_" + GetFullNameFromType(type) + "_h "; if (type.ToString() == "string") - return "char*"; + return "char *"; - return type.ToString(); + return type.ToString() + " "; } void CGeneratorBase::AddStructureFromType(const BaseType& type) { @@ -302,29 +302,44 @@ std::string CGeneratorBase::GetParamTypeString( type.ToString() == "list" || type.ToString() == "array") { if (direction == ParameterType::Direction::IN) - return "rpc_port_" + type.ToString() + "_h"; + return "rpc_port_" + type.ToString() + "_h "; else - return "rpc_port_" + type.ToString() + "_h" + "*"; + return "rpc_port_" + type.ToString() + "_h *"; } if (type.ToString() == "string") { if (direction == ParameterType::Direction::IN) - return "const char*"; + return "const char *"; else - return "char**"; + return "char **"; } if (type.ToString() == "bundle") { if (direction == ParameterType::Direction::IN) - return "bundle*"; + return "bundle *"; else - return "bundle**"; + return "bundle **"; } if (direction == ParameterType::Direction::IN) - return type.ToString(); + return type.ToString() + " "; - return type.ToString() + "*"; + return type.ToString() + " *"; +} + +std::string CGeneratorBase::GetErrorValue(const BaseType& type) +{ + if (type.IsUserDefinedType() || + type.ToString() == "list" || + type.ToString() == "array" || + type.ToString() == "bundle" || + type.ToString() == "string") + return "NULL"; + if (type.ToString() == "bool") + return "false"; + if (type.ToString() == "char") + return "0"; + return "-1"; } } // namespace tidl diff --git a/idlc/c_gen/c_gen_base.h b/idlc/c_gen/c_gen_base.h index 07873c2..70e62f7 100644 --- a/idlc/c_gen/c_gen_base.h +++ b/idlc/c_gen/c_gen_base.h @@ -59,6 +59,7 @@ class CGeneratorBase : public Generator { std::string GetReturnTypeString(const BaseType& type); std::string GetParamTypeString(ParameterType::Direction direction, const BaseType& type); + std::string GetErrorValue(const BaseType& type); bool TypeIsDelegator(const Interface& inf, const BaseType& type); void AddStructureFromType(const BaseType& type); const std::map>& GetStructures(void) { diff --git a/idlc/c_gen/c_header_gen_base.cc b/idlc/c_gen/c_header_gen_base.cc index 2b356d2..78920cd 100644 --- a/idlc/c_gen/c_header_gen_base.cc +++ b/idlc/c_gen/c_header_gen_base.cc @@ -97,7 +97,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, @@ -127,7 +127,7 @@ void CHeaderGeneratorBase::GenStructureDestructor(std::ofstream& stream, void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream, const Structure& st) { - const char format[] = "int rpc_port_$$_$$_$$(rpc_port_$$_h h, $$ $$);\n"; + const char format[] = "int rpc_port_$$_$$_$$(rpc_port_$$_h h, $$$$);\n"; for (auto& i : st.GetElements().GetElms()) { stream << NLine(1); @@ -175,7 +175,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" || @@ -211,7 +211,7 @@ void CHeaderGeneratorBase::GenStructureIterator(std::ofstream& stream, const Structure& st) { const char format[] = "int rpc_port_foreach_$$_$$(rpc_port_$$_h h, " \ - "void (*callback)($$ $$, void* user_data), void* user_data);\n"; + "void (*callback)($$$$, void *user_data), void *user_data);\n"; for (auto& i : st.GetElements().GetElms()) { if (i->GetType().ToString() != "list" && @@ -248,7 +248,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, diff --git a/idlc/c_gen/c_proxy_body_gen.cc b/idlc/c_gen/c_proxy_body_gen.cc index a98f5f3..74cbe0b 100644 --- a/idlc/c_gen/c_proxy_body_gen.cc +++ b/idlc/c_gen/c_proxy_body_gen.cc @@ -37,7 +37,7 @@ void CProxyBodyGen::OnFiniGen(std::ofstream& stream) { void CProxyBodyGen::GenTypedefProxyDelegate(std::ofstream& stream) { const char format[] = - "typedef void (*proxy_delegate)(GList* list, rpc_port_parcel_h parcel, int seq_id);\n"; + "typedef void (*proxy_delegate)(GList *list, rpc_port_parcel_h parcel, int seq_id);\n"; stream << NLine(1); stream << std::string(format); } @@ -74,12 +74,12 @@ void CProxyBodyGen::GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf) { const char block[] = "struct ##_s {\n" \ - " char* stub_appid;\n" \ + " char *stub_appid;\n" \ " rpc_port_proxy_h proxy;\n" \ " rpc_port_h port;\n" \ " rpc_port_proxy_##_callback_s callback;\n" \ - " void* user_data;\n" \ - " GList* delegates;\n" \ + " void *user_data;\n" \ + " GList *delegates;\n" \ "};\n"; stream << NLine(1); stream << SmartIndent(ReplaceAll(block, "##", inf.GetID())); @@ -120,9 +120,9 @@ void CProxyBodyGen::GenInterfaceDelegatorDeclaration( void CProxyBodyGen::GenInterfaceDelegatorSerializer( std::ofstream& stream, const std::string& id, const Declaration& decl) { const char block[] = - "static void __##_to(rpc_port_parcel_h parcel, void* data)\n" \ + "static void __##_to(rpc_port_parcel_h parcel, void *data)\n" \ "{\n" \ - " struct ##_s* handle = data;\n" \ + " struct ##_s *handle = data;\n" \ "\n" \ " if (!handle) {\n" \ " LOGE(\"Invalid parameter\");\n" \ @@ -139,9 +139,9 @@ void CProxyBodyGen::GenInterfaceDelegatorSerializer( void CProxyBodyGen::GenInterfaceDelegatorDeserializer( std::ofstream& stream, const std::string& id, const Declaration& decl) { const char block[] = - "static void __##_from(rpc_port_parcel_h parcel, void* data)\n" \ + "static void __##_from(rpc_port_parcel_h parcel, void *data)\n" \ "{\n" \ - " struct ##_s* handle = data;\n" \ + " struct ##_s *handle = data;\n" \ "\n" \ " if (!handle) {\n" \ " LOGE(\"Invalid parameter\");\n" \ @@ -158,9 +158,9 @@ void CProxyBodyGen::GenInterfaceDelegatorDeserializer( void CProxyBodyGen::GenInterfaceDelegatorConstructor( std::ofstream& stream, const std::string& id, const Declaration& decl) { const char block[] = - "static struct ##_s* __create_##(## callback)\n" \ + "static struct ##_s *__create_##(## callback)\n" \ "{\n" \ - " struct ##_s* handle;\n" \ + " struct ##_s *handle;\n" \ " static int seq_num;\n" \ "\n" \ " handle = calloc(1, sizeof(struct ##_s));\n" \ @@ -194,8 +194,8 @@ void CProxyBodyGen::GenInterfaceDelegatorInvoker( "{\n" \ "$$" \ " do {\n" \ - " struct ##_s* handle;\n" \ - " GList* iter;\n" \ + " struct ##_s *handle;\n" \ + " GList *iter;\n" \ "\n" \ " iter = list;\n" \ " while (iter) {\n" \ @@ -220,7 +220,7 @@ void CProxyBodyGen::GenInterfaceDelegatorInvoker( for (auto& i : decl.GetParameters().GetParams()) { str += GetParcelParamTypeString( i->GetParameterType().GetBaseType()) + - " " + i->GetID() + ";" + NLine(1); + i->GetID() + ";" + NLine(1); cnt++; } if (cnt > 0) @@ -382,7 +382,7 @@ void CProxyBodyGen::GenInterfaceConsumeCommand(std::ofstream& stream, void CProxyBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream, const Interface& inf) { const char block[] = - "static void __##_on_connected(const char* endpoint, const char* port_name, rpc_port_h port, void* data)\n" \ + "static void __##_on_connected(const char *endpoint, const char *port_name, rpc_port_h port, void *data)\n" \ "{\n" \ " rpc_port_proxy_##_h handle = data;\n" \ "\n" \ @@ -398,7 +398,7 @@ void CProxyBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream, void CProxyBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream, const Interface& inf) { const char block[] = - "static void __##_on_disconnected(const char* endpoint, const char* port_name, void* data)\n" \ + "static void __##_on_disconnected(const char *endpoint, const char *port_name, void *data)\n" \ "{\n" \ " rpc_port_proxy_##_h handle = data;\n" \ "\n" \ @@ -414,7 +414,7 @@ void CProxyBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream, void CProxyBodyGen::GenInterfaceOnRejectedEventCB(std::ofstream& stream, const Interface& inf) { const char block[] = - "static void __##_on_rejected(const char* endpoint, const char* port_name, void* data)\n" \ + "static void __##_on_rejected(const char *endpoint, const char *port_name, void *data)\n" \ "{\n" \ " rpc_port_proxy_##_h handle = data;\n" \ "\n" \ @@ -430,7 +430,7 @@ void CProxyBodyGen::GenInterfaceOnRejectedEventCB(std::ofstream& stream, void CProxyBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream, const Interface& inf) { const char block[] = - "static void __##_on_received(const char* endpoint, const char* port_name, void* data)\n" \ + "static void __##_on_received(const char *endpoint, const char *port_name, void *data)\n" \ "{\n" \ " rpc_port_proxy_##_h handle = data;\n" \ " rpc_port_parcel_h parcel_received;\n" \ @@ -455,7 +455,7 @@ void CProxyBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream, void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream, const Interface& inf) { const char block[] = - "$$ rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$)\n" \ + "$$rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$)\n" \ "{\n" \ " rpc_port_parcel_h parcel;\n" \ "$$" \ @@ -479,7 +479,7 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream, "}\n"; const char delegate_block[] = "do {\n" \ - " struct ##_s* handle;\n" \ + " struct ##_s *handle;\n" \ "\n" \ " handle = __create_##($$);\n" \ " if (!handle)\n" \ @@ -522,14 +522,15 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream, p->GetID(); } else { str += ConvertTypeToString(p->GetParameterType().GetDirection(), - p->GetParameterType().GetBaseType()) + " " + p->GetID(); + p->GetParameterType().GetBaseType()) + p->GetID(); } } return str; }, [&]()->std::string { - if (GetReturnTypeString(i->GetType()) != "void") - return GetReturnTypeString(i->GetType()) + " ret = 0;" + NLine(1); + if (GetReturnTypeString(i->GetType()) != "void ") + return GetReturnTypeString(i->GetType()) + "ret = " + + GetErrorValue(i->GetType()) + ";" + NLine(1); return ""; }, [&]()->std::string { @@ -546,12 +547,12 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream, return str; }, [&]()->std::string { - if (GetReturnTypeString(i->GetType()) != "void") + if (GetReturnTypeString(i->GetType()) != "void ") return " ret"; return ""; }, [&]()->std::string { - if (GetReturnTypeString(i->GetType()) != "void") + if (GetReturnTypeString(i->GetType()) != "void ") return " ret"; return ""; }, @@ -627,7 +628,7 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream, } ); } - if (GetReturnTypeString(i->GetType()) != "void") { + if (GetReturnTypeString(i->GetType()) != "void ") { if (i->GetType().IsUserDefinedType() || i->GetType().ToString() == "list" || i->GetType().ToString() == "array") { @@ -652,7 +653,7 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream, return s; } ); - if (GetReturnTypeString(i->GetType()) != "void") { + if (GetReturnTypeString(i->GetType()) != "void ") { str += NLine(1); str += "return ret;" + NLine(1);; } @@ -666,9 +667,9 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream, void CProxyBodyGen::GenInterfaceConstructor(std::ofstream& stream, const Interface& inf) { const char block[] = - "static struct ##_s* __create_##(const char* stub_appid, rpc_port_proxy_##_callback_s* callback, void* user_data)\n" \ + "static struct ##_s *__create_##(const char *stub_appid, rpc_port_proxy_##_callback_s *callback, void *user_data)\n" \ "{\n" \ - " struct ##_s* handle;\n" \ + " struct ##_s *handle;\n" \ "\n" \ " handle = calloc(1, sizeof(struct ##_s));\n" \ " if (!handle) {\n " \ @@ -703,7 +704,7 @@ void CProxyBodyGen::GenInterfaceConstructor(std::ofstream& stream, void CProxyBodyGen::GenInterfaceDestructor(std::ofstream& stream, const Interface& inf) { const char block[] = - "static void __destroy_##(struct ##_s* h)\n" \ + "static void __destroy_##(struct ##_s *h)\n" \ "{\n" \ " if (!h)\n" \ " return;\n" \ @@ -723,9 +724,9 @@ void CProxyBodyGen::GenInterfaceDestructor(std::ofstream& stream, void CProxyBodyGen::GenInterfaceConnect(std::ofstream& stream, const Interface& inf) { const char block[] = - "int rpc_port_proxy_##_connect(const char* stub_appid, rpc_port_proxy_##_callback_s* callback, void* user_data, rpc_port_proxy_##_h* h)\n" \ + "int rpc_port_proxy_##_connect(const char *stub_appid, rpc_port_proxy_##_callback_s *callback, void *user_data, rpc_port_proxy_##_h *h)\n" \ "{\n" \ - " struct ##_s* handle;\n" \ + " struct ##_s *handle;\n" \ " int r;\n" \ "\n" \ " if (!stub_appid || !callback || !h) {\n" \ diff --git a/idlc/c_gen/c_proxy_header_gen.cc b/idlc/c_gen/c_proxy_header_gen.cc index e67de32..f30dca0 100644 --- a/idlc/c_gen/c_proxy_header_gen.cc +++ b/idlc/c_gen/c_proxy_header_gen.cc @@ -81,7 +81,7 @@ void CProxyHeaderGen::GenInterfaceDelegator(std::ofstream& stream, if (cnt != 1) str += ", "; str += ConvertTypeToString(p->GetParameterType().GetDirection(), - p->GetParameterType().GetBaseType()) + " " + p->GetID(); + p->GetParameterType().GetBaseType()) + p->GetID(); cnt++; } return str; @@ -92,12 +92,12 @@ void CProxyHeaderGen::GenInterfaceDelegator(std::ofstream& stream, void CProxyHeaderGen::GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf) { const char format[] = - "typedef struct ##_s* rpc_port_proxy_##_h;\n" \ + "typedef struct ##_s *rpc_port_proxy_##_h;\n" \ "\n" \ "typedef struct {\n" \ - " void (*connected)(rpc_port_proxy_##_h h, void* user_data);\n" \ - " void (*disconnected)(rpc_port_proxy_##_h h, void* user_data);\n" \ - " void (*rejected)(rpc_port_proxy_##_h h, void* user_data);\n" \ + " void (*connected)(rpc_port_proxy_##_h h, void *user_data);\n" \ + " void (*disconnected)(rpc_port_proxy_##_h h, void *user_data);\n" \ + " void (*rejected)(rpc_port_proxy_##_h h, void *user_data);\n" \ "} rpc_port_proxy_##_callback_s;\n"; stream << NLine(1); stream << SmartIndent(ReplaceAll(format, "##", inf.GetID())); @@ -127,7 +127,7 @@ void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream, p->GetID(); } else { str += ConvertTypeToString(p->GetParameterType().GetDirection(), - p->GetParameterType().GetBaseType()) + " " + p->GetID(); + p->GetParameterType().GetBaseType()) + p->GetID(); } } return str; @@ -139,9 +139,9 @@ void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream, void CProxyHeaderGen::GenInterfaceConnect(std::ofstream& stream, const Interface& inf) { const char format[] = - "int rpc_port_proxy_##_connect(const char* stub_appid, " \ - "rpc_port_proxy_##_callback_s* callback, void* user_data, " \ - "rpc_port_proxy_##_h* h);\n"; + "int rpc_port_proxy_##_connect(const char *stub_appid, " \ + "rpc_port_proxy_##_callback_s *callback, void *user_data, " \ + "rpc_port_proxy_##_h *h);\n"; stream << NLine(1); stream << ReplaceAll(format, "##", inf.GetID()); } diff --git a/idlc/c_gen/c_stub_body_gen.cc b/idlc/c_gen/c_stub_body_gen.cc index b74f3b4..8550724 100644 --- a/idlc/c_gen/c_stub_body_gen.cc +++ b/idlc/c_gen/c_stub_body_gen.cc @@ -62,7 +62,7 @@ void CStubBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) { void CStubBodyGen::GenInterfaceMethods(std::ofstream& stream, const Interface& inf) { const char block[] = - "static int __$$_method_$$(rpc_port_h port, rpc_port_parcel_h parcel, void* data)\n" \ + "static int __$$_method_$$(rpc_port_h port, rpc_port_parcel_h parcel, void *data)\n" \ "{\n" \ " rpc_port_stub_$$_context_h context = data;\n" \ "$$" \ @@ -135,7 +135,7 @@ void CStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream, void CStubBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream, const Interface& inf) { const char block[] = - "static void __##_on_connected(const char* sender, const char* instance, void* data)\n" \ + "static void __##_on_connected(const char *sender, const char *instance, void *data)\n" \ "{\n" \ " rpc_port_stub_##_context_h context;\n" \ "\n" \ @@ -156,7 +156,7 @@ void CStubBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream, void CStubBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream, const Interface& inf) { const char block[] = - "static void __##_on_disconnected(const char* sender, const char* instance, void* data)\n" \ + "static void __##_on_disconnected(const char *sender, const char *instance, void *data)\n" \ "{\n" \ " rpc_port_stub_##_context_h context;\n" \ "\n" \ @@ -178,7 +178,7 @@ void CStubBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream, void CStubBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream, const Interface& inf) { const char block[] = - "static int __##_on_received(const char* sender, const char* instance, rpc_port_h port, void* data)\n" \ + "static int __##_on_received(const char *sender, const char *instance, rpc_port_h port, void *data)\n" \ "{\n" \ " rpc_port_stub_##_context_h context;\n" \ " rpc_port_parcel_h parcel;\n" \ @@ -220,7 +220,7 @@ void CStubBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream, void CStubBodyGen::GenInterfaceRegister(std::ofstream& stream, const Interface& inf) { const char block[] = - "int rpc_port_stub_##_register(rpc_port_stub_##_callback_s* callback, void* user_data)\n" \ + "int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_data)\n" \ "{\n" \ " int r;\n" \ "\n" \ @@ -318,8 +318,8 @@ void CStubBodyGen::GenInterfaceGlobalVariables(std::ofstream& stream, const char format[] = "static rpc_port_stub_h __##_stub;\n" \ "static rpc_port_stub_##_callback_s __##_callback;\n" \ - "static void* __##_user_data;\n" \ - "static GList* __##_contexts;\n"; + "static void *__##_user_data;\n" \ + "static GList *__##_contexts;\n"; stream << NLine(1); stream << SmartIndent(ReplaceAll(format, "##", inf.GetID())); @@ -343,7 +343,7 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf, int cnt = 0; for (auto& i : decl.GetParameters().GetParams()) { str += GetParcelParamTypeString(i->GetParameterType().GetBaseType()) + - " " + i->GetID() + ";" + NLine(1); + i->GetID() + ";" + NLine(1); if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN) cnt++; } @@ -520,9 +520,9 @@ 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" \ + " struct ##_s *handle;\n" \ " static int seq_num;\n" \ "\n" \ " if (!h) {\n" \ @@ -580,7 +580,7 @@ void CStubBodyGen::GenInterfaceDelegatorSerializer(std::ofstream& stream, const std::string& id, const Declaration& decl) { const char block[] = - "static void __##_to(rpc_port_parcel_h parcel, void* data)\n" \ + "static void __##_to(rpc_port_parcel_h parcel, void *data)\n" \ "{\n" \ " rpc_port_##_h handle = data;\n" \ "\n" \ @@ -601,7 +601,7 @@ void CStubBodyGen::GenInterfaceDelegatorDeserializer(std::ofstream& stream, const std::string& id, const Declaration& decl) { const char block[] = - "static void __##_from(rpc_port_parcel_h parcel, void* data)\n" \ + "static void __##_from(rpc_port_parcel_h parcel, void *data)\n" \ "{\n" \ " rpc_port_##_h handle = data;\n" \ "\n" \ @@ -622,7 +622,7 @@ 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" \ @@ -696,7 +696,7 @@ void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream, for (auto& i : decl.GetParameters().GetParams()) { str += ", "; str += ConvertTypeToString(i->GetParameterType().GetDirection(), - i->GetParameterType().GetBaseType()) + " " + i->GetID(); + i->GetParameterType().GetBaseType()) + i->GetID(); } return str; }, @@ -765,12 +765,12 @@ void CStubBodyGen::GenInterfaceContextDeclaration(std::ofstream& stream, const Interface& inf) { const char block[] = "struct ##_context_s {\n" \ - " char* sender;\n" \ - " char* instance;\n" \ + " char *sender;\n" \ + " char *instance;\n" \ " rpc_port_h port;\n" \ - " void* tag;\n" \ + " void *tag;\n" \ " rpc_port_stub_##_callback_s callback;\n" \ - " void* user_data;\n" \ + " void *user_data;\n" \ "};\n"; stream << NLine(1); stream << SmartIndent(ReplaceAll(block, "##", inf.GetID())); @@ -779,9 +779,9 @@ void CStubBodyGen::GenInterfaceContextDeclaration(std::ofstream& stream, void CStubBodyGen::GenInterfaceContextConstructor(std::ofstream& stream, const Interface& inf) { const char block[] = - "static struct ##_context_s* __create_##_context(const char* sender, const char* instance)\n" \ + "static struct ##_context_s *__create_##_context(const char *sender, const char *instance)\n" \ "{\n" \ - " struct ##_context_s* handle;\n" \ + " struct ##_context_s *handle;\n" \ "\n" " handle = calloc(1, sizeof(struct ##_context_s));\n" \ " if (!handle) {\n" \ @@ -818,7 +818,7 @@ void CStubBodyGen::GenInterfaceContextDestructor(std::ofstream& stream, const char block[] = "static void __destroy_##_context(gpointer data)\n" \ "{\n" \ - " struct ##_context_s* handle = data;\n" \ + " struct ##_context_s *handle = data;\n" \ "\n" \ " if (!handle) {\n" \ " LOGE(\"Critical error!\");\n" \ @@ -836,14 +836,14 @@ void CStubBodyGen::GenInterfaceContextDestructor(std::ofstream& stream, void CStubBodyGen::GenInterfaceContextFinder(std::ofstream& stream, const Interface& inf) { const char block[] = - "static struct ##_context_s* __find_##_context(const char* instance)\n" \ + "static struct ##_context_s *__find_##_context(const char *instance)\n" \ "{\n" \ - " struct ##_context_s* handle;\n" \ - " GList* iter;\n" \ + " struct ##_context_s *handle;\n" \ + " GList *iter;\n" \ "\n" \ " iter = __##_contexts;\n" \ " while (iter) {\n" \ - " handle = (struct ##_context_s*)iter->data;\n" \ + " handle = (struct ##_context_s *)iter->data;\n" \ " if (!strcmp(handle->instance, instance))\n" \ " return handle;\n" \ " iter = g_list_next(iter);\n" \ @@ -858,7 +858,7 @@ void CStubBodyGen::GenInterfaceContextFinder(std::ofstream& stream, void CStubBodyGen::GenInterfaceContextTagSetter(std::ofstream& stream, const Interface& inf) { const char block[] = - "int rpc_port_stub_##_context_set_tag(rpc_port_stub_##_context_h ctx, void* tag)\n" \ + "int rpc_port_stub_##_context_set_tag(rpc_port_stub_##_context_h ctx, void *tag)\n" \ "{\n" \ " if (!ctx) {\n" \ " LOGE(\"Invalid parameter\");\n" \ @@ -876,7 +876,7 @@ void CStubBodyGen::GenInterfaceContextTagSetter(std::ofstream& stream, void CStubBodyGen::GenInterfaceContextTagGetter(std::ofstream& stream, const Interface& inf) { const char block[] = - "int rpc_port_stub_##_context_get_tag(rpc_port_stub_##_context_h ctx, void** tag)\n" \ + "int rpc_port_stub_##_context_get_tag(rpc_port_stub_##_context_h ctx, void **tag)\n" \ "{\n" \ " if (!ctx || !tag) {\n" \ " LOGE(\"Invalid parameter\");\n" \ @@ -894,7 +894,7 @@ void CStubBodyGen::GenInterfaceContextTagGetter(std::ofstream& stream, void CStubBodyGen::GenInterfaceContextSenderGetter(std::ofstream& stream, const Interface& inf) { const char block[] = - "int rpc_port_stub_##_context_get_sender(rpc_port_stub_##_context_h ctx, char** sender)\n" \ + "int rpc_port_stub_##_context_get_sender(rpc_port_stub_##_context_h ctx, char **sender)\n" \ "{\n" \ " if (!ctx || !sender) {\n" \ " LOGE(\"Invalid parameter\");\n" \ @@ -918,12 +918,12 @@ void CStubBodyGen::GenInterfaceContextPortExist(std::ofstream& stream, const char block[] = "static bool __##_context_port_exist(rpc_port_h port)\n" \ "{\n" \ - " struct ##_context_s* handle;\n" \ - " GList* iter;\n" \ + " struct ##_context_s *handle;\n" \ + " GList *iter;\n" \ "\n" \ " iter = __##_contexts;\n" \ " while (iter) {\n" \ - " handle = (struct ##_context_s*)iter->data;\n" \ + " handle = (struct ##_context_s *)iter->data;\n" \ " if (handle->port == port)\n" \ " return true;\n" \ " iter = g_list_next(iter);\n" \ @@ -937,7 +937,7 @@ void CStubBodyGen::GenInterfaceContextPortExist(std::ofstream& stream, void CStubBodyGen::GenTypedefStubMethod(std::ofstream& stream) { const char format[] = - "typedef int (*stub_method)(rpc_port_h, rpc_port_parcel_h, void* data);\n"; + "typedef int (*stub_method)(rpc_port_h, rpc_port_parcel_h, void *data);\n"; stream << NLine(1); stream << std::string(format); diff --git a/idlc/c_gen/c_stub_header_gen.cc b/idlc/c_gen/c_stub_header_gen.cc index cfcf6ab..61d6d03 100644 --- a/idlc/c_gen/c_stub_header_gen.cc +++ b/idlc/c_gen/c_stub_header_gen.cc @@ -58,8 +58,8 @@ void CStubHeaderGen::GenInterfaceDeclaration(std::ofstream& stream, const char callback[] = "$$ (*$$)(rpc_port_stub_Message_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" \ - " void (*terminate)(rpc_port_stub_##_context_h context, void* user_data);\n" \ + " void (*create)(rpc_port_stub_##_context_h context, void *user_data);\n" \ + " void (*terminate)(rpc_port_stub_##_context_h context, void *user_data);\n" \ " $$" \ "} rpc_port_stub_##_callback_s;\n"; stream << NLine(1); @@ -81,10 +81,10 @@ void CStubHeaderGen::GenInterfaceDeclaration(std::ofstream& stream, for (auto& p : i->GetParameters().GetParams()) { if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) { s += GetParcelParamTypeString(p->GetParameterType().GetBaseType()) + - " " + p->GetID(); + p->GetID(); } else { s += GetParamTypeString(p->GetParameterType().GetDirection(), - p->GetParameterType().GetBaseType()) + " " + p->GetID(); + p->GetParameterType().GetBaseType()) + p->GetID(); } s += ", "; } @@ -116,7 +116,7 @@ void CStubHeaderGen::GenInterfaceContextDeclaration( void CStubHeaderGen::GenInterfaceContextTagSetter( std::ofstream& stream, const Interface& inf) { const char format[] = - "int rpc_port_stub_##_context_set_tag(rpc_port_stub_##_context_h ctx, void* tag);\n"; + "int rpc_port_stub_##_context_set_tag(rpc_port_stub_##_context_h ctx, void *tag);\n"; stream << NLine(1); stream << ReplaceAll(format, "##", inf.GetID()); } @@ -124,7 +124,7 @@ void CStubHeaderGen::GenInterfaceContextTagSetter( void CStubHeaderGen::GenInterfaceContextTagGetter( std::ofstream& stream, const Interface& inf) { const char format[] = - "int rpc_port_stub_##_context_get_tag(rpc_port_stub_##_context_h ctx, void** tag);\n"; + "int rpc_port_stub_##_context_get_tag(rpc_port_stub_##_context_h ctx, void **tag);\n"; stream << NLine(1); stream << ReplaceAll(format, "##", inf.GetID()); } @@ -132,7 +132,7 @@ void CStubHeaderGen::GenInterfaceContextTagGetter( void CStubHeaderGen::GenInterfaceContextSenderGetter( std::ofstream& stream, const Interface& inf) { const char format[] = - "int rpc_port_stub_##_context_get_sender(rpc_port_stub_##_context_h ctx, char** sender);\n"; + "int rpc_port_stub_##_context_get_sender(rpc_port_stub_##_context_h ctx, char **sender);\n"; stream << NLine(1); stream << ReplaceAll(format, "##", inf.GetID()); } @@ -157,7 +157,7 @@ void CStubHeaderGen::GenInterfaceDelegator(std::ofstream& stream, void CStubHeaderGen::GenInterfaceDelegatorDeclaration( std::ofstream& stream, const std::string& id, const Declaration& decl) { - const char format[] = "typedef struct ##_s* rpc_port_##_h;\n"; + const char format[] = "typedef struct ##_s *rpc_port_##_h;\n"; stream << NLine(1); stream << ReplaceAll(format, "##", decl.GetID()); } @@ -173,7 +173,7 @@ void CStubHeaderGen::GenInterfaceDelegatorDestructor( 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()); } @@ -199,7 +199,7 @@ void CStubHeaderGen::GenInterfaceDelegatorInvoker( void CStubHeaderGen::GenInterfaceRegister(std::ofstream& stream, const Interface& inf) { const char format[] = - "int rpc_port_stub_##_register(rpc_port_stub_##_callback_s* callback, void* user_data);\n"; + "int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_data);\n"; stream << NLine(1); stream << ReplaceAll(format, "##", inf.GetID()); }