Fix a bug about long type 30/173230/2
authorJunghoon Park <jh9216.park@samsung.com>
Tue, 20 Mar 2018 06:00:47 +0000 (15:00 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 20 Mar 2018 06:11:15 +0000 (15:11 +0900)
Change-Id: I2fef83b934931a9c43ca58b6ddaf6b1ca691df87
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
idlc/c_gen/c_body_gen_base.cc
idlc/c_gen/c_body_gen_base.h
idlc/c_gen/c_gen_base.cc
idlc/c_gen/c_gen_base.h

index fd8191c..2fc3a3b 100644 (file)
@@ -25,7 +25,19 @@ namespace {
 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()) {
@@ -335,16 +347,7 @@ std::string CBodyGeneratorBase::GetParcelTypeString(const BaseType& type,
                                                     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)
@@ -352,7 +355,7 @@ std::string CBodyGeneratorBase::GetParcelTypeString(const BaseType& type,
     return "array_count";
   }
 
-  return type.ToString();
+  return parcel_type_map_[type.ToString()];
 }
 
 std::string CBodyGeneratorBase::GetParcelWriteFunctionString(
index 39c1485..8b041ce 100644 (file)
@@ -76,6 +76,8 @@ class CBodyGeneratorBase : public CGeneratorBase {
                               const std::string& rvalue);
   std::string GetSetterString(const std::string& lvalue,
                               const std::string& rvalue);
+ private:
+  std::map<std::string, std::string> parcel_type_map_;
 };
 
 }  // namespace tidl
index b7aac13..43a061a 100644 (file)
@@ -30,6 +30,12 @@ namespace tidl {
 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) {
@@ -61,14 +67,6 @@ std::string CGeneratorBase::ConvertTypeToString(
       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()) + "*";
@@ -84,17 +82,10 @@ std::string CGeneratorBase::ConvertTypeToString(
       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) {
@@ -121,9 +112,9 @@ std::string CGeneratorBase::GetParcelParamTypeString(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) {
@@ -134,13 +125,7 @@ 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) {
@@ -306,17 +291,10 @@ std::string CGeneratorBase::GetParamTypeString(
       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)
@@ -337,16 +315,10 @@ 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
index 4981162..c232050 100644 (file)
@@ -77,6 +77,7 @@ class CGeneratorBase : public Generator {
 
  private:
   std::map<std::string, std::unique_ptr<Structure>> structures_;
+  std::map<std::string, std::string> type_map_;
 };
 
 }  // namespace tidl