From f32f6c16bc02ecf1e0d63936b1589df900f0f464 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Tue, 17 Apr 2018 17:44:17 +0900 Subject: [PATCH] Initialize data members for some built-in types Change-Id: I326e1e7900fd5d7ff4dcf525a8c353c195f293da Signed-off-by: Junghoon Park --- idlc/cpp_gen/cpp_gen_base.cc | 22 +++++++++++++++++++--- idlc/cpp_gen/cpp_gen_base.h | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/idlc/cpp_gen/cpp_gen_base.cc b/idlc/cpp_gen/cpp_gen_base.cc index c198d87..a259a3e 100644 --- a/idlc/cpp_gen/cpp_gen_base.cc +++ b/idlc/cpp_gen/cpp_gen_base.cc @@ -46,6 +46,16 @@ CppGeneratorBase::CppGeneratorBase(std::shared_ptr 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; diff --git a/idlc/cpp_gen/cpp_gen_base.h b/idlc/cpp_gen/cpp_gen_base.h index 3a379b1..05d62f2 100644 --- a/idlc/cpp_gen/cpp_gen_base.h +++ b/idlc/cpp_gen/cpp_gen_base.h @@ -81,6 +81,7 @@ class CppGeneratorBase : public Generator { private: std::map type_map_; std::map parcel_type_map_; + std::map type_init_map_; std::map serializer_list_; }; -- 2.7.4