Use string literal operator for getting hash code 46/316946/1
authorpjh9216 <jh9216.park@samsung.com>
Fri, 20 Dec 2024 05:07:24 +0000 (14:07 +0900)
committerpjh9216 <jh9216.park@samsung.com>
Fri, 20 Dec 2024 05:07:24 +0000 (14:07 +0900)
Change-Id: Ib416410581e43ad7a5017d5df55c13c6759732e9
Signed-off-by: pjh9216 <jh9216.park@samsung.com>
idlc/gen/version2/cpp_generator_base.cc
idlc/gen/version2/cpp_group_body_generator.cc
idlc/gen/version2/cpp_proxy_body_generator.cc
idlc/gen/version2/cpp_stub_body_generator.cc
idlc/gen/version2/rs_gen_base.cc
idlc/gen/version2/rs_group_gen.cc
idlc/gen/version2/rs_proxy_gen.cc
idlc/gen/version2/rs_stub_gen.cc

index 212839aa73f5b923e224a75cf838896e80c02cff..fb5696b026affd357b2325c3af07f4fcf9e61d17 100644 (file)
@@ -671,8 +671,8 @@ std::string CppGeneratorBase::GenUnitMap(bool use_file, bool is_group) {
           .Repeat("UNIT_MAP_READ_WRITE", unit_types_,
                   [&](auto& r, const auto& i) {
                     auto& param_type = i.second;
-                    r.Replace("TYPE", std::to_string(GetHashCode(
-                                          GetFullNameFromType(param_type))))
+                    r.Replace("TYPE",
+                              GetHashCodeStr(GetFullNameFromType(param_type)))
                         .Replace("TYPE_STR", GetFullNameFromType(param_type))
                         .Replace("PARAM_TYPE",
                                  ConvertTypeToString(param_type, true));
index b1791e0097e998fd4bc573cdb80fcac286a0d5ba..d17577ea9db034f89c98a4c498fe9eb91e4a9b71 100644 (file)
@@ -70,7 +70,7 @@ std::string CppGroupBodyGenerator::GenInterfaces() {
 std::string CppGroupBodyGenerator::GenInterface(const Interface& iface) {
   return std::string(
       ReplaceAll(CB_INTERFACE)
-          .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
+          .Replace("HASH_METHOD", "[METHOD]"_hash)
           .Repeat("IMPL_DISPATCH_FUNC_INIT", iface.GetDeclarations(),
                   [&](auto& r, const auto& i) {
                     r.Replace("NAME", i->GetID())
@@ -92,8 +92,7 @@ std::string CppGroupBodyGenerator::GenInterfaceImplDispatchFunc(
                         [&](auto& r, const auto& i) {
                           auto& type = i->GetParameterType().GetBaseType();
                           r.Replace("TYPE", ConvertTypeToString(type))
-                              .Replace("HASH_NAME",
-                                       std::to_string(GetHashCode(i->GetID())))
+                              .Replace("HASH_NAME", GetHashCodeStr(i->GetID()))
                               .Replace("NAME", i->GetID());
                           return true;
                         })
@@ -120,13 +119,12 @@ std::string CppGroupBodyGenerator::GenInterfaceMethod(const Interface& iface) {
   std::string code;
   for (auto& decl : iface.GetDeclarations()) {
     code += ReplaceAll(CB_INTERFACE_METHOD)
-                .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
+                .Replace("HASH_METHOD", "[METHOD]"_hash)
                 .Replace("CLS_NAME", iface.GetID())
                 .Replace("PARAMS", GetParameters(decl->GetParameters()))
                 .Repeat("SERIALIZE", decl->GetParameters(),
                         [&](auto& r, const auto& i) {
-                          r.Replace("HASH_NAME",
-                                    std::to_string(GetHashCode(i->GetID())))
+                          r.Replace("HASH_NAME", GetHashCodeStr(i->GetID()))
                               .Replace("NAME", i->GetID());
                           return true;
                         })
index 94aac0d6e601d8fc827e811bbe226bc45b841861..2b2c09a7cd166c5073fd4ae4fb393246ef833a4a 100644 (file)
@@ -104,14 +104,13 @@ std::string CppProxyBodyGenerator::GenInterfaces() {
 }
 
 std::string CppProxyBodyGenerator::GenInterface(const Interface& iface) {
-  return std::string(
-      ReplaceAll(CB_INTERFACE_BASE)
-          .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
-          .Replace("HASH_DELEGATE", std::to_string(GetHashCode("delegate")))
-          .Replace("CLS_NAME", iface.GetID())
-          .Replace("ENUMS", GenEnumerations(iface.GetEnums()))
-          .Replace("CALLBACKS", GenInterfaceCallbacks(iface))
-          .Replace("METHODS", GenInterfaceMethods(iface)));
+  return std::string(ReplaceAll(CB_INTERFACE_BASE)
+                         .Replace("HASH_METHOD", "[METHOD]"_hash)
+                         .Replace("HASH_DELEGATE", "delegate"_hash)
+                         .Replace("CLS_NAME", iface.GetID())
+                         .Replace("ENUMS", GenEnumerations(iface.GetEnums()))
+                         .Replace("CALLBACKS", GenInterfaceCallbacks(iface))
+                         .Replace("METHODS", GenInterfaceMethods(iface)));
 }
 
 std::string CppProxyBodyGenerator::GenInterfaceCallbacks(
@@ -128,8 +127,7 @@ std::string CppProxyBodyGenerator::GenInterfaceCallbacks(
             .Repeat("MAP_READ", decl->GetParameters(),
                     [&](auto& r, const auto& i) {
                       auto& type = i->GetParameterType().GetBaseType();
-                      r.Replace("HASH_NAME",
-                                std::to_string(GetHashCode(i->GetID())))
+                      r.Replace("HASH_NAME", GetHashCodeStr(i->GetID()))
                           .Replace("TYPE", ConvertTypeToString(type))
                           .Replace("NAME", i->GetID());
                       return true;
@@ -187,7 +185,7 @@ std::string CppProxyBodyGenerator::GenInterfaceMethod(const Interface& iface,
                     [&](auto& r, const auto& i) {
                       return GenInterfaceMethodSerialize(r, i);
                     })
-            .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
+            .Replace("HASH_METHOD", "[METHOD]"_hash)
             .Replace("IFACE_NAME", iface.GetID())
             .Replace("NAME", decl.GetID())
             .Replace("PARAMS", GetParameters(decl.GetParameters())));
@@ -206,15 +204,13 @@ std::string CppProxyBodyGenerator::GenInterfaceMethod(const Interface& iface,
                         ParameterType::Direction::IN)
                       return false;
 
-                    r.Replace("HASH_DNAME",
-                              std::to_string(GetHashCode(i->GetID())))
+                    r.Replace("HASH_DNAME", GetHashCodeStr(i->GetID()))
                         .Replace("DNAME", i->GetID());
                     return true;
                   })
-          .Replace("HASH_REMOTE_EXCEPTION",
-                   std::to_string(GetHashCode("[REMOTE_EXCEPTION]")))
-          .Replace("HASH_RESULT", std::to_string(GetHashCode("[RESULT]")))
-          .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
+          .Replace("HASH_REMOTE_EXCEPTION", "[REMOTE_EXCEPTION]"_hash)
+          .Replace("HASH_RESULT", "[RESULT]"_hash)
+          .Replace("HASH_METHOD", "[METHOD]"_hash)
           .Replace("RETURN_TYPE", ConvertTypeToString(decl.GetType()))
           .Replace("SET_INIT_VALUE", GetSettingInitValue(decl.GetType()))
           .Replace("IFACE_NAME", iface.GetID())
@@ -227,7 +223,7 @@ bool CppProxyBodyGenerator::GenInterfaceMethodSerialize(
   if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT)
     return false;
 
-  r.Replace("HASH_SNAME", std::to_string(GetHashCode(i->GetID())))
+  r.Replace("HASH_SNAME", GetHashCodeStr(i->GetID()))
       .Replace("SNAME", i->GetID());
   return true;
 }
index 4695a092c1267b0afe30fa41dbc377c62686d0b2..c99ef2f751fa32204b36184d6b41b44076180dd2 100644 (file)
@@ -154,7 +154,7 @@ std::string CppStubBodyGenerator::GenInterface(const Interface& iface) {
                                  return attr->GetKey() == "trusted" &&
                                         attr->GetValue() == "true";
                                }) == iface.GetAttributes().end())
-          .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
+          .Replace("HASH_METHOD", "[METHOD]"_hash)
           .Replace("CLS_NAME", iface.GetID())
           .Replace("CALLBACKS", GenInterfaceCallbacks(iface))
           .Replace("IMPL_SERVICE_BASE_THREAD_MEMBER_INIT",
@@ -182,25 +182,23 @@ std::string CppStubBodyGenerator::GenInterfaceCallbacks(
   for (const auto& decl : iface.GetDeclarations()) {
     if (decl->GetMethodType() != Declaration::MethodType::DELEGATE) continue;
 
-    code +=
-        ReplaceAll(CB_INTERFACE_CALLBACK)
-            .Repeat("SERIALIZE", decl->GetParameters(),
-                    [&](auto& r, const auto& i) {
-                      r.Replace("HASH_NAME",
-                                std::to_string(GetHashCode(i->GetID())))
-                          .Replace("NAME", i->GetID());
-                      return true;
-                    })
-            .Repeat("PRIVATE_SHARINGS", decl->GetParameters(),
-                    [&](auto& r, const auto& i) {
-                      r.Replace("PRIVATE_SHARING", GenPrivateSharing(*i));
-                      return true;
-                    })
-            .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
-            .Replace("HASH_DELEGATE", std::to_string(GetHashCode("delegate")))
-            .Replace("IFACE_NAME", iface.GetID())
-            .Replace("CLS_NAME", decl->GetID())
-            .Replace("PARAMS", GetParameters(decl->GetParameters()));
+    code += ReplaceAll(CB_INTERFACE_CALLBACK)
+                .Repeat("SERIALIZE", decl->GetParameters(),
+                        [&](auto& r, const auto& i) {
+                          r.Replace("HASH_NAME", GetHashCodeStr(i->GetID()))
+                              .Replace("NAME", i->GetID());
+                          return true;
+                        })
+                .Repeat("PRIVATE_SHARINGS", decl->GetParameters(),
+                        [&](auto& r, const auto& i) {
+                          r.Replace("PRIVATE_SHARING", GenPrivateSharing(*i));
+                          return true;
+                        })
+                .Replace("HASH_METHOD", "[METHOD]"_hash)
+                .Replace("HASH_DELEGATE", "delegate"_hash)
+                .Replace("IFACE_NAME", iface.GetID())
+                .Replace("CLS_NAME", decl->GetID())
+                .Replace("PARAMS", GetParameters(decl->GetParameters()));
 
     code += NLine(1);
   }
@@ -275,8 +273,7 @@ std::string CppStubBodyGenerator::GenInterfaceImplServiceBaseDispatchFunc(
                         ParameterType::Direction::IN)
                       return false;
 
-                    r.Replace("HASH_NAME",
-                              std::to_string(GetHashCode(i->GetID())))
+                    r.Replace("HASH_NAME", GetHashCodeStr(i->GetID()))
                         .Replace("NAME", i->GetID());
                     return true;
                   })
@@ -285,10 +282,9 @@ std::string CppStubBodyGenerator::GenInterfaceImplServiceBaseDispatchFunc(
                     r.Replace("PRIVATE_SHARING", GenPrivateSharing(*i));
                     return true;
                   })
-          .Replace("HASH_REMOTE_EXCEPTION",
-                   std::to_string(GetHashCode("[REMOTE_EXCEPTION]")))
-          .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
-          .Replace("HASH_RESULT", std::to_string(GetHashCode("[RESULT]")))
+          .Replace("HASH_REMOTE_EXCEPTION", "[REMOTE_EXCEPTION]"_hash)
+          .Replace("HASH_METHOD", "[METHOD]"_hash)
+          .Replace("HASH_RESULT", "[RESULT]"_hash)
           .Replace("IFACE_NAME", iface.GetID())
           .Replace("NAME", decl.GetID())
           .Replace("PARAMS", params)
@@ -316,11 +312,11 @@ std::string CppStubBodyGenerator::GenInterfaceServiceBaseDeserialize(
         ParameterType::Direction::OUT)
       continue;
 
-    code += RemoveLine(std::string(
-        ReplaceAll(CB_INTERFACE_SERVICE_BASE_UNIT_MAP_READ)
-            .Replace("HASH_NAME", std::to_string(GetHashCode(param->GetID())))
-            .Replace("TYPE", ConvertTypeToString(type))
-            .Replace("NAME", param->GetID())));
+    code += RemoveLine(
+        std::string(ReplaceAll(CB_INTERFACE_SERVICE_BASE_UNIT_MAP_READ)
+                        .Replace("HASH_NAME", GetHashCodeStr(param->GetID()))
+                        .Replace("TYPE", ConvertTypeToString(type))
+                        .Replace("NAME", param->GetID())));
   }
 
   return RemoveLine(code);
index bc432f527140628bef87eabafe018d21bde048f5..55e8b1b3a699b81c7404752a15b3e19fc9f09590 100644 (file)
@@ -123,17 +123,16 @@ void RsGeneratorBase::OnInitGen(std::ofstream& stream) {
               })
       .ReplaceBlock("META_PARCELS",
                     [&](ReplaceAll& ra) { return SetMetaParcelBlock(ra); })
-      .Replace("HASH_CHAR", std::to_string(GetHashCode("char")))
-      .Replace("HASH_SHORT", std::to_string(GetHashCode("short")))
-      .Replace("HASH_INT", std::to_string(GetHashCode("int")))
-      .Replace("HASH_LONG", std::to_string(GetHashCode("long")))
-      .Replace("HASH_FLOAT", std::to_string(GetHashCode("float")))
-      .Replace("HASH_DOUBLE", std::to_string(GetHashCode("double")))
-      .Replace("HASH_BOOL", std::to_string(GetHashCode("bool")))
-      .Replace("HASH_STRING", std::to_string(GetHashCode("string")))
-      .Replace("HASH_REMOTE_EXCEPTION",
-               std::to_string(GetHashCode("remote_exception")))
-      .Replace("HASH_BUNDLE", std::to_string(GetHashCode("bundle")))
+      .Replace("HASH_CHAR", "char"_hash)
+      .Replace("HASH_SHORT", "short"_hash)
+      .Replace("HASH_INT", "int"_hash)
+      .Replace("HASH_LONG", "long"_hash)
+      .Replace("HASH_FLOAT", "float"_hash)
+      .Replace("HASH_DOUBLE", "double"_hash)
+      .Replace("HASH_BOOL", "bool"_hash)
+      .Replace("HASH_STRING", "string"_hash)
+      .Replace("HASH_REMOTE_EXCEPTION", "remote_exception"_hash)
+      .Replace("HASH_BUNDLE", "bundle"_hash)
       .Out(stream);
   stream.close();
 }
@@ -253,8 +252,7 @@ bool RsGeneratorBase::SetParcels(ReplaceAll& ra,
                              ConvertTypeToString(e->GetType(), i, false));
                 return true;
               })
-      .Replace("HASH_UNIT_TYPE",
-               std::to_string(GetHashCode(GetStructTypeString(st))))
+      .Replace("HASH_UNIT_TYPE", GetHashCodeStr(GetStructTypeString(st)))
       .Replace("UNIT_TYPE", GetStructTypeString(st));
   return true;
 }
@@ -306,8 +304,7 @@ void RsGeneratorBase::SetMetaParcelBlock(ReplaceAll& ra) {
 
     target.Replace("TYPE", ConvertTypeToString(type, nullptr, false))
         .Replace("TYPE_ID", GetFullNameFromType(type))
-        .Replace("HASH_TYPE_ID",
-                 std::to_string(GetHashCode(GetFullNameFromType(type))))
+        .Replace("HASH_TYPE_ID", GetHashCodeStr(GetFullNameFromType(type)))
         .RemoveAll("LIST", type.ToString() != "list")
         .RemoveAll("ARRAY", type.ToString() != "array")
         .RemoveAll("SET", type.ToString() != "set")
index 300a6d51f9e6f508b8fdd38ef300673c7bff85db..6c51c3d439fbc34f1d2e3d6a03f966438b6722b2 100644 (file)
@@ -33,11 +33,11 @@ void RsGroupGen::OnInitGen(std::ofstream& stream) {
   ReplaceAll(::CB_GROUP_MAIN)
       .Replace("VERSION", std::string(FULLVER))
       .Repeat("STRUCTS", GetDocument().GetBlocks(),
-            [&](ReplaceAll& ra, const std::shared_ptr<Block>& i) {
-          return SetStructs(ra, i);
-        })
+              [&](ReplaceAll& ra, const std::shared_ptr<Block>& i) {
+                return SetStructs(ra, i);
+              })
       .ReplaceBlock("MODULE_BLOCK", [&](ReplaceAll& ra) { SetModules(ra); })
-      .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
+      .Replace("HASH_METHOD", "[METHOD]"_hash)
       .Out(stream);
   stream.close();
 }
@@ -51,126 +51,122 @@ void RsGroupGen::SetModules(ReplaceAll& ra) {
   int m_cnt = 2;
   int d_cnt = 1;
 
-  ra.Repeat("MODULES", GetDocument().GetBlocks(),
+  ra.Repeat(
+      "MODULES", GetDocument().GetBlocks(),
       [&](ReplaceAll& ra, const std::shared_ptr<Block>& i) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      return false;
-    Interface& iface = static_cast<Interface&>(*i);
-    ra.Replace("MOD_NAME", PascalToSnake(iface.GetID()))
-        .Repeat("METHOD_ID", iface.GetDeclarations(),
-            [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d){
-          return SetMethodIDs(ra, d, m_cnt);
-        })
-        .Repeat("DELEGATE_ID", iface.GetDeclarations(),
-            [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d){
-          return SetDelegateIDs(ra, d, d_cnt);
-        })
-        .ReplaceBlock("DELEGATE_BLOCK", [&](ReplaceAll& ra) {
-          SetDelegateBlock(ra, iface);
-        })
-        .Repeat("ENUM", iface.GetEnums(),
-            [&](ReplaceAll& ra, const std::unique_ptr<Enum>& e) {
-          return SetEnum(ra, e);
-        })
-        .ReplaceBlock("INTERFACE_BLOCK", [&](ReplaceAll& ra) {
-          SetInterfaceBlock(ra, iface);
-        });
-    return true;
-  });
+        if (i->GetType() != Block::TYPE_INTERFACE) return false;
+        Interface& iface = static_cast<Interface&>(*i);
+        ra.Replace("MOD_NAME", PascalToSnake(iface.GetID()))
+            .Repeat("METHOD_ID", iface.GetDeclarations(),
+                    [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d) {
+                      return SetMethodIDs(ra, d, m_cnt);
+                    })
+            .Repeat("DELEGATE_ID", iface.GetDeclarations(),
+                    [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d) {
+                      return SetDelegateIDs(ra, d, d_cnt);
+                    })
+            .ReplaceBlock("DELEGATE_BLOCK",
+                          [&](ReplaceAll& ra) { SetDelegateBlock(ra, iface); })
+            .Repeat("ENUM", iface.GetEnums(),
+                    [&](ReplaceAll& ra, const std::unique_ptr<Enum>& e) {
+                      return SetEnum(ra, e);
+                    })
+            .ReplaceBlock("INTERFACE_BLOCK", [&](ReplaceAll& ra) {
+              SetInterfaceBlock(ra, iface);
+            });
+        return true;
+      });
 }
 
 bool RsGroupGen::SetMethodIDs(ReplaceAll& ra,
-    const std::unique_ptr<Declaration>& d, int& cnt) {
-  if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
-    return false;
+                              const std::unique_ptr<Declaration>& d, int& cnt) {
+  if (d->GetMethodType() == Declaration::MethodType::DELEGATE) return false;
 
   ra.Replace("ID", SnakeToPascal(d->GetID()))
-    .Replace("COUNT", std::to_string(cnt++));
+      .Replace("COUNT", std::to_string(cnt++));
   return true;
 }
 
 bool RsGroupGen::SetDelegateIDs(ReplaceAll& ra,
-    const std::unique_ptr<Declaration>& d, int& cnt) {
-  if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
-    return false;
+                                const std::unique_ptr<Declaration>& d,
+                                int& cnt) {
+  if (d->GetMethodType() != Declaration::MethodType::DELEGATE) return false;
 
   ra.Replace("ID", SnakeToPascal(d->GetID()))
-    .Replace("COUNT", std::to_string(cnt++));
+      .Replace("COUNT", std::to_string(cnt++));
   return true;
 }
 
