From a856b6e0fd135ccade3fa47b6862f35557f42c88 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 18 Apr 2018 18:20:04 +0900 Subject: [PATCH] Set default value If the string parameter is null, tidl sets empty string. Change-Id: If694ddb8b743fb5bbdfa53f36d8f8b6bdbd017b2 Signed-off-by: Hwankyu Jhun --- idlc/c_gen/c_body_gen_base.cc | 11 ++++++++--- idlc/c_gen/c_proxy_body_gen.cc | 6 +++++- idlc/c_gen/c_stub_body_gen.cc | 8 ++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/idlc/c_gen/c_body_gen_base.cc b/idlc/c_gen/c_body_gen_base.cc index 904451e..71844f4 100644 --- a/idlc/c_gen/c_body_gen_base.cc +++ b/idlc/c_gen/c_body_gen_base.cc @@ -373,6 +373,7 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, const BaseType& type) { std::string str; const char parcel[] = "$$(parcel, $$);"; + const char ternary_operation[] = "## ? ## : \"\""; str += GenTemplateString(parcel, [&]()->std::string { @@ -385,6 +386,8 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, return "g_list_length(h->" + id + ")"; if (type.ToString() == "array") return "h->" + id + "_size"; + if (type.ToString() == "string") + return ReplaceAll(ternary_operation, "##", "h->" + id); return "h->" + id; } ); @@ -407,10 +410,10 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, type.GetMetaType()->ToString() == "list" || type.GetMetaType()->ToString() == "array") return "&value->parcelable, value"; - if (type.GetMetaType()->ToString() == "string" || - type.GetMetaType()->ToString() == "bundle") + if (type.GetMetaType()->ToString() == "bundle") return "value"; - + if (type.GetMetaType()->ToString() == "string") + return ReplaceAll(ternary_operation, "##", "value"); return "*value"; } ); @@ -431,6 +434,8 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, type.GetMetaType()->ToString() == "list" || type.GetMetaType()->ToString() == "array") return "&h->" + id + "[i]->parcelable, h->" + id +"[i]"; + if (type.GetMetaType()->ToString() == "string") + return ReplaceAll(ternary_operation, "##", "h->" + id + "[i]"); return "h->" + id + "[i]"; } ); diff --git a/idlc/c_gen/c_proxy_body_gen.cc b/idlc/c_gen/c_proxy_body_gen.cc index b10469e..969405f 100644 --- a/idlc/c_gen/c_proxy_body_gen.cc +++ b/idlc/c_gen/c_proxy_body_gen.cc @@ -334,7 +334,6 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream, p->GetParameterType().GetBaseType().IsUserDefinedType() || p->GetParameterType().GetBaseType().ToString() == "list" || p->GetParameterType().GetBaseType().ToString() == "array" || - p->GetParameterType().GetBaseType().ToString() == "string" || p->GetParameterType().GetBaseType().ToString() == "bundle") str += " || !" + p->GetID(); } @@ -387,6 +386,7 @@ void CProxyBodyGen::GenInterfaceDisconnect(std::ofstream& stream, std::string CProxyBodyGen::GetMethodWriteString(const Interface& inf, const Declaration& decl) { const char setter[] = "$$($$, $$);\n"; + const char ternary_operation[] = "## ? ## : \"\""; std::string str; for (auto& p : decl.GetParameters().GetParams()) { if (p->GetParameterType().GetDirection() == ParameterType::Direction::OUT) @@ -418,7 +418,11 @@ std::string CProxyBodyGen::GetMethodWriteString(const Interface& inf, return "&" + p->GetID() + "->parcelable, " + p->GetID(); } else if (p->GetParameterType().GetDirection() == ParameterType::Direction::REF) { + if (p->GetParameterType().GetBaseType().ToString() == "string") + return ReplaceAll(ternary_operation, "##", "*" + p->GetID()); return "*" + p->GetID(); + } else if (p->GetParameterType().GetBaseType().ToString() == "string") { + return ReplaceAll(ternary_operation, "##", p->GetID()); } return p->GetID(); } diff --git a/idlc/c_gen/c_stub_body_gen.cc b/idlc/c_gen/c_stub_body_gen.cc index 1464340..79c30a2 100644 --- a/idlc/c_gen/c_stub_body_gen.cc +++ b/idlc/c_gen/c_stub_body_gen.cc @@ -169,6 +169,7 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf, " rpc_port_parcel_send(result, port);\n" \ " rpc_port_parcel_destroy(result);\n" \ "} while (0);\n"; + const char ternary_operation[] = "## ? ## : \"\""; int cnt = 0; for (auto& i : decl.GetParameters().GetParams()) { if (IsDelegateType(inf, i->GetParameterType().GetBaseType())) { @@ -268,6 +269,8 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf, i->GetParameterType().GetBaseType().ToString() == "list" || i->GetParameterType().GetBaseType().ToString() == "array") return "&" + i->GetID() + "->parcelable, " + i->GetID(); + else if (i->GetParameterType().GetBaseType().ToString() == "string") + return ReplaceAll(ternary_operation, "##", i->GetID()); return i->GetID(); } ); @@ -285,6 +288,8 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf, decl.GetType().ToString() == "list" || decl.GetType().ToString() == "array") return "&ret->parcelable, ret"; + else if (decl.GetType().ToString() == "string") + return ReplaceAll(ternary_operation, "##", "ret"); return "ret"; } ); @@ -423,6 +428,7 @@ void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream, const std::string& id, const Declaration& decl) { const char parcel[] = "$$(parcel, $$);\n"; + const char ternary_operation[] = "## ? ## : \"\""; stream << SmartIndent(GenTemplateString(CB_INTERFACE_DELEGATOR_INVOKER, [&]()->std::string { return id + "_" + decl.GetID(); @@ -456,6 +462,8 @@ void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream, i->GetParameterType().GetBaseType().ToString() == "list" || i->GetParameterType().GetBaseType().ToString() == "array") return "&" + i->GetID() + "->parcelable, " + i->GetID(); + else if (i->GetParameterType().GetBaseType().ToString() == "string") + return ReplaceAll(ternary_operation, "##", i->GetID()); return i->GetID(); } ); -- 2.7.4