c++/fix: properly handle $out for f_type rule appied to return
ref
@@ -23,7 +23,7 @@ use crate::{
foreign_from_rust_convert_method_output, foreign_to_rust_convert_method_inputs,
unpack_from_heap_pointer,
},
- ForeignTypeInfo, TypeMap, FROM_VAR_TEMPLATE, TO_VAR_TEMPLATE,
+ ForeignTypeInfo, TypeMap, FROM_VAR_TEMPLATE, TO_VAR_TEMPLATE, TO_VAR_TYPE_TEMPLATE,
},
types::{ForeignerClassInfo, MethodAccess, MethodVariant, SelfTypeVariant},
WRITE_TO_MEM_FAILED_MSG,
@@ -180,6 +180,8 @@ May be you need to use `private constructor = empty;` syntax?",
method.arg_names_without_self().map(|x| x.into()).collect();
let ret_name = new_unique_name(&known_names, "ret");
known_names.insert(ret_name.clone());
+ let conv_ret = new_unique_name(&known_names, "conv_ret");
+ known_names.insert(conv_ret.clone());
let cpp_args_with_types =
cpp_code::cpp_generate_args_with_types(f_method, method.arg_names_without_self());
@@ -207,14 +209,29 @@ May be you need to use `private constructor = empty;` syntax?",
let method_name = method.short_name().as_str().to_string();
let (cpp_ret_type, convert_ret_for_cpp) =
if let Some(cpp_converter) = f_method.output.cpp_converter.as_ref() {
- (
- cpp_converter.typename.clone(),
- cpp_converter
+ let cpp_ret_type = cpp_converter.typename.clone();
+ let conv_code = cpp_converter
.converter
- .replace(FROM_VAR_TEMPLATE, &ret_name),
+ .replace(FROM_VAR_TEMPLATE, &ret_name);
+ if conv_code.contains(TO_VAR_TYPE_TEMPLATE) {
+ let conv_code = conv_code
+ .replace(
+ TO_VAR_TYPE_TEMPLATE,
+ &format!("{} {}", cpp_ret_type, conv_ret),
+ )
+ .replace(TO_VAR_TEMPLATE, &conv_ret);
+ (
+ cpp_ret_type,
+ format!("{}\n return {};", conv_code, conv_ret),
)
} else {
- (f_method.output.as_ref().name.clone(), "ret".to_string())
+ (cpp_ret_type, format!(" return {};", conv_code))
+ }
+ } else {
+ (
+ f_method.output.as_ref().name.clone(),
+ format!(" return {};", ret_name),
+ )
};
//rename types like "struct Foo" to "Foo" to make VC++ compiler happy
let cpp_ret_type = cpp_ret_type.as_str().replace("struct", "");
@@ -263,7 +280,7 @@ May be you need to use `private constructor = empty;` syntax?",
&mut inline_impl,
r#"
{c_ret_type} {ret} = {c_func_name}({cpp_args_for_c});
- return {convert_ret_for_cpp};
+{convert_ret_for_cpp}
}}
"#,
c_ret_type = f_method.output.as_ref().name,
@@ -337,7 +354,7 @@ May be you need to use `private constructor = empty;` syntax?",
&mut inline_impl,
r#"
{c_ret_type} {ret} = {c_func_name}(this->self_{cpp_args_for_c});
- return {convert_ret_for_cpp};
+{convert_ret_for_cpp}
}}
"#,
convert_ret_for_cpp = convert_ret_for_cpp,
