namespace tidl {
CBodyGeneratorBase::CBodyGeneratorBase(std::shared_ptr<Document> doc)
- : CGeneratorBase(doc) {}
+ : CGeneratorBase(doc) {
+ parcel_type_map_ = {
+ {"char", "byte"},
+ {"int", "int32"},
+ {"short", "int16"},
+ {"long", "int64"},
+ {"string", "string"},
+ {"bool", "bool"},
+ {"float", "float"},
+ {"double", "double"},
+ {"bundle", "bundle"},
+ };
+}
void CBodyGeneratorBase::GenStructures(std::ofstream& stream) {
for (auto& i : GetDocument().GetBlocks()) {
bool meta_type) {
if (type.IsUserDefinedType())
return "";
- if (type.ToString() == "char")
- return "byte";
- if (type.ToString() == "short")
- return "int16";
- if (type.ToString() == "int")
- return "int32";
- if (type.ToString() == "long")
- return "int32";
- if (type.ToString() == "long long")
- return "int64";
+
if (type.ToString() == "list" ||
type.ToString() == "array") {
if (meta_type)
return "array_count";
}
- return type.ToString();
+ return parcel_type_map_[type.ToString()];
}
std::string CBodyGeneratorBase::GetParcelWriteFunctionString(
CGeneratorBase::CGeneratorBase(std::shared_ptr<Document> doc)
: Generator(doc) {
structures_.clear();
+ type_map_ = {
+ {"char", "char "}, {"int", "int "}, {"short", "short "},
+ {"long", "long long "}, {"bool", "bool "}, {"string", "char *"},
+ {"list", "GList *"}, {"float","float "}, {"double", "double "},
+ {"bundle", "bundle *"}, {"void", "void "}
+ };
}
std::string CGeneratorBase::Tab(int cnt) {
return "rpc_port_" + type.ToString() + "_h *";
}
- if (type.ToString() == "list" ||
- type.ToString() == "array") {
- if (direction == ParameterType::Direction::IN)
- return "GList *";
- else
- return "GList **";
- }
-
if (type.ToString() == "array") {
if (direction == ParameterType::Direction::IN) {
return GetReturnTypeString(*type.GetMetaType()) + "*";
return "char **";
}
- if (type.ToString() == "bundle") {
- if (direction == ParameterType::Direction::IN)
- return "bundle *";
- else
- return "bundle **";
- }
-
if (direction == ParameterType::Direction::IN)
- return type.ToString() + " ";
+ return type_map_[type.ToString()];
- return type.ToString() + " *";
+ return type_map_[type.ToString()] + "*";
}
std::string CGeneratorBase::GetFullNameFromType(const BaseType& type) {
return "char *";
if (is_pointer)
- return type.ToString() + " *";
+ return type_map_[type.ToString()] + "*";
- return type.ToString() + " ";
+ return type_map_[type.ToString()];
}
std::string CGeneratorBase::GetReturnTypeString(const BaseType& type) {
type.ToString() == "array")
return "rpc_port_" + GetFullNameFromType(type) + "_h ";
- if (type.ToString() == "string")
- return "char *";
-
- if (type.ToString() == "bundle")
- return "bundle *";
-
- return type.ToString() + " ";
+ return type_map_[type.ToString()];
}
void CGeneratorBase::AddStructureFromType(const BaseType& type) {
return "char **";
}
- if (type.ToString() == "bundle") {
- if (direction == ParameterType::Direction::IN)
- return "bundle *";
- else
- return "bundle **";
- }
-
if (direction == ParameterType::Direction::IN)
- return type.ToString() + " ";
+ return type_map_[type.ToString()];
- return type.ToString() + " *";
+ return type_map_[type.ToString()] + "*";
}
std::string CGeneratorBase::GetErrorValue(const BaseType& type)
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() + " ";
+ return type_map_[type.ToString()];
}
} // namespace tidl