Add missing implementation about ref keyword 25/288725/2
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 22 Feb 2023 06:23:34 +0000 (06:23 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 22 Feb 2023 06:38:57 +0000 (06:38 +0000)
If there is the 'ref' keyword, we should read and wrtie the argument.

Change-Id: I027cf6cc3101b474cc8ba07a7428a98d6566c488
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/gen/version2/c_proxy_body_generator.cc
idlc/gen/version2/c_proxy_body_generator.hh
idlc/gen/version2/c_proxy_body_generator_cb.hh
idlc/gen/version2/c_stub_body_generator.cc

index 6112edaf5f30e392242faa8a7445785d9da4a3ed..54380df2bb88e1b539a5c50d7a91850c59e05b11 100644 (file)
@@ -163,7 +163,7 @@ std::string CProxyBodyGenerator::GenMethodArgs(const Interface& iface,
   std::string code;
   for (const auto& param : decl.GetParameters()) {
     auto& param_type = param->GetParameterType();
-    if (param_type.GetDirection() != ParameterType::Direction::OUT)
+    if (param_type.GetDirection() == ParameterType::Direction::IN)
       continue;
 
     auto& type = param_type.GetBaseType();
@@ -197,37 +197,46 @@ std::string CProxyBodyGenerator::GenMethodUnitMapWrite(const Interface& iface,
   std::string code;
   for (const auto& param : decl.GetParameters()) {
     auto& param_type = param->GetParameterType();
-    if (param_type.GetDirection() != ParameterType::Direction::IN)
+    if (param_type.GetDirection() == ParameterType::Direction::OUT)
       continue;
 
+    std::string arg = param->GetID();
+    if (param_type.GetDirection() == ParameterType::Direction::REF)
+      arg = "*" + arg;
+
     auto& type = param_type.GetBaseType();
     if (type.GetUserDefinedType() == BaseType::UserType::DELEGATE) {
       code += ReplaceAll(CB_INTERFACE_METHOD_DELEGATE_UNIT_MAP_WRITE)
-          .Change("<ARG>", param->GetID());
+          .Change("<ARG_NAME>", param->GetID())
+          .Change("<ARG>", arg);
     } else if (type.GetUserDefinedType() == BaseType::UserType::ENUM) {
       code += ReplaceAll(CB_INTERFACE_METHOD_ENUM_UNIT_MAP_WRITE)
           .Change("<ARG_NAME>", param->GetID())
-          .Change("<ARG>", param->GetID());
+          .Change("<ARG>", arg);
     } else if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) {
       code += ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_UNIT_MAP_WRITE)
           .Change("<TYPE_NAME>", GetFullNameFromType(type, iface))
-          .Change("<ARG>", param->GetID());
+          .Change("<ARG_NAME>", param->GetID())
+          .Change("<ARG>", arg);
       code += GetPrivateSharingString(type, iface, "h->port", param->GetID());
     } else if (type.ToString() == "bundle") {
       code += ReplaceAll(CB_INTERFACE_METHOD_BUNDLE_UNIT_MAP_WRITE)
-          .Change("<ARG>", param->GetID());
+          .Change("<ARG_NAME>", param->GetID())
+          .Change("<ARG>", arg);
     } else if (type.ToString() == "string") {
       code += ReplaceAll(CB_INTERFACE_METHOD_STRING_UNIT_MAP_WRITE)
-          .Change("<ARG>", param->GetID());
+          .Change("<ARG_NAME>", param->GetID())
+          .Change("<ARG>", arg);
     } else if (type.ToString() == "file") {
       code += ReplaceAll(CB_INTERFACE_METHOD_STRING_UNIT_MAP_WRITE)
-          .Change("<ARG>", param->GetID());
+          .Change("<ARG_NAME>", param->GetID())
+          .Change("<ARG>", arg);
       code += GetPrivateSharingString(type, iface, "h->port", param->GetID());
     } else {
       code += ReplaceAll(CB_INTERFACE_METHOD_BASE_UNIT_MAP_WRITE)
           .Change("<TYPE_NAME>", GetFullNameFromType(type, iface))
           .Change("<ARG_NAME>",  param->GetID())
-          .Change("<ARG>", param->GetID());
+          .Change("<ARG>", arg);
     }
   }
 
@@ -272,7 +281,7 @@ std::string CProxyBodyGenerator::GenMethodUnitMapReadBase(
   std::string code;
   if (type.GetUserDefinedType() == BaseType::UserType::DELEGATE ||
       type.GetUserDefinedType() == BaseType::UserType::STRUCTURE ||
-      type.GetMetaType() != nullptr) {
+      type.GetMetaType() != nullptr || type.GetKeyType() != nullptr) {
     code = ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_UNIT_MAP_READ)
         .Change("<TYPE_NAME>", GetFullNameFromType(type, iface))
         .Change("<ARG_NAME>", arg_name)
@@ -299,18 +308,42 @@ std::string CProxyBodyGenerator::GenMethodUnitMapReadBase(
   return code;
 }
 
+std::string CProxyBodyGenerator::GenMethodRefFree(
+    const Interface& iface, const BaseType& type, const std::string& arg) {
+  std::string code;
+  if (type.GetUserDefinedType() == BaseType::UserType::DELEGATE ||
+      type.GetUserDefinedType() == BaseType::UserType::STRUCTURE ||
+      type.GetMetaType() != nullptr || type.GetKeyType() != nullptr) {
+    code = ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_REF_FREE)
+        .Change("<PREFIX>", GetHandlePrefix())
+        .Change("<NAME>", GetFullNameFromType(type, iface))
+        .Change("<ARG>", arg);
+  } else if (type.ToString() == "bundle") {
+    code = ReplaceAll(CB_INTERFACE_METHOD_BUNDLE_REF_FREE)
+        .Change("<ARG>", arg);
+  } else if (type.ToString() == "string" || type.ToString() == "file") {
+    code = ReplaceAll(CB_INTERFACE_METHOD_STRING_REF_FREE)
+        .Change("<ARG>", arg);
+  }
+
+  return code;
+}
+
 std::string CProxyBodyGenerator::GenMethodUnitMapRead(const Interface& iface,
     const Declaration& decl) {
   std::string code;
   std::string parcel_read_code;
   for (const auto& p : decl.GetParameters()) {
     auto& param_type = p->GetParameterType();
-    if (param_type.GetDirection() != ParameterType::Direction::OUT)
+    if (param_type.GetDirection() == ParameterType::Direction::IN)
       continue;
 
     auto& type = param_type.GetBaseType();
     code += GenMethodUnitMapReadBase(iface, type, p->GetID(),
         "new_" + p->GetID());
+    if (param_type.GetDirection() == ParameterType::Direction::REF)
+      code += GenMethodRefFree(iface, type, p->GetID());
+
     code += ReplaceAll(CB_INTERFACE_METHOD_PARAM_SET, "<PARAM>",
         p->GetID());
   }
index 14f75b18d9c2dcfb0afafcc70182675ef0227833..c4bb347296e887ca31bcf6187db226ea7b559ea6 100644 (file)
@@ -60,6 +60,8 @@ class CProxyBodyGenerator : public CBodyGeneratorBase {
       const std::string& arg);
   std::string GenMethodUnitMapRead(const Interface& iface,
       const Declaration& decl);
+  std::string GenMethodRefFree(const Interface& iface,
+      const BaseType& type, const std::string& arg);
   void GenMethodBase(std::ofstream& stream, const Interface& iface,
       const Declaration& decl);
   void GenInterfaceMethodBase(std::ofstream& stream, const Interface& iface,
index ec64a436a53a3b2df4b1bd05736d3870f164f3e2..d2e1ca47d15104eb8d574004512cd36901e52470 100644 (file)
@@ -1063,40 +1063,45 @@ R"__c_cb(
 )__c_cb";
 
 /**
+ * <ARG_NAME>  The name of the argument.
  * <TYPE_NAME> The type name of the argument.
  * <ARG> The argument.
  */
 constexpr const char CB_INTERFACE_METHOD_USER_DEFINED_UNIT_MAP_WRITE[] =
 R"__c_cb(
-rpc_port_unit_map_write_<TYPE_NAME>(map_, "<ARG>", <ARG>);
+rpc_port_unit_map_write_<TYPE_NAME>(map_, "<ARG_NAME>", <ARG>);
 )__c_cb";
 
 /**
+ * <ARG_NAME>  The name of the argument.
  * <ARG> The argument.
  */
 constexpr const char CB_INTERFACE_METHOD_DELEGATE_UNIT_MAP_WRITE[] =
 R"__c_cb(
-rpc_port_unit_map_write_delegate(map_, "<ARG>", (rpc_port_delegate_h)<ARG>);
+rpc_port_unit_map_write_delegate(map_, "<ARG_NAME>", (rpc_port_delegate_h)<ARG>);
 )__c_cb";
 
 /**
+ * <ARG_NAME>  The name of the argument.
  * <ARG> The argument.
  */
 constexpr const char CB_INTERFACE_METHOD_BUNDLE_UNIT_MAP_WRITE[] =
 R"__c_cb(
-rpc_port_unit_map_write_bundle(map_, "<ARG>", <ARG>);
+rpc_port_unit_map_write_bundle(map_, "<ARG_NAME>", <ARG>);
 )__c_cb";
 
 /**
+ * <ARG_NAME>  The name of the argument.
  * <ARG> The argument.
  */
 constexpr const char CB_INTERFACE_METHOD_STRING_UNIT_MAP_WRITE[] =
 R"__c_cb(
