Skip to content
Draft
91 changes: 63 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ edition = "2024"
bitflags = "2.10"
getopts = "0.2.24"
getter_rules = { package = "fix-getters-rules", version = "0.3.0", default-features = false }
xml-rs = "1.0"
toml = { version = "0.9" , features = ["preserve_order"] }
env_logger = { version = "0.11", default-features = false }
log = "0.4"
regex = "1.12"
hprof = "0.1"
rustdoc-stripper = "0.1.19"
gir-parser = { git = "https://github.com/bilelmoussaoui/gir-parser.git", rev = "946d79b9d220e3c68692f3b590986a15fcca7139" }

[profile.release]
codegen-units = 4
Expand Down
48 changes: 23 additions & 25 deletions src/analysis/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
config,
consts::TYPE_PARAMETERS_START,
env::Env,
library::{Basic, Class, Concurrency, Function, ParameterDirection, Type, TypeId},
library::{Basic, Class, Concurrency, Function, Type, TypeId},
traits::IntoString,
};

Expand Down Expand Up @@ -97,16 +97,16 @@ impl Bounds {
let mut ret = None;
let mut need_is_into_check = false;

if !par.instance_parameter && par.direction != ParameterDirection::Out {
if !par.is_instance_parameter && !par.direction.is_out() {
if let Some(bound_type) = Bounds::type_for(env, par.typ) {
ret = Some(Bounds::get_to_glib_extra(
&bound_type,
*par.nullable,
par.instance_parameter,
par.nullable,
par.is_instance_parameter,
par.move_,
));
if r#async && (par.name == "callback" || par.name.ends_with("_callback")) {
let func_name = func.c_identifier.as_ref().unwrap();
let func_name = &func.c_identifier;
let finish_func_name = if let Some(finish_func_name) = &func.finish_func {
finish_func_name.to_string()
} else {
Expand All @@ -120,19 +120,19 @@ impl Bounds {
find_out_parameters(env, function, configured_functions);
if use_function_return_for_result(
env,
function.ret.typ,
function.ret.typ(),
&func.name,
configured_functions,
) {
let nullable = configured_functions
.iter()
.find_map(|f| f.ret.nullable)
.unwrap_or(function.ret.nullable);
.unwrap_or(function.ret.is_nullable());

out_parameters.insert(
0,
RustType::builder(env, function.ret.typ)
.direction(function.ret.direction)
RustType::builder(env, function.ret.typ())
.direction(function.ret.direction())
.nullable(nullable)
.try_build()
.into_string(),
Expand Down Expand Up @@ -187,16 +187,16 @@ impl Bounds {
});
}
}
if (!need_is_into_check || !*par.nullable) && par.c_type != "GDestroyNotify" {
if (!need_is_into_check || !par.nullable) && par.c_type != "GDestroyNotify" {
self.add_parameter(&par.name, &type_string, bound_type, r#async);
}
}
} else if par.instance_parameter
} else if par.is_instance_parameter
&& let Some(bound_type) = Bounds::type_for(env, par.typ)
{
ret = Some(Bounds::get_to_glib_extra(
&bound_type,
*par.nullable,
par.nullable,
true,
par.move_,
));
Expand Down Expand Up @@ -229,7 +229,7 @@ impl Bounds {
pub fn get_to_glib_extra(
bound_type: &BoundType,
nullable: bool,
instance_parameter: bool,
is_instance_parameter: bool,
move_: bool,
) -> String {
use self::BoundType::*;
Expand All @@ -239,7 +239,7 @@ impl Bounds {
AsRef(_) if move_ => ".upcast()".to_owned(),
AsRef(_) => ".as_ref()".to_owned(),
IsA(_) if move_ && nullable => ".map(|p| p.upcast())".to_owned(),
IsA(_) if nullable && !instance_parameter => ".map(|p| p.as_ref())".to_owned(),
IsA(_) if nullable && !is_instance_parameter => ".map(|p| p.as_ref())".to_owned(),
IsA(_) if move_ => ".upcast()".to_owned(),
IsA(_) => ".as_ref()".to_owned(),
_ => String::new(),
Expand Down Expand Up @@ -333,9 +333,7 @@ fn find_out_parameters(
.iter()
.enumerate()
.filter(|&(index, param)| {
Some(index) != index_to_ignore
&& param.direction == ParameterDirection::Out
&& param.name != "error"
Some(index) != index_to_ignore && param.direction().is_out() && !param.is_error()
})
.map(|(_, param)| {
// FIXME: This should work completely based on the analysis of the finish()
Expand All @@ -346,13 +344,13 @@ fn find_out_parameters(
.find_map(|f| {
f.parameters
.iter()
.filter(|p| p.ident.is_match(&param.name))
.filter(|p| p.ident.is_match(param.name()))
.find_map(|p| p.nullable)
})
.unwrap_or(param.nullable);
.unwrap_or(param.is_nullable());

RustType::builder(env, param.typ)
.direction(param.direction)
RustType::builder(env, param.typ())
.direction(param.direction())
.nullable(nullable)
.try_build()
.into_string()
Expand All @@ -372,11 +370,11 @@ fn find_error_type(env: &Env, function: &Function) -> Option<String> {
let error_param = function
.parameters
.iter()
.find(|param| param.direction.is_out() && param.is_error)?;
if let Type::Record(_) = env.type_(error_param.typ) {
.find(|param| param.direction().is_out() && param.is_error())?;
if let Type::Record(_) = env.type_(error_param.typ()) {
Some(
RustType::builder(env, error_param.typ)
.direction(error_param.direction)
RustType::builder(env, error_param.typ())
.direction(error_param.direction())
.try_build()
.into_string(),
)
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/child_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct ChildProperty {
pub typ: library::TypeId,
pub child_name: String,
pub child_type: Option<library::TypeId>,
pub nullable: library::Nullable,
pub nullable: bool,
pub get_out_ref_mode: RefMode,
pub set_in_ref_mode: RefMode,
pub doc_hidden: bool,
Expand Down Expand Up @@ -117,7 +117,7 @@ fn analyze_property(
if set_in_ref_mode == RefMode::ByRefMut {
set_in_ref_mode = RefMode::ByRef;
}
let nullable = library::Nullable(set_in_ref_mode.is_ref());
let nullable = set_in_ref_mode.is_ref();

let mut bounds_str = String::new();
let dir = ParameterDirection::In;
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn new(env: &Env, obj: &GObject, imports: &mut Imports) -> Option<Info> {
let first_param = &mut f.parameters.c_parameters[0];

if first_param.typ == enumeration_tid {
first_param.instance_parameter = true;
first_param.is_instance_parameter = true;

let t = f
.parameters
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn new(env: &Env, obj: &GObject, imports: &mut Imports) -> Option<Info> {
let first_param = &mut f.parameters.c_parameters[0];

if first_param.typ == flags_tid {
first_param.instance_parameter = true;
first_param.is_instance_parameter = true;

let t = f
.parameters
Expand Down
Loading