-
 void RsGroupGen::SetDelegateBlock(ReplaceAll& ra, const Interface& iface) {
   auto& decls = iface.GetDeclarations();
 
   ra.Repeat("DELEGATES", decls,
-      [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& i) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-      return false;
-    ra.Replace("TYPES", GetParameters(i->GetParameters(), true))
-      .Repeat("REPLY_BODY", i->GetParameters(),
-          [&](ReplaceAll& ra, const std::unique_ptr<tidl::Parameter>& p) {
-        ra.Replace("ID", p->GetID());
-        return true;
-      })
-      .Replace("METHOD_NAME", SnakeToPascal(i->GetID()))
-      .Replace("METHOD_ORG_NAME", i->GetID());
-    return true;
-  });
+            [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& i) {
+              if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+                return false;
+              ra.Replace("TYPES", GetParameters(i->GetParameters(), true))
+                  .Repeat("REPLY_BODY", i->GetParameters(),
+                          [&](ReplaceAll& ra,
+                              const std::unique_ptr<tidl::Parameter>& p) {
+                            ra.Replace("ID", p->GetID());
+                            return true;
+                          })
+                  .Replace("METHOD_NAME", SnakeToPascal(i->GetID()))
+                  .Replace("METHOD_ORG_NAME", i->GetID());
+              return true;
+            });
 }
 
 void RsGroupGen::SetInterfaceBlock(ReplaceAll& ra, const Interface& iface) {
   ra.Repeat("ENUM", iface.GetEnums(),
-      [&](ReplaceAll& ra, const std::unique_ptr<Enum>& e) {
-    return SetEnum(ra, e);
-  });
+            [&](ReplaceAll& ra, const std::unique_ptr<Enum>& e) {
+              return SetEnum(ra, e);
+            });
 
   ra.Replace("IFACE_NAME", SnakeToPascal(iface.GetID()))
