Skip to content

Commit

Permalink
codegen: Handle gobject_ffi for functions as well
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Jun 1, 2024
1 parent 50fed1e commit 6a8847c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/codegen/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn generate(
)?;

if !only_declaration {
let body = body_chunk(env, analysis).to_code(env);
let body = body_chunk(env, analysis, parent_type_id).to_code(env);
for s in body {
writeln!(w, "{}{}", tabs(indent), s)?;
}
Expand Down Expand Up @@ -333,20 +333,26 @@ pub fn bounds(
(type_names, bounds)
}

pub fn body_chunk(env: &Env, analysis: &analysis::functions::Info) -> Chunk {
pub fn body_chunk(
env: &Env,
analysis: &analysis::functions::Info,
parent_type_id: Option<TypeId>,
) -> Chunk {
if analysis.commented {
return ffi_function_todo(env, &analysis.glib_name);
}

let outs_as_return = !analysis.outs.is_empty();

let mut builder = function_body_chunk::Builder::new();
let sys_crate_name = if let Some(ty_id) = parent_type_id {
env.sys_crate_import(ty_id)
} else {
env.main_sys_crate_name().to_owned()
};

builder
.glib_name(&format!(
"{}::{}",
env.main_sys_crate_name(),
analysis.glib_name
))
.glib_name(&format!("{}::{}", sys_crate_name, analysis.glib_name))
.assertion(analysis.assertion)
.ret(&analysis.ret)
.transformations(&analysis.parameters.transformations)
Expand Down

0 comments on commit 6a8847c

Please sign in to comment.