From: Hwankyu Jhun Date: Fri, 16 Jul 2021 01:30:34 +0000 (+0900) Subject: Fix bugs of C Generator X-Git-Tag: submit/tizen/20210716.045930~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f0a29c9efe5d3adfb63d1ead8514796c11d3bbf6;p=platform%2Fcore%2Fappfw%2Ftidl.git Fix bugs of C Generator If the type is built-in type, setting the result to an integer variable is not needed. Change-Id: I00106fcf8c8019b9b8c034b96fc9c48974ab81b5 Signed-off-by: Hwankyu Jhun --- diff --git a/idlc/gen/c_body_gen_base.cc b/idlc/gen/c_body_gen_base.cc index 29b01e9..f555c26 100644 --- a/idlc/gen/c_body_gen_base.cc +++ b/idlc/gen/c_body_gen_base.cc @@ -844,21 +844,30 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, str += GenTemplateString(ReplaceAll(CB_SETTER_ARRAY_BLOCK, "##", id), [&]()->std::string { std::string s; - s += "int __ret = "; + if (type.GetMetaType()->IsUserDefinedType() || + type.GetMetaType()->ToString() == "list" || + type.GetMetaType()->ToString() == "array") + s += "int __ret = "; + s += GetSetterString(*type.GetMetaType(), "h->" + id + "[i]", id + "[i]"); - s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, - [&]()->std::string { - return "__ret != 0"; - }, - [&]()->std::string { - std::string r; - r += "_E(\"Failed to clone " + id + "\");" + NLine(1); - r += GetFinalizeString(id, type, "h->") + NLine(1); - r += GetSetterString("h->" + id, "NULL") + NLine(1); - r += "return -1;"; - return r; - }); + if (type.GetMetaType()->IsUserDefinedType() || + type.GetMetaType()->ToString() == "list" || + type.GetMetaType()->ToString() == "array") { + s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, + [&]()->std::string { + return "__ret != 0"; + }, + [&]()->std::string { + std::string r; + r += "_E(\"Failed to clone " + id + "\");" + NLine(1); + r += GetFinalizeString(id, type, "h->") + NLine(1); + r += GetSetterString("h->" + id, "NULL") + NLine(1); + r += "return -1;"; + return r; + }); + } + s += NLine(1); return s; }); @@ -877,21 +886,31 @@ std::string CBodyGeneratorBase::GetGetterString(const std::string& id, str += GenTemplateString(ReplaceAll(CB_GETTER_ARRAY_BLOCK, "##", id), [&]()->std::string { std::string s; - s += "int __ret = "; + if (type.GetMetaType()->IsUserDefinedType() || + type.GetMetaType()->ToString() == "list" || + type.GetMetaType()->ToString() == "array") + s += "int __ret = "; + s += GetSetterString(*type.GetMetaType(), "(*" + id + ")[i]", "h->" + id + "[i]"); - s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, - [&]()->std::string { - return "__ret != 0"; - }, - [&]()->std::string { - std::string r; - r += "_E(\"Failed to clone " + id + "\");" + NLine(1); - r += GetFinalizeString(id, type, "h->") + NLine(1); - r += GetSetterString("h->" + id, "NULL") + NLine(1); - r += "return -1;"; - return r; - }); + + if (type.GetMetaType()->IsUserDefinedType() || + type.GetMetaType()->ToString() == "list" || + type.GetMetaType()->ToString() == "array") { + s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, + [&]()->std::string { + return "__ret != 0"; + }, + [&]()->std::string { + std::string r; + r += "_E(\"Failed to clone " + id + "\");" + NLine(1); + r += GetFinalizeString(id, type, "h->") + NLine(1); + r += GetSetterString("h->" + id, "NULL") + NLine(1); + r += "return -1;"; + return r; + }); + } + s += NLine(1); return s; }); @@ -1068,21 +1087,31 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, }, [&]()->std::string { std::string s; - s += "int __ret = "; + if (type.GetMetaType()->IsUserDefinedType() || + type.GetMetaType()->ToString() == "list" || + type.GetMetaType()->ToString() == "array") + s += "int __ret = "; + s += GetSetterString(*type.GetMetaType(), "handle->" + id + "[i]", "h->" + id + "[i]"); - s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, - [&]()->std::string { - return "__ret != 0"; - }, - [&]()->std::string { - std::string tmp; - tmp += "_E(\"Failed to clone " + id + "\");" + NLine(1); - tmp += "rpc_port_" + GetStructIdWithNamespace(st) + - "_destroy(handle);" + NLine(1); - tmp += "return -1;"; - return tmp; - }); + + if (type.GetMetaType()->IsUserDefinedType() || + type.GetMetaType()->ToString() == "list" || + type.GetMetaType()->ToString() == "array") { + s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, + [&]()->std::string { + return "__ret != 0"; + }, + [&]()->std::string { + std::string tmp; + tmp += "_E(\"Failed to clone " + id + "\");" + NLine(1); + tmp += "rpc_port_" + GetStructIdWithNamespace(st) + + "_destroy(handle);" + NLine(1); + tmp += "return -1;"; + return tmp; + }); + } + s += NLine(1); return s; });