From: Hwankyu Jhun Date: Fri, 23 Sep 2022 06:49:15 +0000 (+0000) Subject: Fix static analysis issues X-Git-Tag: accepted/tizen/unified/20220927.132322~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a9ffc573b5a0ff43e50ffcd285d31a12a8410a4;p=platform%2Fcore%2Fappfw%2Ftidl.git Fix static analysis issues Issues: - USELESS_TYPE_QUALIFIER_ON_RETURN_TYPE - INEFFECTIVE_MOVE Change-Id: I4edeaaf8888d0a89bd7c16e5d36d6e4a18225cd9 Signed-off-by: Hwankyu Jhun --- diff --git a/idlc/ast/attribute.cc b/idlc/ast/attribute.cc index dd9dd40..88e6d82 100644 --- a/idlc/ast/attribute.cc +++ b/idlc/ast/attribute.cc @@ -20,7 +20,7 @@ namespace tidl { -Attribute::Attribute(std::string key, std::string value, unsigned line) +Attribute::Attribute(std::string key, std::string value, unsigned int line) : key_(std::move(key)), value_(std::move(value)), line_(line) { } @@ -32,7 +32,7 @@ const std::string& Attribute::GetValue() const { return value_; } -const unsigned Attribute::GetLine() const { +const unsigned int Attribute::GetLine() const { return line_; } diff --git a/idlc/ast/attribute.h b/idlc/ast/attribute.h index 989ce76..2cf95cc 100644 --- a/idlc/ast/attribute.h +++ b/idlc/ast/attribute.h @@ -25,16 +25,16 @@ namespace tidl { class Attribute { public: - Attribute(std::string key, std::string value, unsigned line); + Attribute(std::string key, std::string value, unsigned int line); const std::string& GetKey() const; const std::string& GetValue() const; - const unsigned GetLine() const; + const unsigned int GetLine() const; private: std::string key_; std::string value_; - unsigned line_; + unsigned int line_; }; class Attributes { diff --git a/idlc/ast/block.cc b/idlc/ast/block.cc index 3630155..c1b6092 100644 --- a/idlc/ast/block.cc +++ b/idlc/ast/block.cc @@ -22,7 +22,7 @@ namespace tidl { Block::Block(std::string id, Block::Type type, - std::string comments, unsigned line) + std::string comments, unsigned int line) : id_(std::move(id)), type_(type), comments_(std::move(comments)), line_(line) {} @@ -34,7 +34,7 @@ const Block::Type& Block::GetType() const { return type_; } -const unsigned Block::GetLine() const { +const unsigned int Block::GetLine() const { return line_; } diff --git a/idlc/ast/block.h b/idlc/ast/block.h index ea2e19d..38a8c27 100644 --- a/idlc/ast/block.h +++ b/idlc/ast/block.h @@ -32,19 +32,19 @@ class Block { }; Block(std::string id, Block::Type type, std::string comments, - unsigned line); + unsigned int line); virtual ~Block() = default; const std::string& GetID() const; const Block::Type& GetType() const; - const unsigned GetLine() const; + const unsigned int GetLine() const; const std::string& GetComments() const; private: std::string id_; Block::Type type_; std::string comments_; - unsigned line_; + unsigned int line_; }; } // namespace tidl diff --git a/idlc/ast/declaration.cc b/idlc/ast/declaration.cc index 627af67..192b88b 100644 --- a/idlc/ast/declaration.cc +++ b/idlc/ast/declaration.cc @@ -23,8 +23,8 @@ namespace tidl { Declaration::Declaration(std::string id, std::unique_ptr ret_type, - std::unique_ptr params, std::string comments, unsigned line, - MethodType mtype) + std::unique_ptr params, std::string comments, + unsigned int line, MethodType mtype) : id_(std::move(id)), ret_type_(std::move(ret_type)), params_(std::move(params)), @@ -44,7 +44,7 @@ const Parameters& Declaration::GetParameters() const { return *params_; } -const unsigned Declaration::GetLine() const { +const unsigned int Declaration::GetLine() const { return line_; } diff --git a/idlc/ast/declaration.h b/idlc/ast/declaration.h index e8ecb25..985cdb9 100644 --- a/idlc/ast/declaration.h +++ b/idlc/ast/declaration.h @@ -35,14 +35,14 @@ class Declaration { }; Declaration(std::string id, std::unique_ptr ret_type, - std::unique_ptr params, std::string comments, unsigned line, - MethodType mtype = MethodType::SYNC); + std::unique_ptr params, std::string comments, + unsigned int line, MethodType mtype = MethodType::SYNC); const std::string& GetID() const; const BaseType& GetType() const; const Parameters& GetParameters() const; MethodType GetMethodType() const { return mtype_; } - const unsigned GetLine() const; + const unsigned int GetLine() const; const std::string& GetComments() const; private: @@ -50,7 +50,7 @@ class Declaration { std::unique_ptr ret_type_; std::unique_ptr params_; std::string comments_; - unsigned line_; + unsigned int line_; MethodType mtype_; }; diff --git a/idlc/ast/element.cc b/idlc/ast/element.cc index 41f24ad..7dc93c5 100644 --- a/idlc/ast/element.cc +++ b/idlc/ast/element.cc @@ -22,7 +22,7 @@ namespace tidl { Element::Element(std::string id, BaseType* type, - std::string comments, unsigned line) + std::string comments, unsigned int line) : id_(std::move(id)), type_(type), comments_(std::move(comments)), line_(line) {} @@ -34,7 +34,7 @@ const BaseType& Element::GetType() const { return *type_; } -const unsigned Element::GetLine() const { +const unsigned int Element::GetLine() const { return line_; } diff --git a/idlc/ast/element.h b/idlc/ast/element.h index 51228d4..17e48da 100644 --- a/idlc/ast/element.h +++ b/idlc/ast/element.h @@ -29,18 +29,18 @@ namespace tidl { class Element { public: Element(std::string id, BaseType* type, - std::string comments, unsigned line); + std::string comments, unsigned int line); const std::string& GetID() const; const BaseType& GetType() const; - const unsigned GetLine() const; + const unsigned int GetLine() const; const std::string& GetComments() const; private: std::string id_; std::unique_ptr type_; std::string comments_; - unsigned line_; + unsigned int line_; }; class Elements { diff --git a/idlc/ast/parameter.cc b/idlc/ast/parameter.cc index bce4a94..0c564c5 100644 --- a/idlc/ast/parameter.cc +++ b/idlc/ast/parameter.cc @@ -21,7 +21,7 @@ namespace tidl { -Parameter::Parameter(std::string id, ParameterType* type, unsigned line) +Parameter::Parameter(std::string id, ParameterType* type, unsigned int line) : type_(type), id_(std::move(id)), line_(line) {} const std::string& Parameter::GetID() const { @@ -32,7 +32,7 @@ const ParameterType& Parameter::GetParameterType() const { return *type_; } -const unsigned Parameter::GetLine() const { +const unsigned int Parameter::GetLine() const { return line_; } diff --git a/idlc/ast/parameter.h b/idlc/ast/parameter.h index 6194211..2e32d65 100644 --- a/idlc/ast/parameter.h +++ b/idlc/ast/parameter.h @@ -27,16 +27,16 @@ namespace tidl { class Parameter { public: - Parameter(std::string id, ParameterType* type, unsigned line); + Parameter(std::string id, ParameterType* type, unsigned int line); const std::string& GetID() const; const ParameterType& GetParameterType() const; - const unsigned GetLine() const; + const unsigned int GetLine() const; private: std::unique_ptr type_; std::string id_; - unsigned line_; + unsigned int line_; }; class Parameters { diff --git a/idlc/gen/cpp_gen_base.cc b/idlc/gen/cpp_gen_base.cc index 9aafedd..ee9f047 100644 --- a/idlc/gen/cpp_gen_base.cc +++ b/idlc/gen/cpp_gen_base.cc @@ -283,10 +283,21 @@ void CppGeneratorBase::GenDeSerializer(std::ofstream& stream, .Change("", [&]() { std::string str; for (const auto& i : st.GetElements()) { + auto& type = i->GetType(); str += AddIndent(TAB_SIZE, - ConvertTypeToDeserializer(i->GetType(), i->GetID(), "h")); - str += Tab(1) + "param.Set" + i->GetID() + "(std::move(" - + i->GetID() + "));" + NLine(2); + ConvertTypeToDeserializer(type, i->GetID(), "h")); + + str += Tab(1) + "param.Set" + i->GetID() + "("; + if (type.ToString() == "list" || + type.ToString() == "array" || + type.ToString() == "string" || + type.ToString() == "bundle" || + type.IsUserDefinedType()) + str += "std::move(" + i->GetID() + ")"; + else + str += i->GetID(); + + str += ");" + NLine(2); } str += Tab(1) + "return h;"; return str; diff --git a/idlc/gen/dart_gen_base.cc b/idlc/gen/dart_gen_base.cc index e7c3dc1..e8ff539 100644 --- a/idlc/gen/dart_gen_base.cc +++ b/idlc/gen/dart_gen_base.cc @@ -500,7 +500,7 @@ std::string DartGeneratorBase::SmartIndent(std::string lines) { // Set tab if (line.length() > 0) - tab += std::move(Tab(tab_size)); + tab += Tab(tab_size); // Set tab for if statement or for loop or while loop if (tab_once) { diff --git a/idlc/gen/dart_proxy_gen.cc b/idlc/gen/dart_proxy_gen.cc index 89a35bc..522f302 100644 --- a/idlc/gen/dart_proxy_gen.cc +++ b/idlc/gen/dart_proxy_gen.cc @@ -158,7 +158,7 @@ std::string DartProxyGen::GenMethodParcelRead(const Declaration& decl) { return {}; std::string code = std::move(GenMethodResultParcelRead(decl)); - code += std::move(GenMethodOutParamParcelRead(decl)); + code += GenMethodOutParamParcelRead(decl); code = ReplaceAll(CB_METHOD_PARCEL_READ, "", code); return code; } diff --git a/idlc/gen/dart_stub_gen.cc b/idlc/gen/dart_stub_gen.cc index 550e2a4..df58931 100644 --- a/idlc/gen/dart_stub_gen.cc +++ b/idlc/gen/dart_stub_gen.cc @@ -102,7 +102,7 @@ std::string DartStubGen::GenInterfaceCtor(const Interface& iface) { std::string code = std::move(method_handler_table); code += NLine(1); - code += std::move(attributes); + code += attributes; return code; } @@ -206,7 +206,7 @@ std::string DartStubGen::GenMethodHandlerParcelWrite(const Declaration& decl) { return {}; std::string code = std::move(GenMethodHandlerResultParcelWrite(decl)); - code += std::move(GenMethodHandlerOutParamParcelWrite(decl)); + code += GenMethodHandlerOutParamParcelWrite(decl); code = ReplaceAll(CB_METHOD_HANDLER_PARCEL_WRITE, "", code); return code; } diff --git a/idlc/gen_cion/cpp_cion_gen_base.cc b/idlc/gen_cion/cpp_cion_gen_base.cc index bb9837b..90d08dd 100644 --- a/idlc/gen_cion/cpp_cion_gen_base.cc +++ b/idlc/gen_cion/cpp_cion_gen_base.cc @@ -316,10 +316,21 @@ void CppCionGeneratorBase::GenDeSerializer(std::ofstream& stream, stream << " "; GenBrace(stream, 0, [&]() { for (const auto& i : st.GetElements()) { + auto& type = i->GetType(); stream << AddIndent(TAB_SIZE, - ConvertTypeToDeserializer(i->GetType(), i->GetID(), "h")); - stream << Tab(1) << "param.Set" << i->GetID() << "(std::move(" - << i->GetID() << "));" << NLine(2); + ConvertTypeToDeserializer(type, i->GetID(), "h")); + + stream << Tab(1) << "param.Set" << i->GetID() << "("; + if (type.ToString() == "list" || + type.ToString() == "array" || + type.ToString() == "string" || + type.ToString() == "bundle" || + type.IsUserDefinedType()) + stream << "std::move(" << i->GetID() << ")"; + else + stream << i->GetID(); + + stream << ");" << NLine(2); } stream << Tab(1) << "return h;" << NLine(1); }, false); diff --git a/tests/unit_tests/attribute_unittest.cc b/tests/unit_tests/attribute_unittest.cc index 869c87d..3274e6b 100644 --- a/tests/unit_tests/attribute_unittest.cc +++ b/tests/unit_tests/attribute_unittest.cc @@ -47,7 +47,7 @@ TEST_F(AttributeTest, Attribute_GetValue) { } TEST_F(AttributeTest, Attribute_GetLine) { - unsigned line = __LINE__; + unsigned int line = __LINE__; tidl::Attribute* attr = new tidl::Attribute("key", "value", line); EXPECT_NE(attr, nullptr); EXPECT_EQ(attr->GetLine(), line); diff --git a/tests/unit_tests/declaration_unittest.cc b/tests/unit_tests/declaration_unittest.cc index c7710f8..1dbb67e 100644 --- a/tests/unit_tests/declaration_unittest.cc +++ b/tests/unit_tests/declaration_unittest.cc @@ -91,7 +91,7 @@ TEST_F(DeclarationTest, Declaration_GetComments) { } TEST_F(DeclarationTest, Declaration_GetLine) { - unsigned line = __LINE__; + unsigned int line = __LINE__; tidl::Declaration decl("test", std::unique_ptr(new tidl::BaseType("int", "")), std::move(params), "", line); diff --git a/tests/unit_tests/element_unittest.cc b/tests/unit_tests/element_unittest.cc index d174b9e..19e730c 100644 --- a/tests/unit_tests/element_unittest.cc +++ b/tests/unit_tests/element_unittest.cc @@ -41,7 +41,7 @@ TEST_F(ElementTest, Element_GetType) { } TEST_F(ElementTest, Element_GetLine) { - unsigned line = __LINE__; + unsigned int line = __LINE__; tidl::Element elm("test", new tidl::BaseType("int", ""), "", line); EXPECT_EQ(elm.GetLine(), line); }