-    .Repeat("METHODS_PROTO", iface.GetDeclarations(),
-        [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d){
-      return SetMethod(ra, d);
-    })
-    .Repeat("METHODS", iface.GetDeclarations(),
-        [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d){
-      return SetMethod(ra, d);
-    })
-    .Repeat("DISPATCHES", iface.GetDeclarations(),
-        [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d) {
-      if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
-        return false;
-
-      ra.Replace("ID", d->GetID())
-        .Replace("SNAKE_ID", PascalToSnake(d->GetID()));
-      return true;
-    })
-    .Repeat("PRIVILEGES", iface.GetDeclarations(),
-        [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d) {
-          if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
-            return false;
-
-          std::vector<std::string> privileges;
-          for (auto& attr : d->GetAttributes()) {
-            if (attr->GetKey() != "privilege")
-              continue;
-
-            privileges.push_back(attr->GetValue());
-          }
-          if (privileges.empty())
-            return false;
-
-          ra.Repeat("PRIVILEGE", privileges,
-              [&](ReplaceAll& ra, const std::string& priv) {
-            ra.Replace("ID", priv);
-            return true;
-          })
-          .Replace("METHOD", SnakeToPascal(d->GetID()));
-          return true;
-        });
+      .Repeat("METHODS_PROTO", iface.GetDeclarations(),
+              [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d) {
+                return SetMethod(ra, d);
+              })
+      .Repeat("METHODS", iface.GetDeclarations(),
+              [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d) {
+                return SetMethod(ra, d);
+              })
+      .Repeat("DISPATCHES", iface.GetDeclarations(),
+              [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d) {
+                if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
+                  return false;
+
+                ra.Replace("ID", d->GetID())
+                    .Replace("SNAKE_ID", PascalToSnake(d->GetID()));
+                return true;
+              })
+      .Repeat("PRIVILEGES", iface.GetDeclarations(),
+              [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& d) {
+                if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
+                  return false;
+
+                std::vector<std::string> privileges;
+                for (auto& attr : d->GetAttributes()) {
+                  if (attr->GetKey() != "privilege") continue;
+
+                  privileges.push_back(attr->GetValue());
+                }
+                if (privileges.empty()) return false;
+
+                ra.Repeat("PRIVILEGE", privileges,
+                          [&](ReplaceAll& ra, const std::string& priv) {
+                            ra.Replace("ID", priv);
+                            return true;
+                          })
+                    .Replace("METHOD", SnakeToPascal(d->GetID()));
+                return true;
+              });
 }
 
