Initialize data members for some built-in types 80/176180/1
authorJunghoon Park <jh9216.park@samsung.com>
Tue, 17 Apr 2018 08:44:17 +0000 (17:44 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 17 Apr 2018 08:44:17 +0000 (17:44 +0900)
Change-Id: I326e1e7900fd5d7ff4dcf525a8c353c195f293da
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
idlc/cpp_gen/cpp_gen_base.cc
idlc/cpp_gen/cpp_gen_base.h

index c198d87..a259a3e 100644 (file)
@@ -46,6 +46,16 @@ CppGeneratorBase::CppGeneratorBase(std::shared_ptr<Document> doc)
     {"double", "double"},
     {"bundle", "bundle"},
   };
+
+  type_init_map_ = {
+    {"char", "0"},
+    {"int", "0"},
+    {"short", "0"},
+    {"long", "0"},
+    {"bool", "false"},
+    {"float", "0.0f"},
+    {"double", "0.0"},
+  };
 }
 
 void CppGeneratorBase::GenStructuresForHeader(std::ofstream& stream) {
@@ -101,9 +111,15 @@ void CppGeneratorBase::GenStructureForHeader(std::ofstream& stream,
       [&]()->std::string {
         std::string str;
         for (auto& i : st.GetElements().GetElms()) {
-            str += NLine(1) + Tab(1)
-                + ConvertTypeToString(i->GetType()) + " "
-                + i->GetID() + "_;";
+          str += NLine(1) + Tab(1)
+              + ConvertTypeToString(i->GetType()) + " "
+              + i->GetID() + "_";
+          if (type_init_map_.find(i->GetType().ToString())
+              == type_init_map_.end()) {
+            str += ";";
+          } else {
+            str += " = " + type_init_map_[i->GetType().ToString()] + ";";
+          }
         }
         str += NLine(1);
         return str;
index 3a379b1..05d62f2 100644 (file)
@@ -81,6 +81,7 @@ class CppGeneratorBase : public Generator {
  private:
   std::map<std::string, std::string> type_map_;
   std::map<std::string, std::string> parcel_type_map_;
+  std::map<std::string, std::string> type_init_map_;
   std::map<std::string, const BaseType*> serializer_list_;
 };