Fix static analysis issues 17/281917/1
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 23 Sep 2022 06:49:15 +0000 (06:49 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 23 Sep 2022 06:50:31 +0000 (06:50 +0000)
Issues:
 - USELESS_TYPE_QUALIFIER_ON_RETURN_TYPE
 - INEFFECTIVE_MOVE

Change-Id: I4edeaaf8888d0a89bd7c16e5d36d6e4a18225cd9
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
18 files changed:
idlc/ast/attribute.cc
idlc/ast/attribute.h
idlc/ast/block.cc
idlc/ast/block.h
idlc/ast/declaration.cc
idlc/ast/declaration.h
idlc/ast/element.cc
idlc/ast/element.h
idlc/ast/parameter.cc
idlc/ast/parameter.h
idlc/gen/cpp_gen_base.cc
idlc/gen/dart_gen_base.cc
idlc/gen/dart_proxy_gen.cc
idlc/gen/dart_stub_gen.cc
idlc/gen_cion/cpp_cion_gen_base.cc
tests/unit_tests/attribute_unittest.cc
tests/unit_tests/declaration_unittest.cc
tests/unit_tests/element_unittest.cc

index dd9dd40..88e6d82 100644 (file)
@@ -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_;
 }
 
index 989ce76..2cf95cc 100644 (file)
@@ -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 {
index 3630155..c1b6092 100644 (file)
@@ -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_;
 }
 
index ea2e19d..38a8c27 100644 (file)
@@ -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
index 627af67..192b88b 100644 (file)
@@ -23,8 +23,8 @@
 namespace tidl {
 
 Declaration::Declaration(std::string id, std::unique_ptr<BaseType> ret_type,
-    std::unique_ptr<Parameters> params, std::string comments, unsigned line,
-    MethodType mtype)
+    std::unique_ptr<Parameters> 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_;
 }
 
index e8ecb25..985cdb9 100644 (file)
@@ -35,14 +35,14 @@ class Declaration {
   };
 
   Declaration(std::string id, std::unique_ptr<BaseType> ret_type,
-      std::unique_ptr<Parameters> params, std::string comments, unsigned line,
-      MethodType mtype = MethodType::SYNC);
+      std::unique_ptr<Parameters> 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<BaseType> ret_type_;
   std::unique_ptr<Parameters> params_;
   std::string comments_;
-  unsigned line_;
+  unsigned int line_;
   MethodType mtype_;
 };
 
index 41f24ad..7dc93c5 100644 (file)
@@ -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_;
 }
 
index 51228d4..17e48da 100644 (file)
@@ -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<BaseType> type_;
   std::string comments_;
-  unsigned line_;
+  unsigned int line_;
 };
 
 class Elements {
index bce4a94..0c564c5 100644 (file)
@@ -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_;
 }
 
index 6194211..2e32d65 100644 (file)
@@ -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<ParameterType> type_;
   std::string id_;
-  unsigned line_;
+  unsigned int line_;
 };
 
 class Parameters {
index 9aafedd..ee9f047 100644 (file)
@@ -283,10 +283,21 @@ void CppGeneratorBase::GenDeSerializer(std::ofstream& stream,
       .Change("<BODY>", [&]() {
         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;
index e7c3dc1..e8ff539 100644 (file)
@@ -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) {
index 89a35bc..522f302 100644 (file)
@@ -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, "<PARCEL_READ>", code);
   return code;
 }
index 550e2a4..df58931 100644 (file)
@@ -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, "<PARCEL_WRITE>", code);
   return code;
 }
index bb9837b..90d08dd 100644 (file)
@@ -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);
index 869c87d..3274e6b 100644 (file)
@@ -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);
index c7710f8..1dbb67e 100644 (file)
@@ -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<tidl::BaseType>(new tidl::BaseType("int", "")),
       std::move(params), "", line);
index d174b9e..19e730c 100644 (file)
@@ -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);
 }