summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2021-10-06 16:57:45 +0900
committerHwankyu Jhun <h.jhun@samsung.com>2021-10-06 17:41:45 +0900
commitb8cb8c8b01e5a33be8156b4d7a167f56722db014 (patch)
treef7671f6569bab119c39579cb38fa172fd27eef4a
parentb4865ab223555d64bc9a2d095feb9f49f7d21324 (diff)
downloadtidl-b8cb8c8b01e5a33be8156b4d7a167f56722db014.tar.gz
tidl-b8cb8c8b01e5a33be8156b4d7a167f56722db014.tar.bz2
tidl-b8cb8c8b01e5a33be8156b4d7a167f56722db014.zip
Fix bugs about C Generator
The generated codes make build break issues. Change-Id: I1e0b687efff38d967e15c50ad241b5d8a4b41c89 Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r--idlc/gen/c_body_gen_base.cc54
-rw-r--r--idlc/gen/c_gen_base.cc2
-rw-r--r--idlc/gen/c_proxy_body_gen.cc12
-rw-r--r--idlc/gen/c_proxy_body_gen.h2
-rw-r--r--idlc/gen/c_proxy_body_gen_cb.h5
-rw-r--r--idlc/gen/c_stub_body_gen.cc13
-rw-r--r--idlc/gen/c_stub_body_gen_cb.h10
7 files changed, 31 insertions, 67 deletions
diff --git a/idlc/gen/c_body_gen_base.cc b/idlc/gen/c_body_gen_base.cc
index e1c3cf7..573a1c9 100644
--- a/idlc/gen/c_body_gen_base.cc
+++ b/idlc/gen/c_body_gen_base.cc
@@ -213,15 +213,7 @@ std::string CBodyGeneratorBase::GenArrayParcelRead(
type.ToString() == "array") {
code = ReplaceAll(CB_STRUCTURE_ARRAY_USER_DEFINED_PARCEL_READ, "<PREFIX>",
GetHandlePrefix());
-
- std::string name;
- auto* meta_type = type.GetMetaType();
- if (meta_type == nullptr)
- name = type.ToString();
- else
- name = GetFullNameFromType(*meta_type);
-
- code = ReplaceAll(code, "<NAME>", name);
+ code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
} else if (type.ToString() == "bundle") {
code = std::string(CB_STRUCTURE_ARRAY_BUNDLE_PARCEL_READ);
} else if (type.ToString() == "string" || type.ToString() == "file") {
@@ -247,15 +239,7 @@ std::string CBodyGeneratorBase::GenArrayElementsFree(
type.ToString() == "array") {
code = ReplaceAll(CB_STRUCTURE_ARRAY_USER_DEFINED_FREE, "<PREFIX>",
GetHandlePrefix());
-
- std::string name;
- auto* meta_type = type.GetMetaType();
- if (meta_type == nullptr)
- name = type.ToString();
- else
- name = GetFullNameFromType(*meta_type);
-
- code = ReplaceAll(code, "<NAME>", name);
+ code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
} else if (type.ToString() == "bundle") {
code = std::string(CB_STRUCTURE_ARRAY_BUNDLE_FREE);
} else if (type.ToString() == "string" || type.ToString() == "file") {
@@ -307,15 +291,7 @@ std::string CBodyGeneratorBase::GenListDataFree(
type.ToString() == "array") {
code = ReplaceAll(CB_STRUCTURE_LIST_USER_DEFINED_FREE, "<PREFIX>",
GetHandlePrefix());
-
- std::string name;
- auto* meta_type = type.GetMetaType();
- if (meta_type == nullptr)
- name = type.ToString();
- else
- name = GetFullNameFromType(*meta_type);
-
- code = ReplaceAll(code, "<NAME>", name);
+ code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
} else if (type.ToString() == "bundle") {
code = std::string(CB_STRUCTURE_LIST_BUNDLE_FREE);
} else if (type.ToString() == "string" || type.ToString() == "flie") {
@@ -364,15 +340,7 @@ std::string CBodyGeneratorBase::GenListParcelRead(
type.ToString() == "array") {
code = ReplaceAll(CB_STRUCTURE_LIST_USER_DEFINED_PARCEL_READ, "<PREFIX>",
GetHandlePrefix());
-
- std::string name;
- auto* meta_type = type.GetMetaType();
- if (meta_type == nullptr)
- name = type.ToString();
- else
- name = GetFullNameFromType(*meta_type);
-
- code = ReplaceAll(code, "<NAME>", name);
+ code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
} else if (type.ToString() == "bundle") {
code = std::string(CB_STRUCTURE_LIST_BUNDLE_PARCEL_READ);
} else if (type.ToString() == "string" || type.ToString() == "file") {
@@ -401,15 +369,7 @@ std::string CBodyGeneratorBase::GenListAdd(
type.ToString() == "array") {
code = ReplaceAll(CB_STRUCTURE_LIST_USER_DEFINED_ADD, "<PREFIX>",
GetHandlePrefix());
-
- std::string name;
- auto* meta_type = type.GetMetaType();
- if (meta_type == nullptr)
- name = type.ToString();
- else
- name = GetFullNameFromType(*meta_type);
-
- code = ReplaceAll(code, "<NAME>", name);
+ code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
} else if (type.ToString() == "bundle") {
code = std::string(CB_STRUCTURE_LIST_BUNDLE_ADD);
} else if (type.ToString() == "string" || type.ToString() == "file") {
@@ -489,9 +449,7 @@ std::string CBodyGeneratorBase::GenBaseElementFree(
type.ToString() == "array") {
code = ReplaceAll(CB_STRUCTURE_BASE_USER_DEFINED_FREE, "<PREFIX>",
GetHandlePrefix());
-
- std::string name = GetFullNameFromType(type);
- code = ReplaceAll(code, "<NAME>", name);
+ code = ReplaceAll(code, "<NAME>", GetFullNameFromType(type));
code = ReplaceAll(code, "<ELEMENT_NAME>", elm->GetID());
} else if (type.ToString() == "bundle") {
code = ReplaceAll(CB_STRUCTURE_BASE_BUNDLE_FREE, "<ELEMENT_NAME>",
diff --git a/idlc/gen/c_gen_base.cc b/idlc/gen/c_gen_base.cc
index b8b40cf..1787130 100644
--- a/idlc/gen/c_gen_base.cc
+++ b/idlc/gen/c_gen_base.cc
@@ -464,7 +464,7 @@ std::string CGeneratorBase::GetHandlePrefix() {
if (!HasNamespace())
return prefix;
- return prefix + "_" + GetFileNamespace() + "_";
+ return prefix + "_" + GetFileNamespace();
}
const std::map<std::string, std::unique_ptr<Structure>>&
diff --git a/idlc/gen/c_proxy_body_gen.cc b/idlc/gen/c_proxy_body_gen.cc
index d24488d..b986ec3 100644
--- a/idlc/gen/c_proxy_body_gen.cc
+++ b/idlc/gen/c_proxy_body_gen.cc
@@ -225,7 +225,7 @@ std::string CProxyBodyGen::GenDelegateParcelRead(const Interface& iface,
// @see CB_INTERFACE_DELEGATE_BUNDLE_ARG_FREE
// @see CB_INTERFACE_DELEGATE_STRING_ARG_FREE
std::string CProxyBodyGen::GenDelegateArgsFree(const Interface& iface,
- const Declaration& decl) {
+ const Declaration& decl, bool& has_free) {
std::string code;
for (auto& p : decl.GetParameters().GetParams()) {
std::string param_free_code;
@@ -242,12 +242,15 @@ std::string CProxyBodyGen::GenDelegateArgsFree(const Interface& iface,
std::string name = GetFullNameFromType(type, iface);
param_free_code = ReplaceAll(param_free_code, "<NAME>", name);
param_free_code = ReplaceAll(param_free_code, "<ARG>", p->GetID());
+ has_free = true;
} else if (type.ToString() == "bundle") {
param_free_code = ReplaceAll(CB_INTERFACE_DELEGATE_BUNDLE_ARG_FREE,
"<ARG>", p->GetID());
+ has_free = true;
} else if (type.ToString() == "string" || type.ToString() == "file") {
param_free_code = ReplaceAll(CB_INTERFACE_DELEGATE_STRING_ARG_FREE,
"<ARG>", p->GetID());
+ has_free = true;
}
code += param_free_code;
@@ -281,10 +284,13 @@ void CProxyBodyGen::GenInterfaceDelegateBase(std::ofstream& stream,
GenDelegateArgsDecl(iface, decl));
code = ReplaceAll(code, "<DELEGATE_PARCEL_READ>",
GenDelegateParcelRead(iface, decl));
- code = ReplaceAll(code, "<DELEGATE_ARGS_FREE>",
- GenDelegateArgsFree(iface, decl));
+ bool has_free = false;
+ std::string delegate_args_free = GenDelegateArgsFree(iface, decl, has_free);
+ code = ReplaceAll(code, "<DELEGATE_ARGS_FREE>", delegate_args_free);
code = ReplaceAll(code, "<DELEGATE_CALLBACK_ARGS>",
GenDelegateCallbackArgs(decl));
+ code = ReplaceAll(code, "<GOTO_STATEMENT>",
+ has_free ? "out:" + NLine(1) : "");
stream << SmartIndent(code);
}
diff --git a/idlc/gen/c_proxy_body_gen.h b/idlc/gen/c_proxy_body_gen.h
index 3c4885a..7f940f3 100644
--- a/idlc/gen/c_proxy_body_gen.h
+++ b/idlc/gen/c_proxy_body_gen.h
@@ -62,7 +62,7 @@ class CProxyBodyGen : public CBodyGeneratorBase {
std::string GenDelegateParcelRead(const Interface& iface,
const Declaration& decl);
std::string GenDelegateArgsFree(const Interface& iface,
- const Declaration& decl);
+ const Declaration& decl, bool& has_free);
std::string GenDelegateCallbackArgs(const Declaration& decl);
std::string GenMethodAsyncBase(const Interface& iface,
diff --git a/idlc/gen/c_proxy_body_gen_cb.h b/idlc/gen/c_proxy_body_gen_cb.h
index c6c9091..3d2bb86 100644
--- a/idlc/gen/c_proxy_body_gen_cb.h
+++ b/idlc/gen/c_proxy_body_gen_cb.h
@@ -60,6 +60,7 @@ typedef struct <PREFIX>_<NAME>_<DELEGATE_NAME>_s {
* <DELEGATE_PARCEL_READ> The implementation to read the arguments from the parcel.
* <DELEGATE_ARGS_FREE> The implementation to release the allocated arguments.
* <DELEGATE_CALLBACK_ARGS> The arguments of the delegate callback.
+ * <GOTO_STATEMENT> The statement label.
*/
constexpr const char CB_INTERFACE_DELEGATE_BASE[] =
R"__c_cb(
@@ -320,7 +321,7 @@ static void __<PREFIX>_<NAME>_<DELEGATE_NAME>_delegate_handler(GList **delegates
}
}
-out:
+<GOTO_STATEMENT>
<DELEGATE_ARGS_FREE>
}
)__c_cb";
@@ -414,7 +415,7 @@ if (<ARG>)
*/
constexpr const char CB_INTERFACE_DELEGATE_TABLE[] =
R"__c_cb(
-static <PREFIX>_delegate_cb __<PREFIX>_<NAME>_delegate_table[] = {
+static rpc_port_proxy_delegate_cb __<PREFIX>_<NAME>_delegate_table[] = {
<DELEGATE_HANDLERS>
};
)__c_cb";
diff --git a/idlc/gen/c_stub_body_gen.cc b/idlc/gen/c_stub_body_gen.cc
index 0d571cd..60e168a 100644
--- a/idlc/gen/c_stub_body_gen.cc
+++ b/idlc/gen/c_stub_body_gen.cc
@@ -58,10 +58,7 @@ void CStubBodyGen::GenThreadEnableDefinition(std::ofstream& stream) {
// @see #CB_INTERFACE_METHOD_HANDLER_TYPE
void CStubBodyGen::GenInterfaceMethodHandlerType(std::ofstream& stream) {
- std::string code = ReplaceAll(CB_INTERFACE_METHOD_HANDLER_TYPE, "<PREFIX>",
- GetHandlePrefix());
-
- stream << SmartIndent(code);
+ stream << SmartIndent(CB_INTERFACE_METHOD_HANDLER_TYPE);
}
void CStubBodyGen::GenInterfaceEnums(std::ofstream& stream) {
@@ -479,10 +476,14 @@ std::string CStubBodyGen::GenMethodHandlerParcelWrite(const Interface& iface,
if (decl.GetMethodType() != Declaration::MethodType::SYNC)
return code;
+ std::string prefix = GetHandlePrefix();
+ std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
+ code = ReplaceAll(CB_INTERFACE_METHOD_PARCEL_WRITE_PRE, "<UPPERCASE_PREFIX>",
+ prefix);
+
std::string name = iface.GetID();
std::transform(name.begin(), name.end(), name.begin(), ::toupper);
- code = ReplaceAll(CB_INTERFACE_METHOD_PARCEL_WRITE_PRE, "<UPPERCASE_NAME>",
- name);
+ code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
std::string parcel_write_code;
for (auto& p : decl.GetParameters().GetParams()) {
diff --git a/idlc/gen/c_stub_body_gen_cb.h b/idlc/gen/c_stub_body_gen_cb.h
index 4d25311..877485a 100644
--- a/idlc/gen/c_stub_body_gen_cb.h
+++ b/idlc/gen/c_stub_body_gen_cb.h
@@ -22,12 +22,9 @@ R"__c_cb(
#define TIDL_THREAD_ENABLE 1
)__c_cb";
-/**
- * <PREFIX> The prefix of the interface.
- */
constexpr const char CB_INTERFACE_METHOD_HANDLER_TYPE[] =
R"__c_cb(
-typedef int (*<PREFIX>_method_handler)(rpc_port_h port, rpc_port_parcel_h parcel, void *data);
+typedef int (*rpc_port_stub_method_handler)(rpc_port_h port, rpc_port_parcel_h parcel, void *data);
)__c_cb";
/**
@@ -819,6 +816,7 @@ if (context_->callback.<METHOD_NAME>)
)__c_cb";
/**
+ * <UPPERCASE_PREFIX> The uppercase prefix of the interface.
* <UPPERCASE_NAME> The uppercase name of the interface.
*/
constexpr const char CB_INTERFACE_METHOD_PARCEL_WRITE_PRE[] =
@@ -833,7 +831,7 @@ rpc_port_parcel_get_header(parcel_, &header_);
rpc_port_parcel_header_set_tag(header_, TIDL_VERSION);
rpc_port_parcel_header_set_seq_num(header_, seq_num_);
-rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_<UPPERCASE_NAME>_METHOD_RESULT_);
+rpc_port_parcel_write_int32(parcel_, <UPPERCASE_PREFIX>_<UPPERCASE_NAME>_METHOD_RESULT_);
)__c_cb";
constexpr const char CB_INTERFACE_METHOD_PARCEL_WRITE_POST[] =
@@ -1024,7 +1022,7 @@ static int __<PREFIX>_<NAME>_set_access_control(void)
return ret;
}
-int <PREFIX>_<NAME>_register(rpc_port_stub_<NAME>_callback_s *callback, void *user_data)
+int <PREFIX>_<NAME>_register(<PREFIX>_<NAME>_callback_s *callback, void *user_data)
{
int ret;