Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gir-parser #1577

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 69 additions & 37 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,12 +14,12 @@ edition = "2021"
bitflags = "2.5"
getopts = "0.2.21"
getter_rules = { package = "fix-getters-rules", version = "0.3.0", default-features = false }
xml-rs = "0.8"
toml = { version = "0.8" , features = ["preserve_order"] }
env_logger = { version = "0.11", default-features = false }
log = "0.4"
regex = "1.10"
hprof = "0.1"
gir-parser = {git = "https://github.com/bilelmoussaoui/gir-parser"}
rustdoc-stripper = { git = "https://github.com/GuillaumeGomez/rustdoc-stripper" }

[profile.release]
Expand Down
50 changes: 24 additions & 26 deletions src/analysis/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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,20 +97,20 @@
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 {
finish_function_name(func_name)
finish_function_name(&func_name)

Check failure on line 113 in src/analysis/bounds.rs

View workflow job for this annotation

GitHub Actions / Hygiene (ubuntu-latest, stable)

this expression creates a reference which is immediately dereferenced by the compiler
};
if let Some(function) = find_function(env, &finish_func_name) {
// FIXME: This should work completely based on the analysis of the finish()
Expand All @@ -120,19 +120,19 @@
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,15 +187,15 @@
});
}
}
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 {
if 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 @@
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 @@
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 @@
.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 @@
.find_map(|f| {
f.parameters
.iter()
.filter(|p| p.ident.is_match(&param.name))
.filter(|p| p.ident.is_match(&param.name()))

Check failure on line 347 in src/analysis/bounds.rs

View workflow job for this annotation

GitHub Actions / Hygiene (ubuntu-latest, stable)

this expression creates a reference which is immediately dereferenced by the compiler
.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 @@
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()) {
return 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
Loading
Loading