GenStructureSetter(stream, st);
GenStructureGetter(stream, st);
GenStructureIterator(stream, st);
+ GenStructureRemover(stream, st);
+ GenStructureLengthGetter(stream, st);
}
void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
}));
}
+void CBodyGeneratorBase::GenStructureRemover(std::ofstream& stream,
+ const Structure& st) {
+ for (auto& i : st.GetElements().GetElms()) {
+ if (i->GetType().ToString() != "list")
+ continue;
+
+ stream << SmartIndent(GenTemplateString(CB_STRUCT_REMOVER,
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+ i->GetType().GetMetaType()->ToString() == "list" ||
+ i->GetType().GetMetaType()->ToString() == "array")
+ return GetParcelParamTypeString(*i->GetType().GetMetaType());
+
+ return ConvertTypeToString(ParameterType::Direction::IN,
+ *i->GetType().GetMetaType());
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ std::string str;
+ str += NLine(1);
+ str += "h->" + i->GetID() + " = g_list_remove(h-> " +
+ i->GetID() + ", ";
+ if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+ i->GetType().GetMetaType()->ToString() == "list" ||
+ i->GetType().GetMetaType()->ToString() == "array" ||
+ i->GetType().GetMetaType()->ToString() == "string" ||
+ i->GetType().GetMetaType()->ToString() == "bundle")
+ str += i->GetID() + ");";
+ else
+ str += "GUINT_TO_POINTER(" + i->GetID() + "));";
+ str += NLine(1);
+ return str;
+ }));
+ }
+}
+
+void CBodyGeneratorBase::GenStructureLengthGetter(std::ofstream& stream,
+ const Structure& st) {
+ for (auto& i : st.GetElements().GetElms()) {
+ if (i->GetType().ToString() != "list")
+ continue;
+
+ stream << SmartIndent(GenTemplateString(CB_STRUCT_LENGTH_GETTER,
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ }));
+ }
+}
+
std::string CBodyGeneratorBase::GetParcelTypeString(const BaseType& type,
bool meta_type) {
if (type.IsUserDefinedType())
return "h->" + id;
},
[&]()->std::string {
- return GetParcelParamTypeString(*type.GetMetaType());
+ return GetParcelParamTypeString(*type.GetMetaType(), true);
},
[&]()->std::string {
return GenTemplateString(parcel,
return "value";
if (type.GetMetaType()->ToString() == "string")
return ReplaceAll(ternary_operation, "##", "value");
- return "*value";
+ return "GPOINTER_TO_UINT(value)";
});
});
} else if (type.ToString() == "array") {
});
},
[&]()->std::string {
- return GetParcelParamTypeString(*type.GetMetaType());
+ return GetParcelParamTypeString(*type.GetMetaType(), false);
+ },
+ [&]()->std::string {
+ if (type.GetMetaType()->IsUserDefinedType() ||
+ type.GetMetaType()->ToString() == "list" ||
+ type.GetMetaType()->ToString() == "array" ||
+ type.GetMetaType()->ToString() == "string" ||
+ type.GetMetaType()->ToString() == "bundle")
+ return "NULL;";
+ return "0;";
},
[&]()->std::string {
std::string s;
return "&value";
});
} else {
- s += "value = calloc(1, sizeof(*value));" + NLine(1);
- s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
- [&]()->std::string {
- return "!value";
- },
- [&]()->std::string {
- std::string ss;
- ss += "_E(\"Out of memory\");" + NLine(1);
- ss += "return;";
- return ss;
- });
- s += NLine(1);
s += GenTemplateString(parcel,
[&]()->std::string {
return GetParcelReadFunctionString(*type.GetMetaType());
},
[&]()->std::string {
- return "value";
+ return "&value";
});
}
},
[&]()->std::string {
return "h->" + id;
+ },
+ [&]()->std::string {
+ if (type.GetMetaType()->IsUserDefinedType() ||
+ type.GetMetaType()->ToString() == "list" ||
+ type.GetMetaType()->ToString() == "array" ||
+ type.GetMetaType()->ToString() == "string" ||
+ type.GetMetaType()->ToString() == "bundle")
+ return "value";
+ return "GUINT_TO_POINTER(value)";
});
} else if (type.ToString() == "array") {
str += GenTemplateString(ReplaceAll(CB_READ_ARRAY_BLOCK, "##", id),
return str;
if (type.ToString() == "list") {
- str += GenTemplateString(CB_FINALIZE_LIST_BLOCK,
- [&]()->std::string {
- return "h->" + id;
- },
- [&]()->std::string {
- return GetParcelParamTypeString(*type.GetMetaType());
- },
- [&]()->std::string {
- return GenTemplateString(CB_IF_STATEMENT,
- [&]()->std::string {
- return "value";
- },
- [&]()->std::string {
- return GetDestructorString(*type.GetMetaType(),
- "value", true) + NLine(1);
- });
- },
- [&]()->std::string {
- return "h->" + id;
- });
+ str += "g_list_free(h->" + id + ");";
+ str += NLine(1);
} else if (type.ToString() == "array") {
if (!type.GetMetaType()->IsUserDefinedType() &&
type.GetMetaType()->ToString() != "list" &&
return "h->" + id;
},
[&]()->std::string {
- if (type.GetMetaType()->ToString() == "string")
- return "g_list_append(h->" + id + ", strdup(" + id + "))";
return "g_list_append(h->" + id + ", " + id + ")";
});
} else {
str += GenTemplateString(CB_SETTER_LIST_BLOCK,
[&]()->std::string {
- return GetParcelParamTypeString(*type.GetMetaType());
- },
- [&]()->std::string {
- std::string s;
- s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
- [&]()->std::string {
- return "!value";
- },
- [&]()->std::string {
- std::string s;
- s += "_E(\"Out of memory\");" + NLine(1);
- s += "return -1;";
- return s;
- });
- s += NLine(1);
- s += GetSetterString("*value", id);
- return s;
+ return id;
},
[&]()->std::string {
return "h->" + id;
},
[&]()->std::string {
- return "h->" + id;
+ return "h->" + id;
});
}
} else if (type.ToString() == "array") {
type.GetMetaType()->ToString() == "bundle")
return "value";
- return "*value";
+ return "GPOINTER_TO_UINT(value)";
});
return str;
return "h->" + id;
},
[&]()->std::string {
- return GetParcelParamTypeString(*type.GetMetaType());
- },
- [&]()->std::string {
- return GetParcelParamTypeString(*type.GetMetaType());
- },
- [&]()->std::string {
- return GetStructIdWithNamespace(st);
- },
- [&]()->std::string {
- std::string s;
- if (type.GetMetaType()->IsUserDefinedType() ||
- type.GetMetaType()->ToString() == "list" ||
- type.GetMetaType()->ToString() == "array" ||
- type.GetMetaType()->ToString() == "string" ||
- type.GetMetaType()->ToString() == "bundle") {
- s += GetSetterString(*type.GetMetaType(),
- "new_value", "value");
- s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
- [&]()->std::string {
- return "!new_value";
- },
- [&]()->std::string {
- std::string ss;
- ss += "_E(\"Failed to duplicate value\");" + NLine(1);
- ss += "rpc_port_" + GetStructIdWithNamespace(st)
- + "_destroy(handle);" + NLine(1);
- ss += "return -1;";
- return ss;
- });
- } else {
- s += "new_value = calloc(1, sizeof(*new_value));" + NLine(1);
- s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
- [&]()->std::string {
- return "!new_value";
- },
- [&]()->std::string {
- std::string tmp;
- tmp += "_E(\"Out of memory\");" + NLine(1);
- tmp += "rpc_port_" + GetStructIdWithNamespace(st)
- + "_destroy(handle);" + NLine(1);
- tmp += "return -1;";
- return tmp;
- });
- s += NLine(1);
- s += GetSetterString(*type.GetMetaType(),
- "*new_value", "*value");
- }
- s += NLine(1);
- return s;
- },
- [&]()->std::string {
return "handle->" + id;
},
[&]()->std::string {
$$value = iter->data;
iter = g_list_next(iter);
- if (!value) {
- _W("Warning: value is NULL");
- continue;
- }
+ if (!value)
+ _W("Warning: value is nullptr");
+
$$
}
} while (0);
)__c_cb";
+const char CB_STRUCT_REMOVER[] =
+R"__c_cb(
+int rpc_port_$$_remove_$$(rpc_port_$$_h h, $$$$)
+{
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+$$
+ return 0;
+}
+)__c_cb";
+
+const char CB_STRUCT_LENGTH_GETTER[] =
+R"__c_cb(
+int rpc_port_$$_get_$$_length(rpc_port_$$_h h, unsigned int *length)
+{
+ if (!h || !length) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *length = g_list_length(h->$$);
+
+ return 0;
+}
+)__c_cb";
+
const char CB_WRITE_ARRAY_BLOCK[] =
R"__c_cb(
do {
$$
for (int i = 0; i < len; i++) {
- $$value = NULL;
+ $$value = $$;
$$
- $$ = g_list_append($$, value);
+ $$ = g_list_append($$, $$);
}
} while (0);
)__c_cb";
const char CB_SETTER_LIST_BLOCK[] =
R"__c_cb(
do {
- $$value;
+ gpointer value = GUINT_TO_POINTER($$);
- value = calloc(1, sizeof(*value));
- $$
$$ = g_list_append($$, value);
} while (0);
)__c_cb";
$$value = iter->data;
iter = g_list_next(iter);
- if (!value) {
- _W("Warning: value is NULL");
- continue;
- }
+ if (!value)
+ _W("Warning: value is nullptr");
bool ret = callback($$, user_data);
if (!ret)
iter = $$;
while (iter) {
- $$new_value;
- $$value = iter->data;
-
- if (!value) {
- _E("Error: value is NULL");
- rpc_port_$$_destroy(handle);
- return -1;
- }
-
- $$
- $$ = g_list_append($$, new_value);
+ $$ = g_list_append($$, iter->data);
iter = g_list_next(iter);
}
} while (0);
GenStructureSetter(stream, st);
GenStructureGetter(stream, st);
GenStructureIterator(stream, st);
+ GenStructureRemover(stream, st);
+ GenStructureLengthGetter(stream, st);
}
void CHeaderGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
});
}
+void CHeaderGeneratorBase::GenStructureRemover(std::ofstream& stream,
+ const Structure& st) {
+ for (auto& i : st.GetElements().GetElms()) {
+ if (i->GetType().ToString() != "list")
+ continue;
+
+ GenTemplate(CB_STRUCT_REMOVER, stream,
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+ i->GetType().GetMetaType()->ToString() == "list" ||
+ i->GetType().GetMetaType()->ToString() == "array")
+ return GetParcelParamTypeString(*i->GetType().GetMetaType());
+
+ return ConvertTypeToString(ParameterType::Direction::IN,
+ *i->GetType().GetMetaType());
+ },
+ [&]()->std::string {
+ return i->GetID();
+ });
+ }
+}
+
+void CHeaderGeneratorBase::GenStructureLengthGetter(std::ofstream& stream,
+ const Structure& st) {
+ for (auto& i : st.GetElements().GetElms()) {
+ if (i->GetType().ToString() != "list")
+ continue;
+
+ GenTemplate(CB_STRUCT_LENGTH_GETTER, stream,
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ });
+ }
+}
+
} // namespace tidl