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 dd9dd402a80755f0194b347c1ee77aa23b0fa58e..88e6d826d011c374fc8b342fed3c12f163977cc8 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 989ce76cc208c7823ba734b70af637afcafb27ec..2cf95ccab64ddb2fd87c3acc991e4512ea5a42ae 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 3630155e27339aa3920c1f8859c19273f138a9f4..c1b6092f1992efdb20ec2a2a9e4821bc0c1b41b8 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 ea2e19ddc84e2a615b64312ba9262adf04dd0c01..38a8c27ca9ef43bdbbd486ebbdcbd9dc74e7793c 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 627af67366a8345c4f3073dd41b5b7ca31cd3764..192b88b655ac57e2ada7ebfd8f1e8b190ff0acc8 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 e8ecb25ce5e4d6e92fb68651fa38ab453051688c..985cdb929f5bfe5afa84ac5d8ef09548f02c10df 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 41f24adbfa39c89c220e1e82b05006a4b79ae1ac..7dc93c5a0df092604d06de39728592946efd152f 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 51228d49d87576e11e3e5fc573117c38a1d6ff74..17e48daabdebcddc7b6f77509db93a5c85f49f53 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 bce4a9481a71efdc7871c30e8e0ea0f971dce56f..0c564c5b750374d3321f1ed1d1629361523c36c0 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 619421132aa1685f3cba87cbe265a3090ee81034..2e32d65880ac3e94e8557152e4ec1116126de7c1 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 9aafedd62358290266958f8fb74ec37ae9f6ed36..ee9f047ab6ba480cedb327408de16055b062f6bb 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 e7c3dc18aaecff604bf68becee2b66e7045ccc66..e8ff539daaeb9ee4756491f3bac73d114d35adf0 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 89a35bca27055f16a2eafc00e63d37f5c461802d..522f302baf1714b0bca516b29bba0c95afa8f76e 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 550e2a4efb976a7171f606f8bab49aadfd3b8136..df58931c6035ca8fb412d5dedeae5d0aad60b1d0 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 bb9837bd04a74cb371989f335f4277935ae3d84d..90d08ddf5cc1c430942b4936bc2ebb92a1590d36 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 869c87dde0e296647060726adf412a203470a3c1..3274e6b1f2efda47fbe6a7e680a9fe3259817b4e 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 c7710f8eae698a4f91ab4fae0a1e3588eb368480..1dbb67e6d7b1b1a553703b77336ca3d736206389 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 d174b9e08eee22a2cdf17076d8b58697f125d1c2..19e730c1255009f9d2f49cb44dbffe13a9bc8aae 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);
 }