-rpc_port_unit_map_write_string(map_, "<ARG>", <ARG>);
+rpc_port_unit_map_write_string(map_, "<ARG_NAME>", <ARG>);
 )__c_cb";
 
 /**
  * <TYPE_NAME> The type name of the argument.
+ * <ARG_NAME>  The name of the argument.
  * <ARG> The argument.
  */
 constexpr const char CB_INTERFACE_METHOD_BASE_UNIT_MAP_WRITE[] =
@@ -1106,6 +1111,7 @@ rpc_port_unit_map_write_<TYPE_NAME>(map_, "<ARG_NAME>", <ARG>);
 
 /**
  * <TYPE_NAME> The type name of the argument.
+ * <ARG_NAME>  The name of the argument.
  * <ARG> The argument.
  */
 constexpr const char CB_INTERFACE_METHOD_ENUM_UNIT_MAP_WRITE[] =
@@ -1193,6 +1199,32 @@ R"__c_cb(
 *<PARAM> = new_<PARAM>;
 )__c_cb";
 
+/**
+ * <PREFIX> The prefix of the reference argument.
+ * <NAME> The name of the reference argument.
+ * <ARG> The argument.
+ */
+constexpr const char CB_INTERFACE_METHOD_USER_DEFINED_REF_FREE[] =
+R"__c_cb(
+<PREFIX>_<NAME>_destroy(*<ARG>);
+)__c_cb";
+
+/**
+ * <ARG> The argument.
+ */
+constexpr const char CB_INTERFACE_METHOD_BUNDLE_REF_FREE[] =
+R"__c_cb(
+bundle_free(*<ARG>);
+)__c_cb";
+
+/**
+ * <ARG> The argument.
+ */
+constexpr const char CB_INTERFACE_METHOD_STRING_REF_FREE[] =
+R"__c_cb(
+free(*<ARG>);
+)__c_cb";
+
 /**
  * <ARG> The argument.
  */