-bool RsGroupGen::SetMethod(ReplaceAll& ra, const std::unique_ptr<Declaration>& d) {
-  if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
-    return false;
+bool RsGroupGen::SetMethod(ReplaceAll& ra,
+                           const std::unique_ptr<Declaration>& d) {
+  if (d->GetMethodType() == Declaration::MethodType::DELEGATE) return false;
 
   if (!d->GetComments().empty())
     ra.Replace("COMMENTS", AddIndent(2 * TAB_SIZE, d->GetComments()));
@@ -196,9 +192,9 @@ bool RsGroupGen::SetMethod(ReplaceAll& ra, const std::unique_ptr<Declaration>& d
                 if (p->GetParameterType().GetBaseType().IsDelegateType())
                   return false;
                 ra.Replace("ID", p->GetID())
-                  .Replace("HASH_ID", std::to_string(GetHashCode(p->GetID())))
-                  .Replace("TYPE", ConvertTypeToString(
-                      p->GetParameterType().GetBaseType()));
+                    .Replace("HASH_ID", GetHashCodeStr(p->GetID()))
+                    .Replace("TYPE", ConvertTypeToString(
+                                         p->GetParameterType().GetBaseType()));
                 return true;
               })
       .Repeat("DELEGATER_RECEIVER_BODY", (*d).GetParameters(),
@@ -206,14 +202,15 @@ bool RsGroupGen::SetMethod(ReplaceAll& ra, const std::unique_ptr<Declaration>& d
                 if (!p->GetParameterType().GetBaseType().IsDelegateType())
                   return false;
                 ra.Replace("ID", p->GetID())
-                  .Replace("HASH_ID", std::to_string(GetHashCode(p->GetID())))
-                  .Replace("TYPE", ConvertTypeToString(
-                      p->GetParameterType().GetBaseType()));
+                    .Replace("HASH_ID", GetHashCodeStr(p->GetID()))
+                    .Replace("TYPE", ConvertTypeToString(
+                                         p->GetParameterType().GetBaseType()));
                 return true;
               })
       .Repeat("RETURNS", (*d).GetParameters(),
               [&](ReplaceAll& ra, const std::unique_ptr<tidl::Parameter>& p) {
-                if (p->GetParameterType().GetDirection() == ParameterType::Direction::IN ||
+                if (p->GetParameterType().GetDirection() ==
+                        ParameterType::Direction::IN ||
                     p->GetParameterType().GetBaseType().IsDelegateType())
                   return false;
 
@@ -226,37 +223,35 @@ bool RsGroupGen::SetMethod(ReplaceAll& ra, const std::unique_ptr<Declaration>& d
 }
 
 void RsGroupGen::SetFile(ReplaceAll& ra,
-    const std::unique_ptr<tidl::Parameter>& i) {
+                         const std::unique_ptr<tidl::Parameter>& i) {
   std::string type = GetFullNameFromType(i->GetParameterType().GetBaseType());
 
   ra.Remove("FILE", type != "file")
-    .Remove("FILESLIST", type != "list_file")
-    .Remove("FILESARRAY", type != "array_file");
+      .Remove("FILESLIST", type != "list_file")
+      .Remove("FILESARRAY", type != "array_file");
 }
 
 bool RsGroupGen::SetSenderBody(ReplaceAll& ra,
-    const std::unique_ptr<tidl::Parameter>& i) {
+                               const std::unique_ptr<tidl::Parameter>& i) {
   if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT)
     return false;
 
   SetFile(ra, i);
 
-  ra.Replace("ID", i->GetID())
-    .Replace("HASH_ID", std::to_string(GetHashCode(i->GetID())));
+  ra.Replace("ID", i->GetID()).Replace("HASH_ID", GetHashCodeStr(i->GetID()));
   return true;
 }
 
 bool RsGroupGen::SetReceiverBody(ReplaceAll& ra,
-    const std::unique_ptr<tidl::Parameter>& i) {
+                                 const std::unique_ptr<tidl::Parameter>& i) {
   if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN)
-        return false;
+    return false;
   ra.Replace("ID", i->GetID());
   return true;
 }
 
 std::string RsGroupGen::GetRetExpr(const Declaration& decl) {
-  if (decl.GetType().ToString() == "void")
-    return "";
+  if (decl.GetType().ToString() == "void") return "";
   return "-> " + ConvertTypeToString(decl.GetType());
 }
 
index cc9c407f54c6327ef5709d964c275a06c4c64b2a..74895d3e6ef117e81c3056358f820bb1f168aacf 100644 (file)
@@ -36,11 +36,10 @@ void RsProxyGen::OnInitGen(std::ofstream& stream) {
               })
       .ReplaceBlock("MODULE_BLOCK", [&](ReplaceAll& ra) { SetModules(ra); })
       .Remove("BUNDLE_HEADER_BLOCK", RsGeneratorBase::HasBundle() != true)
-      .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
-      .Replace("HASH_REMOTE_EXCEPTION",
-               std::to_string(GetHashCode("[REMOTE_EXCEPTION]")))
-      .Replace("HASH_RESULT", std::to_string(GetHashCode("[RESULT]")))
-      .Replace("HASH_DELEGATE", std::to_string(GetHashCode("delegate")))
+      .Replace("HASH_METHOD", "[METHOD]"_hash)
+      .Replace("HASH_REMOTE_EXCEPTION", "[REMOTE_EXCEPTION]"_hash)
+      .Replace("HASH_RESULT", "[RESULT]"_hash)
+      .Replace("HASH_DELEGATE", "delegate"_hash)
       .Out(stream);
   stream.close();
 }
