From bc42987e27b73c5c4d0d6d88df77ff52a306d107 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 8 Mar 2018 15:50:32 +0900 Subject: [PATCH] Fix C Generator - Fixes implementation of array type Change-Id: Ibde6fdaea6fd185a483336fab2fabcc863b0ef37 Signed-off-by: Hwankyu Jhun --- idlc/c_gen/c_body_gen_base.cc | 432 ++++++++++++++++++++++++++++++---------- idlc/c_gen/c_body_gen_base.h | 1 - idlc/c_gen/c_gen_base.cc | 23 +++ idlc/c_gen/c_gen_base.h | 1 + idlc/c_gen/c_header_gen_base.cc | 33 ++- 5 files changed, 378 insertions(+), 112 deletions(-) diff --git a/idlc/c_gen/c_body_gen_base.cc b/idlc/c_gen/c_body_gen_base.cc index 0c020bd..24eea6f 100644 --- a/idlc/c_gen/c_body_gen_base.cc +++ b/idlc/c_gen/c_body_gen_base.cc @@ -82,6 +82,8 @@ void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream, for (auto& i : st.GetElements().GetElms()) { str += GetStringFromElementType(i->GetType()) + i->GetID() + ";" + NLine(1); + if (i->GetType().ToString() == "array") + str += "int " + i->GetID() + "_size;" + NLine(1); } return str; } @@ -184,8 +186,8 @@ void CBodyGeneratorBase::GenStructureDestructor(std::ofstream& stream, " LOGE(\"Invalid parameter\");\n" \ " return -1;\n" \ " }\n" \ - "$$" \ "\n" \ + "$$" \ " free(h);\n" \ "\n" \ " return 0;\n" \ @@ -196,7 +198,6 @@ void CBodyGeneratorBase::GenStructureDestructor(std::ofstream& stream, [&]()->std::string { std::string str; for (auto& i : st.GetElements().GetElms()) { - str += NLine(1); str += GetFinalizeString(i->GetID(), i->GetType()); } return str; @@ -226,8 +227,7 @@ void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream, return st.GetID(); }, [&]()->std::string { - if (i->GetType().ToString() == "list" || - i->GetType().ToString() == "array") + if (i->GetType().ToString() == "list") return "add"; return "set"; }, @@ -241,8 +241,7 @@ void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream, if (i->GetType().IsUserDefinedType()) return GetParcelParamTypeString(i->GetType()); - if (i->GetType().ToString() == "list" || - i->GetType().ToString() == "array") { + if (i->GetType().ToString() == "list") { if (i->GetType().GetMetaType()->IsUserDefinedType() || i->GetType().GetMetaType()->ToString() == "list" || i->GetType().GetMetaType()->ToString() == "array") { @@ -253,10 +252,21 @@ void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream, } } + if (i->GetType().ToString() == "array") { + return GetStringFromElementType(i->GetType()); + } + return ConvertTypeToString(ParameterType::Direction::IN, i->GetType()); }, [&]()->std::string { + if (i->GetType().ToString() == "array") { + std::string str; + str += i->GetID(); + str += ", "; + str += "int " + i->GetID() + "_size"; + return str; + } return i->GetID(); }, [&]()->std::string { @@ -300,8 +310,7 @@ void CBodyGeneratorBase::GenStructureGetter(std::ofstream& stream, "}\n"; for (auto& i : st.GetElements().GetElms()) { - if (i->GetType().ToString() == "list" || - i->GetType().ToString() == "array") + if (i->GetType().ToString() == "list") continue; stream << NLine(1); @@ -319,13 +328,31 @@ void CBodyGeneratorBase::GenStructureGetter(std::ofstream& stream, if (i->GetType().IsUserDefinedType()) return GetParcelParamTypeString(i->GetType()); + if (i->GetType().ToString() == "array") + return GetStringFromElementType(i->GetType()) + "*"; + return ConvertTypeToString(ParameterType::Direction::OUT, i->GetType()); }, [&]()->std::string { + if (i->GetType().ToString() == "array") { + std::string str; + str += i->GetID(); + str += ", "; + str += "int *" + i->GetID() + "_size"; + return str; + } return i->GetID(); }, [&]()->std::string { + if (i->GetType().ToString() == "array") { + std::string str; + str += "!"; + str += i->GetID(); + str += "|| "; + str += "!" + i->GetID() + "_size"; + return str; + } return "!" + i->GetID(); }, [&]()->std::string { @@ -355,8 +382,7 @@ void CBodyGeneratorBase::GenStructureIterator(std::ofstream& stream, "}\n"; for (auto& i : st.GetElements().GetElms()) { - if (i->GetType().ToString() != "list" && - i->GetType().ToString() != "array") + if (i->GetType().ToString() != "list") continue; stream << NLine(1); @@ -455,20 +481,6 @@ std::string CBodyGeneratorBase::GetParcelTypeString(const BaseType& type, return type.ToString(); } -std::string CBodyGeneratorBase::GetStringFromElementType(const BaseType& type) { - if (type.IsUserDefinedType()) - return "rpc_port_" + type.ToString() + "_h "; - if (type.ToString() == "list" || - type.ToString() == "array") - return "GList *"; - if (type.ToString() == "string") - return "char *"; - if (type.ToString() == "bundle") - return "bundle *"; - - return type.ToString() + " "; -} - std::string CBodyGeneratorBase::GetParcelWriteFunctionString( const BaseType& type, bool meta_type) { std::string str = "rpc_port_parcel_write"; @@ -483,7 +495,7 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, const BaseType& type) { std::string str; const char parcel[] = "$$(parcel, $$);\n"; - const char do_while[] = + const char do_while_list[] = "do {\n" \ " GList *iter = $$;\n" " while (iter) {\n" \ @@ -498,6 +510,12 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, " $$" \ " }\n" \ "} while (0);\n"; + const char do_while_array[] = + "do {\n" \ + " for (int i = 0; i < $$; i++) {\n" \ + "$$" + " }\n" \ + "} while (0);\n"; str += GenTemplateString(parcel, [&]()->std::string { @@ -506,16 +524,16 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, [&]()->std::string { if (type.IsUserDefinedType()) return "&h->" + id + ", h->" + id; - if (type.ToString() == "list" || - type.ToString() == "array") + if (type.ToString() == "list") return "g_list_length(h->" + id + ")"; + if (type.ToString() == "array") + return "h->" + id + "_size"; return "h->" + id; } ); - if (type.ToString() == "list" || - type.ToString() == "array") { - str += GenTemplateString(do_while, + if (type.ToString() == "list") { + str += GenTemplateString(do_while_list, [&]()->std::string { return "h->" + id; }, @@ -541,6 +559,26 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, ); } ); + } else if (type.ToString() == "array") { + str += GenTemplateString(do_while_array, + [&]()->std::string { + return "h->" + id + "_size"; + }, + [&]()->std::string { + return GenTemplateString(parcel, + [&]()->std::string { + return GetParcelWriteFunctionString(*type.GetMetaType(), true); + }, + [&]()->std::string { + if (type.GetMetaType()->IsUserDefinedType() || + type.GetMetaType()->ToString() == "list" || + type.GetMetaType()->ToString() == "array") + return "&h->" + id + "[i]->parcelable, h->" + id +"[i]"; + return "h->" + id + "[i]"; + } + ); + } + ); } return str; @@ -564,7 +602,7 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id, "if ($$) {\n" \ " $$" \ "}\n"; - const char do_while[] = + const char do_while_list[] = "do {\n" \ " int len = 0;\n" \ "\n" \ @@ -576,21 +614,25 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id, " $$ = g_list_append($$, value);\n" \ " }\n" \ "} while (0);\n"; + const char do_while_array[] = + "do {\n" \ + " $$" \ + "\n" \ + " h->## = calloc(h->##_size, sizeof(*h->##));\n" \ + " if (!h->##) {\n" \ + " LOGE(\"Out of memory\");\n" \ + " return;\n" \ + " }\n" \ + "\n" \ + " for (int i = 0; i < h->##_size; i++) {\n" \ + " $$value = $$;\n" \ + "\n" \ + " $$" \ + " }\n" \ + "} while (0);\n"; - if (type.ToString() != "list" && - type.ToString() != "array") { - str += GenTemplateString(parcel, - [&]()->std::string { - return GetParcelReadFunctionString(type); - }, - [&]()->std::string { - if (type.IsUserDefinedType()) - return "&h->" + id + "h->" + id; - return "&h->" + id; - } - ); - } else { - str += GenTemplateString(do_while, + if (type.ToString() == "list") { + str += GenTemplateString(do_while_list, [&]()->std::string { return GenTemplateString(parcel, [&]()->std::string { @@ -674,6 +716,75 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id, return "h->" + id; } ); + } else if (type.ToString() == "array") { + str += GenTemplateString(ReplaceAll(do_while_array, "##", id), + [&]()->std::string { + return GenTemplateString(parcel, + [&]()->std::string { + return GetParcelReadFunctionString(type); + }, + [&]()->std::string { + return "&h->" + id + "_size"; + } + ); + }, + [&]()->std::string { + return GetReturnTypeString(*type.GetMetaType()); + }, + [&]()->std::string { + return GetErrorValue(*type.GetMetaType()); + }, + [&]()->std::string { + std::string s; + if (type.GetMetaType()->IsUserDefinedType() || + type.GetMetaType()->ToString() == "list" || + type.GetMetaType()->ToString() == "array") { + s += GetConstructorString(*type.GetMetaType(), "value"); + s += GenTemplateString(if_statement_with_braces, + [&]()->std::string { + return "!value"; + }, + [&]()->std::string { + std::string ss; + ss += "LOGE(\"Failed to create handle\");" + NLine(1); + ss += "return;" + NLine(1); + return ss; + } + ); + s += NLine(1); + s += GenTemplateString(parcel, + [&]()->std::string { + return GetParcelReadFunctionString(*type.GetMetaType(), true); + }, + [&]()->std::string { + return "&value->parcelable, value"; + } + ); + } else { + s += GenTemplateString(parcel, + [&]()->std::string { + return GetParcelReadFunctionString(*type.GetMetaType()); + }, + [&]()->std::string { + return "&value"; + } + ); + } + s += GetSetterString("h->" + id + "[i]", "value"); + return s; + } + ); + } else { + str += GenTemplateString(parcel, + [&]()->std::string { + return GetParcelReadFunctionString(type); + }, + [&]()->std::string { + if (type.IsUserDefinedType()) + return "&h->" + id + "h->" + id; + return "&h->" + id; + } + ); } return str; @@ -685,7 +796,7 @@ std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id, const char if_statement[] = "if ($$)\n" \ " $$"; - const char do_while[] = + const char do_while_list[] = "do {\n" \ " GList *iter = $$;\n" \ " while (iter) {\n" \ @@ -695,24 +806,23 @@ std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id, " }\n" \ " g_list_free($$);\n" \ "} while (0);\n"; + const char do_while_array[] = + "do {\n" \ + " for (int i = 0; i < $$; i++) {\n" \ + " $$" \ + " }\n" \ + " free($$);\n" \ + "} while (0);\n"; if (!type.IsUserDefinedType() && - type.ToString() != "list" && - type.ToString() != "string" && - type.ToString() != "bundle") + type.ToString() != "list" && + type.ToString() != "array" && + type.ToString() != "string" && + type.ToString() != "bundle") return str; - if (type.ToString() != "list") { - str += GenTemplateString(if_statement, - [&]()->std::string { - return "h->" + id; - }, - [&]()->std::string { - return GetDestructorString(type, "h->" + id); - } - ); - } else { - str += GenTemplateString(do_while, + if (type.ToString() == "list") { + str += GenTemplateString(do_while_list, [&]()->std::string { return "h->" + id; }, @@ -725,7 +835,8 @@ std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id, return "value"; }, [&]()->std::string { - return GetDestructorString(*type.GetMetaType(), "value", true); + return GetDestructorString(*type.GetMetaType(), + "value", true); } ); }, @@ -733,6 +844,49 @@ std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id, return "h->" + id; } ); + } else if (type.ToString() == "array") { + if (!type.GetMetaType()->IsUserDefinedType() && + type.GetMetaType()->ToString() != "list" && + type.GetMetaType()->ToString() != "array" && + type.GetMetaType()->ToString() != "string" && + type.GetMetaType()->ToString() != "bundle") { + return GenTemplateString(if_statement, + [&]()->std::string { + return "h->" + id; + }, + [&]()->std::string { + return "free(h->" + id + ");" + NLine(1); + } + ); + } + str += GenTemplateString(do_while_array, + [&]()->std::string { + return "h->" + id + "_size"; + }, + [&]()->std::string { + return GenTemplateString(if_statement, + [&]()->std::string { + return "h->" + id + "[i]"; + }, + [&]()->std::string { + return GetDestructorString(*type.GetMetaType(), + "h->" + id + "[i]", true); + } + ); + }, + [&]()->std::string { + return "h->" + id; + } + ); + } else { + str += GenTemplateString(if_statement, + [&]()->std::string { + return "h->" + id; + }, + [&]()->std::string { + return GetDestructorString(type, "h->" + id); + } + ); } return str; @@ -746,7 +900,7 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, "if ($$) {\n" \ " $$" \ "}\n"; - const char do_while[] = + const char do_while_list[] = "do {\n" \ " $$value;\n" \ "\n" \ @@ -754,6 +908,19 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, " $$" \ " $$ = g_list_append($$, value);\n" \ "} while (0);\n"; + const char do_while_array[] = + "do {\n" \ + " h->## = calloc(##_size, sizeof(*##));\n" \ + " if (!h->##) {\n" \ + " LOGE(\"Out of memory\");\n" \ + " return -1;\n" \ + " }\n" \ + " h->##_size = ##_size;\n" \ + "\n" \ + " for (int i = 0; i < h->##_size; i++) {\n" \ + " $$" \ + " }\n" \ + "} while (0);\n"; if (type.IsUserDefinedType() || type.ToString() == "string" || @@ -782,8 +949,7 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, return s; } ); - } else if (type.ToString() == "list" || - type.ToString() == "array") { + } else if (type.ToString() == "list") { if (type.GetMetaType()->IsUserDefinedType() || type.GetMetaType()->ToString() == "string" || type.GetMetaType()->ToString() == "bundle" || @@ -798,7 +964,7 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, } ); } else { - str += GenTemplateString(do_while, + str += GenTemplateString(do_while_list, [&]()->std::string { return GetParcelParamTypeString(*type.GetMetaType()); }, @@ -827,6 +993,16 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, } ); } + } else if (type.ToString() == "array") { + str += GetFinalizeString(id, type); + str += GetSetterString("h->" + id, "NULL"); + str += NLine(1); + str += GenTemplateString(ReplaceAll(do_while_array, "##", id), + [&]()->std::string { + return GetSetterString(*type.GetMetaType(), + "h->" + id + "[i]", id + "[i]"); + } + ); } else { str += GetSetterString(type, "h->" + id, id); } @@ -841,47 +1017,73 @@ std::string CBodyGeneratorBase::GetGetterString(const std::string& id, "if ($$) {\n" \ " $$" \ "}\n"; + const char do_while_array[] = + "do {\n" \ + " if (h->##_size == 0) {\n" \ + " LOGW(\"## is empty\");\n" \ + " break;\n" \ + " }\n" \ + "\n" \ + " *## = calloc(h->##_size, sizeof(*h->##));\n" \ + " if (!*##) {\n" \ + " LOGE(\"Out of memory\");\n" \ + " return -1;\n" \ + " }\n" \ + " *##_size = h->##_size;\n" \ + "\n" \ + " for (int i = 0; i < h->##_size; i++) {\n" \ + " $$" \ + " }\n" \ + "} while (0);\n"; - if (type.IsUserDefinedType() || - type.ToString() == "string" || - type.ToString() == "bundle") { - str += GenTemplateString(if_statement_with_braces, - [&]()->std::string { - return "!h->" + id; - }, + if (type.ToString() == "array") { + str += GenTemplateString(ReplaceAll(do_while_array, "##", id), [&]()->std::string { - std::string s; - s += "LOGE(\"Invalid parameter: h->" + id + - " is NULL\");" + NLine(1); - s += "return -1;" + NLine(1); - return s; + return GetSetterString(*type.GetMetaType(), + "(*" + id + ")[i]", "h->" + id + "[i]"); } ); - str += NLine(1); - } - - if (type.IsUserDefinedType()) { - str += GetSetterString(type, id, "h->" + id); } else { - str += GetSetterString(type, "*" + id, "h->" + id); - } + if (type.IsUserDefinedType() || + type.ToString() == "string" || + type.ToString() == "bundle") { + str += GenTemplateString(if_statement_with_braces, + [&]()->std::string { + return "!h->" + id; + }, + [&]()->std::string { + std::string s; + s += "LOGE(\"Invalid parameter: h->" + id + + " is NULL\");" + NLine(1); + s += "return -1;" + NLine(1); + return s; + } + ); + str += NLine(1); + } - if (type.IsUserDefinedType() || - type.ToString() == "string" || - type.ToString() == "bundle") { - str += GenTemplateString(if_statement_with_braces, - [&]()->std::string { - return "*" + id + " == NULL"; - }, - [&]()->std::string { - std::string s; - s += "LOGE(\"Failed to duplicate " + id + "\");" + NLine(1); - s += "return -1;" + NLine(1); - return s; - } - ); - } + if (type.IsUserDefinedType()) { + str += GetSetterString(type, id, "h->" + id); + } else { + str += GetSetterString(type, "*" + id, "h->" + id); + } + if (type.IsUserDefinedType() || + type.ToString() == "string" || + type.ToString() == "bundle") { + str += GenTemplateString(if_statement_with_braces, + [&]()->std::string { + return "*" + id + " == NULL"; + }, + [&]()->std::string { + std::string s; + s += "LOGE(\"Failed to duplicate " + id + "\");" + NLine(1); + s += "return -1;" + NLine(1); + return s; + } + ); + } + } return str; } @@ -934,7 +1136,7 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, "if ($$) {\n" \ " $$" \ "}\n"; - const char do_while[] = + const char do_while_list[] = "do {\n" \ " GList *iter = $$;\n" \ " while (iter) {\n" \ @@ -952,6 +1154,24 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, " iter = g_list_next(iter);\n" \ " }\n" \ "} while (0);\n"; + const char do_while_array[] = + "do {\n" \ + " if (h->##_size == 0) {\n" \ + " LOGW(\"## is empty\");\n" \ + " break;\n" \ + " }\n" \ + "\n" \ + " handle->## = calloc(h->##_size, sizeof(*h->##));\n" \ + " if (!handle->##) {\n" \ + " LOGE(\"Out of memory\");\n" \ + " return -1;\n" \ + " }\n" \ + " handle->##_size = h->##_size;\n" \ + "\n" \ + " for (int i = 0; i < h->##_size; i++) {\n" \ + " $$" \ + " }\n" \ + "} while (0);\n"; if (type.IsUserDefinedType() || type.ToString() == "string" || @@ -980,9 +1200,8 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, return s; } ); - } else if (type.ToString() == "list" || - type.ToString() == "array") { - str += GenTemplateString(do_while, + } else if (type.ToString() == "list") { + str += GenTemplateString(do_while_list, [&]()->std::string { return "h->" + id; }, @@ -1047,6 +1266,13 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, return "handle->" + id; } ); + } else if (type.ToString() == "array") { + str += GenTemplateString(ReplaceAll(do_while_array, "##", id), + [&]()->std::string { + return GetSetterString(*type.GetMetaType(), + "handle->" + id + "[i]", "h->" + id + "[i]"); + } + ); } else { str += GetSetterString(type, "handle->" + id, "h->" + id); } diff --git a/idlc/c_gen/c_body_gen_base.h b/idlc/c_gen/c_body_gen_base.h index 985419e..39c1485 100644 --- a/idlc/c_gen/c_body_gen_base.h +++ b/idlc/c_gen/c_body_gen_base.h @@ -63,7 +63,6 @@ class CBodyGeneratorBase : public CGeneratorBase { void GenStructureCloner(std::ofstream& stream, const Structure& st); private: - std::string GetStringFromElementType(const BaseType& type); std::string GetParcelTypeString(const BaseType& type, bool meta_type); std::string GetParcelWriteString(const std::string& id, const BaseType& type); std::string GetParcelReadString(const std::string& id, const BaseType& type); diff --git a/idlc/c_gen/c_gen_base.cc b/idlc/c_gen/c_gen_base.cc index 839dc97..5029707 100644 --- a/idlc/c_gen/c_gen_base.cc +++ b/idlc/c_gen/c_gen_base.cc @@ -65,6 +65,14 @@ std::string CGeneratorBase::ConvertTypeToString( return "GList **"; } + if (type.ToString() == "array") { + if (direction == ParameterType::Direction::IN) { + return GetReturnTypeString(*type.GetMetaType()) + "*"; + } else { + return GetReturnTypeString(*type.GetMetaType()) + "**"; + } + } + if (type.ToString() == "string") { if (direction == ParameterType::Direction::IN) return "const char *"; @@ -345,4 +353,19 @@ std::string CGeneratorBase::GetErrorValue(const BaseType& type) return "-1"; } +std::string CGeneratorBase::GetStringFromElementType(const BaseType& type) { + if (type.IsUserDefinedType()) + return "rpc_port_" + type.ToString() + "_h "; + if (type.ToString() == "list") + return "GList *"; + if (type.ToString() == "array") + return GetReturnTypeString(*type.GetMetaType()) + "*"; + if (type.ToString() == "string") + return "char *"; + if (type.ToString() == "bundle") + return "bundle *"; + + return type.ToString() + " "; +} + } // namespace tidl diff --git a/idlc/c_gen/c_gen_base.h b/idlc/c_gen/c_gen_base.h index 70e62f7..d5707af 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 GetStringFromElementType(const BaseType& type); std::string GetErrorValue(const BaseType& type); bool TypeIsDelegator(const Interface& inf, const BaseType& type); void AddStructureFromType(const BaseType& type); diff --git a/idlc/c_gen/c_header_gen_base.cc b/idlc/c_gen/c_header_gen_base.cc index 55cae34..5782eee 100644 --- a/idlc/c_gen/c_header_gen_base.cc +++ b/idlc/c_gen/c_header_gen_base.cc @@ -144,8 +144,7 @@ void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream, return st.GetID(); }, [&]()->std::string { - if (i->GetType().ToString() == "list" || - i->GetType().ToString() == "array") + if (i->GetType().ToString() == "list") return "add"; return "set"; }, @@ -159,8 +158,7 @@ void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream, if (i->GetType().IsUserDefinedType()) return GetParcelParamTypeString(i->GetType()); - if (i->GetType().ToString() == "list" || - i->GetType().ToString() == "array") { + if (i->GetType().ToString() == "list") { if (i->GetType().GetMetaType()->IsUserDefinedType() || i->GetType().GetMetaType()->ToString() == "list" || i->GetType().GetMetaType()->ToString() == "array") { @@ -171,10 +169,21 @@ void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream, } } + if (i->GetType().ToString() == "array") { + return GetStringFromElementType(i->GetType()); + } + return ConvertTypeToString(ParameterType::Direction::IN, i->GetType()); }, [&]()->std::string { + if (i->GetType().ToString() == "array") { + std::string str; + str += i->GetID(); + str += ", "; + str += "int " + i->GetID() + "_size"; + return str; + } return i->GetID(); } ); @@ -186,8 +195,7 @@ void CHeaderGeneratorBase::GenStructureGetter(std::ofstream& stream, const char format[] = "int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$);\n"; for (auto& i : st.GetElements().GetElms()) { - if (i->GetType().ToString() == "list" || - i->GetType().ToString() == "array") + if (i->GetType().ToString() == "list") continue; stream << NLine(1); @@ -205,10 +213,20 @@ void CHeaderGeneratorBase::GenStructureGetter(std::ofstream& stream, if (i->GetType().IsUserDefinedType()) return GetParcelParamTypeString(i->GetType()); + if (i->GetType().ToString() == "array") + return GetStringFromElementType(i->GetType()) + "*"; + return ConvertTypeToString(ParameterType::Direction::OUT, i->GetType()); }, [&]()->std::string { + if (i->GetType().ToString() == "array") { + std::string str; + str += i->GetID(); + str += ", "; + str += "int *" + i->GetID() + "_size"; + return str; + } return i->GetID(); } ); @@ -222,8 +240,7 @@ void CHeaderGeneratorBase::GenStructureIterator(std::ofstream& stream, "void (*callback)($$$$, void *user_data), void *user_data);\n"; for (auto& i : st.GetElements().GetElms()) { - if (i->GetType().ToString() != "list" && - i->GetType().ToString() != "array") + if (i->GetType().ToString() != "list") continue; stream << NLine(1); -- 2.7.4