index e5a865e874e47d9a5e1000baa93667b70d709da7..96c2169ee19f74666298417d3dd57ea1499f9304 100644 (file)
@@ -426,11 +426,11 @@ std::string CStubBodyGenerator::GenMethodUnitMapRead(const Interface& iface,
   for (const auto& p : decl.GetParameters()) {
     std::string parcel_read_code;
     auto& param_type = p->GetParameterType();
-    if (param_type.GetDirection() != ParameterType::Direction::IN)
+    if (param_type.GetDirection() == ParameterType::Direction::OUT)
       continue;
 
     auto& type = param_type.GetBaseType();
-    if (type.GetUserDefinedType() == BaseType::UserType::DELEGATE){
+    if (type.GetUserDefinedType() == BaseType::UserType::DELEGATE) {
       parcel_read_code = ReplaceAll(CB_INTERFACE_METHOD_DELEGATE_UNIT_MAP_READ)
           .Change("<PREFIX>", GetHandlePrefix())
           .Change("<TYPE_NAME>", GetFullNameFromType(type, iface))
@@ -441,7 +441,8 @@ std::string CStubBodyGenerator::GenMethodUnitMapRead(const Interface& iface,
           .Change("<ARG_NAME>", p->GetID())
           .Change("<ARG>", p->GetID());
     } else if (type.GetUserDefinedType() == BaseType::UserType::STRUCTURE ||
-        type.GetMetaType() != nullptr) {
+        type.GetMetaType() != nullptr ||
+        type.GetKeyType() != nullptr) {
       parcel_read_code = ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_UNIT_MAP_READ)
           .Change("<TYPE_NAME>", GetFullNameFromType(type, iface))
           .Change("<ARG_NAME>", p->GetID())
@@ -524,8 +525,8 @@ std::string CStubBodyGenerator::GenMethodUnitMapWriteBase(
          .Change("<ARG_NAME>", arg_name)
          .Change("<ARG>", arg);
   } else if (type.IsUserDefinedType() ||
-             type.ToString() == "list" ||
-             type.ToString() == "array") {
+      type.GetMetaType() != nullptr ||
+      type.GetKeyType() != nullptr) {
     parcel_write_code = ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_UNIT_MAP_WRITE)
         .Change("<TYPE_NAME>", GetFullNameFromType(type, iface))
         .Change("<ARG_NAME>", arg_name)
@@ -600,8 +601,8 @@ std::string CStubBodyGenerator::GenMethodHandlerArgsFree(const Interface& iface,
     auto& type = param_type.GetBaseType();
     if (type.GetUserDefinedType() == BaseType::UserType::STRUCTURE  ||
         type.GetUserDefinedType() == BaseType::UserType::DELEGATE  ||
-        type.ToString() == "list" ||
-        type.ToString() == "array") {
+        type.GetMetaType() != nullptr ||
+        type.GetKeyType() != nullptr) {
       free_code = ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_FREE,
           "<PREFIX>", GetHandlePrefix());
       free_code = ReplaceAll(free_code, "<NAME>",
@@ -624,8 +625,8 @@ std::string CStubBodyGenerator::GenMethodHandlerArgsFree(const Interface& iface,
     auto& type = decl.GetType();
     if (type.GetUserDefinedType() == BaseType::UserType::STRUCTURE  ||
         type.GetUserDefinedType() == BaseType::UserType::DELEGATE  ||
-        type.ToString() == "list" ||
-        type.ToString() == "array") {
+        type.GetMetaType() != nullptr ||
+        type.GetKeyType() != nullptr) {
       free_code = ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_FREE,
           "<PREFIX>", GetHandlePrefix());
       free_code = ReplaceAll(free_code, "<NAME>",