@@ -113,8 +112,7 @@ void RsProxyGen::SetDelegateBlock(ReplaceAll& ra, const Interface& iface) {
                 "RECEIVER_BODY", i->GetParameters(),
                 [&](ReplaceAll& ra, const std::unique_ptr<tidl::Parameter>& p) {
                   ra.Replace("ID", p->GetID())
-                      .Replace("HASH_ID",
-                               std::to_string(GetHashCode(p->GetID())))
+                      .Replace("HASH_ID", GetHashCodeStr(p->GetID()))
                       .Replace("TYPE",
                                ConvertTypeToString(
                                    p->GetParameterType().GetBaseType()));
@@ -167,7 +165,7 @@ bool RsProxyGen::SetMethod(ReplaceAll& ra,
                 return SetRegDelegaters(ra, i);
               })
       .Remove("HAS_RETURN", (*d).GetType().ToString() == "void")
-      .Replace("HASH_RESULT", std::to_string(GetHashCode("[RESULT]")))
+      .Replace("HASH_RESULT", "[RESULT]"_hash)
       .Replace("TYPE", [&]() { return ConvertTypeToString((*d).GetType()); });
   return true;
 }
@@ -196,7 +194,7 @@ bool RsProxyGen::SetSenderBody(ReplaceAll& ra,
                    return "";
                  return "&";
                })
-      .Replace("HASH_ID", std::to_string(GetHashCode(i->GetID())));
+      .Replace("HASH_ID", GetHashCodeStr(i->GetID()));
   return true;
 }
 
@@ -204,8 +202,7 @@ bool RsProxyGen::SetReceiverBody(ReplaceAll& ra,
                                  const std::unique_ptr<tidl::Parameter>& i) {
   if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN)
     return false;
-  ra.Replace("ID", i->GetID())
-      .Replace("HASH_ID", std::to_string(GetHashCode(i->GetID())));
+  ra.Replace("ID", i->GetID()).Replace("HASH_ID", GetHashCodeStr(i->GetID()));
 
   return true;
 }
index 07b69e919b552111024d9e5ed1b07e3c335a2ca3..013a710e250589b446bc39c26304b56e207cbc96 100644 (file)
@@ -40,11 +40,10 @@ void RsStubGen::OnInitGen(std::ofstream& stream) {
               })
       .ReplaceBlock("MODULE_BLOCK", [&](ReplaceAll& ra) { SetModules(ra); })
       .Remove("BUNDLE_HEADER_BLOCK", RsGeneratorBase::HasBundle() != true)
-      .Replace("HASH_METHOD", std::to_string(GetHashCode("[METHOD]")))
-      .Replace("HASH_REMOTE_EXCEPTION",
-               std::to_string(GetHashCode("[REMOTE_EXCEPTION]")))
-      .Replace("HASH_RESULT", std::to_string(GetHashCode("[RESULT]")))
-      .Replace("HASH_DELEGATE", std::to_string(GetHashCode("delegate")))
+      .Replace("HASH_METHOD", "[METHOD]"_hash)
+      .Replace("HASH_REMOTE_EXCEPTION", "[REMOTE_EXCEPTION]"_hash)
+      .Replace("HASH_RESULT", "[RESULT]"_hash)
+      .Replace("HASH_DELEGATE", "delegate"_hash)
       .Out(stream);
   stream.close();
 }
@@ -107,24 +106,22 @@ bool RsStubGen::SetDelegateIDs(ReplaceAll& ra,
 void RsStubGen::SetDelegateBlock(ReplaceAll& ra, const Interface& iface) {
   auto& decls = iface.GetDeclarations();
 
-  ra.Repeat(
-      "DELEGATES", decls,
-      [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& i) {
-        if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-          return false;
-        ra.Replace("TYPES", GetParameters(i->GetParameters(), true))
-            .Repeat(
-                "REPLY_BODY", i->GetParameters(),
-                [&](ReplaceAll& ra, const std::unique_ptr<tidl::Parameter>& p) {
-                  ra.Replace("ID", p->GetID())
-                      .Replace("HASH_ID",
-                               std::to_string(GetHashCode(p->GetID())));
-                  return true;
-                })
-            .Replace("METHOD_NAME", SnakeToPascal(i->GetID()))
-            .Replace("METHOD_ORG_NAME", i->GetID());
-        return true;
-      });
+  ra.Repeat("DELEGATES", decls,
+            [&](ReplaceAll& ra, const std::unique_ptr<Declaration>& i) {
+              if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+                return false;
+              ra.Replace("TYPES", GetParameters(i->GetParameters(), true))
+                  .Repeat("REPLY_BODY", i->GetParameters(),
+                          [&](ReplaceAll& ra,
+                              const std::unique_ptr<tidl::Parameter>& p) {
+                            ra.Replace("ID", p->GetID())
+                                .Replace("HASH_ID", GetHashCodeStr(p->GetID()));
+                            return true;
+                          })
+                  .Replace("METHOD_NAME", SnakeToPascal(i->GetID()))
+                  .Replace("METHOD_ORG_NAME", i->GetID());
+              return true;
+            });
 }
 
 void RsStubGen::SetInterfaceBlock(ReplaceAll& ra, const Interface& iface) {
@@ -214,7 +211,7 @@ bool RsStubGen::SetMethod(ReplaceAll& ra,
                 ra.Remove("IS_OUT_DIR", p->GetParameterType().GetDirection() ==
                                             ParameterType::Direction::OUT)
                     .Replace("ID", p->GetID())
-                    .Replace("HASH_ID", std::to_string(GetHashCode(p->GetID())))
+                    .Replace("HASH_ID", GetHashCodeStr(p->GetID()))
                     .Replace("TYPE", ConvertTypeToString(
                                          p->GetParameterType().GetBaseType()));
                 return true;
@@ -224,7 +221,7 @@ bool RsStubGen::SetMethod(ReplaceAll& ra,
                 if (!p->GetParameterType().GetBaseType().IsDelegateType())
                   return false;
                 ra.Replace("ID", p->GetID())
-                    .Replace("HASH_ID", std::to_string(GetHashCode(p->GetID())))
+                    .Replace("HASH_ID", GetHashCodeStr(p->GetID()))
                     .Replace("TYPE", ConvertTypeToString(
                                          p->GetParameterType().GetBaseType()));
                 return true;
@@ -237,8 +234,7 @@ bool RsStubGen::SetMethod(ReplaceAll& ra,
                   return false;
 
                 ra.Replace("ID", p->GetID())
-                    .Replace("HASH_ID",
-                             std::to_string(GetHashCode(p->GetID())));
+                    .Replace("HASH_ID", GetHashCodeStr(p->GetID()));
                 return true;
               })
       .Replace("IDS", GetParameterIDsWithDir((*d).GetParameters()))