Rework argument override settings
MODIFY
binding-generator/src/bin/settings-cleanup.rs
binding-generator/src/bin/settings-cleanup.rs
@@ -26,7 +26,7 @@ struct FunctionFinder<'tu, 'f> {
pub func_unsafe_unused: &'f mut HashSet<&'static str>,
pub func_manual_unused: &'f mut HashSet<&'static str>,
pub func_specialize_unused: &'f mut HashSet<&'static str>,
- pub slice_argument_unused: &'f mut HashSet<String>, // fixme, doesn't seem to work perfectly (shows cv::mixChannels, but it's def used)
+ pub argument_override_unused: &'f mut HashSet<String>, // fixme, doesn't seem to work perfectly (shows cv::mixChannels, but it's def used)
}
impl<'tu, 'f> FunctionFinder<'tu, 'f> {
@@ -39,7 +39,7 @@ impl<'tu, 'f> FunctionFinder<'tu, 'f> {
}
pub fn update_used_func_cpp_fullname(&mut self, cpp_fullname: &str) {
- self.slice_argument_unused.remove(cpp_fullname);
+ self.argument_override_unused.remove(cpp_fullname);
}
}
@@ -116,7 +116,7 @@ fn main() {
let mut func_unsafe_unused = settings::FUNC_UNSAFE.clone();
let mut func_manual_unused = settings::FUNC_MANUAL.keys().copied().collect::<HashSet<_>>();
let mut func_specialize_unused = settings::FUNC_SPECIALIZE.keys().copied().collect::<HashSet<_>>();
- let mut slice_argument_unused = settings::SLICE_ARGUMENT.keys().cloned()
+ let mut argument_override_unused = settings::ARGUMENT_OVERRIDE.keys().cloned()
.map(|func_id| func_id.name().to_string())
.collect::<HashSet<_>>();
for opencv_header_dir in opencv_header_dirs {
@@ -148,7 +148,7 @@ fn main() {
func_unsafe_unused: &mut func_unsafe_unused,
func_manual_unused: &mut func_manual_unused,
func_specialize_unused: &mut func_specialize_unused,
- slice_argument_unused: &mut slice_argument_unused,
+ argument_override_unused: &mut argument_override_unused,
});
});
}
@@ -163,6 +163,6 @@ fn main() {
show(func_manual_unused);
println!("Unused entries in settings::FUNC_SPECIALIZE ({}):", func_specialize_unused.len());
show(func_specialize_unused);
- println!("Unused entries in settings::SLICE_ARGUMENT ({}):", slice_argument_unused.len());
- show(slice_argument_unused);
+ println!("Unused entries in settings::ARGUMENT_OVERRIDE ({}):", argument_override_unused.len());
+ show(argument_override_unused);
}

MODIFY
binding-generator/src/field.rs
binding-generator/src/field.rs
@@ -22,6 +22,7 @@ use crate::{
EntityElement,
GeneratorEnv,
NamePool,
+ settings::ArgumentOverride,
type_ref::{FishStyle, TypeRefTypeHint},
TypeRef,
};
@@ -29,9 +30,7 @@ use crate::{
#[derive(Clone, Copy, Debug)]
pub enum FieldTypeHint<'tu> {
None,
- Slice,
- NullableSlice,
- LenForSlice(&'static str, usize),
+ ArgOverride(ArgumentOverride),
FieldSetter,
Specialized(Type<'tu>),
}
@@ -72,8 +71,8 @@ impl<'tu, 'ge> Field<'tu, 'ge> {
pub fn type_ref(&self) -> TypeRef<'tu, 'ge> {
let type_hint = match self.type_hint {
- FieldTypeHint::Slice => TypeRefTypeHint::Slice,
- FieldTypeHint::NullableSlice => TypeRefTypeHint::NullableSlice,
+ FieldTypeHint::ArgOverride(ArgumentOverride::Slice) => TypeRefTypeHint::Slice,
+ FieldTypeHint::ArgOverride(ArgumentOverride::NullableSlice) => TypeRefTypeHint::NullableSlice,
FieldTypeHint::Specialized(typ) => TypeRefTypeHint::Specialized(typ),
_ => TypeRefTypeHint::None,
};
@@ -131,7 +130,7 @@ impl<'tu, 'ge> Field<'tu, 'ge> {
}
pub fn as_slice_len(&self) -> Option<(&'static str, usize)> {
- if let FieldTypeHint::LenForSlice(ptr_arg, len_div) = self.type_hint {
+ if let FieldTypeHint::ArgOverride(ArgumentOverride::LenForSlice(ptr_arg, len_div)) = self.type_hint {
Some((ptr_arg, len_div))
} else {
None

MODIFY
binding-generator/src/func.rs
binding-generator/src/func.rs
@@ -24,7 +24,7 @@ use crate::{
FieldTypeHint,
GeneratorEnv,
reserved_rename,
- settings::{self, SliceHint},
+ settings,
StrExt,
StringExt,
type_ref::{FishStyle, TypeRefTypeHint},
@@ -429,7 +429,7 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
&empty_hashmap
};
let is_field_setter = self.as_field_setter().is_some();
- let slice_args = settings::SLICE_ARGUMENT.get(&self.func_id());
+ let arg_overrides = settings::ARGUMENT_OVERRIDE.get(&self.func_id());
args.into_iter()
.map(|a| {
@@ -437,18 +437,8 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
return Field::new_ext(a, FieldTypeHint::FieldSetter, self.gen_env)
}
- if let Some(slice_arg) = slice_args.and_then(|o| o.get(a.rust_leafname(FishStyle::No).as_ref())) {
- return match *slice_arg {
- SliceHint::Slice => {
- Field::new_ext(a, FieldTypeHint::Slice, self.gen_env)
- },
- SliceHint::NullableSlice => {
- Field::new_ext(a, FieldTypeHint::NullableSlice, self.gen_env)
- },
- SliceHint::LenForSlice(slice, len_div) => {
- Field::new_ext(a, FieldTypeHint::LenForSlice(slice, len_div), self.gen_env)
- }
- }
+ if let Some(arg_override) = arg_overrides.and_then(|o| o.get(a.rust_leafname(FishStyle::No).as_ref())) {
+ return Field::new_ext(a, FieldTypeHint::ArgOverride(*arg_override), self.gen_env);
}
let out = Field::new(a, self.gen_env);

MODIFY
binding-generator/src/settings.rs
binding-generator/src/settings.rs
@@ -873,75 +873,75 @@ pub static IMPLEMENTED_GENERICS: Lazy<HashSet<&str>> = Lazy::new(|| hashset! {
"cv::Vec",
});
-#[derive(Debug)]
-pub enum SliceHint {
+#[derive(Clone, Copy, Debug)]
+pub enum ArgumentOverride {
Slice,
NullableSlice,
LenForSlice(&'static str, usize),
}
/// (cpp_fullname, argument count)
-pub static SLICE_ARGUMENT: Lazy<HashMap<FuncId, HashMap<&str, SliceHint>>> = Lazy::new(|| hashmap! {
+pub static ARGUMENT_OVERRIDE: Lazy<HashMap<FuncId, HashMap<&str, ArgumentOverride>>> = Lazy::new(|| hashmap! {
FuncId::new("cv::Mat::at", ["idx"]) => hashmap! {
- "idx" => SliceHint::Slice
+ "idx" => ArgumentOverride::Slice
},
FuncId::new("cv::Mat::ptr", ["idx"]) => hashmap! {
- "idx" => SliceHint::Slice
+ "idx" => ArgumentOverride::Slice
},
FuncId::new("cv::Mat::Mat", ["sizes", "type", "data", "steps"]) => hashmap! {
- "steps" => SliceHint::NullableSlice,
- "sizes" => SliceHint::Slice,
- "ndims" => SliceHint::LenForSlice("sizes", 1),
+ "steps" => ArgumentOverride::NullableSlice,
+ "sizes" => ArgumentOverride::Slice,
+ "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::Mat::Mat", ["ndims", "sizes", "type", "s"]) => hashmap! {
- "steps" => SliceHint::NullableSlice,
- "sizes" => SliceHint::Slice,
- "ndims" => SliceHint::LenForSlice("sizes", 1),
+ "steps" => ArgumentOverride::NullableSlice,
+ "sizes" => ArgumentOverride::Slice,
+ "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::Mat::Mat", ["ndims", "sizes", "type", "data", "steps"]) => hashmap! {
- "steps" => SliceHint::NullableSlice,
- "sizes" => SliceHint::Slice,
- "ndims" => SliceHint::LenForSlice("sizes", 1),
+ "steps" => ArgumentOverride::NullableSlice,
+ "sizes" => ArgumentOverride::Slice,
+ "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::Mat::zeros", ["ndims", "sz", "type"]) => hashmap! {
- "sz" => SliceHint::Slice,
- "ndims" => SliceHint::LenForSlice("sz", 1),
+ "sz" => ArgumentOverride::Slice,
+ "ndims" => ArgumentOverride::LenForSlice("sz", 1),
},
FuncId::new("cv::Mat::ones", ["ndims", "sz", "type"]) => hashmap! {
- "sz" => SliceHint::Slice,
- "ndims" => SliceHint::LenForSlice("sz", 1),
+ "sz" => ArgumentOverride::Slice,
+ "ndims" => ArgumentOverride::LenForSlice("sz", 1),
},
FuncId::new("cv::Mat::create", ["ndims", "sizes", "type"]) => hashmap! {
- "sizes" => SliceHint::Slice,
- "ndims" => SliceHint::LenForSlice("sizes", 1),
+ "sizes" => ArgumentOverride::Slice,
+ "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::Mat::reshape", ["cn", "newndims", "newsz"]) => hashmap! {
- "newsz" => SliceHint::Slice,
- "newndims" => SliceHint::LenForSlice("newsz", 1),
+ "newsz" => ArgumentOverride::Slice,
+ "newndims" => ArgumentOverride::LenForSlice("newsz", 1),
},
FuncId::new("cv::SparseMat::Hdr::Hdr", ["_dims", "_sizes", "_type"]) => hashmap! {
- "_sizes" => SliceHint::Slice,
- "_dims" => SliceHint::LenForSlice("_sizes", 1),
+ "_sizes" => ArgumentOverride::Slice,
+ "_dims" => ArgumentOverride::LenForSlice("_sizes", 1),
},
FuncId::new("cv::UMat::UMat", ["ndims", "sizes", "type", "usageFlags"]) => hashmap! {
- "sizes" => SliceHint::Slice,
- "ndims" => SliceHint::LenForSlice("sizes", 1),
+ "sizes" => ArgumentOverride::Slice,
+ "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::UMat::UMat", ["ndims", "sizes", "type", "s", "usageFlags"]) => hashmap! {
- "sizes" => SliceHint::Slice,
- "ndims" => SliceHint::LenForSlice("sizes", 1),
+ "sizes" => ArgumentOverride::Slice,
+ "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::UMat::create", ["ndims", "sizes", "type", "usageFlags"]) => hashmap! {
- "sizes" => SliceHint::Slice,
- "ndims" => SliceHint::LenForSlice("sizes", 1),
+ "sizes" => ArgumentOverride::Slice,
+ "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::_OutputArray::create", ["dims", "size", "type", "i", "allowTransposed", "fixedDepthMask"]) => hashmap! {
- "size" => SliceHint::Slice,
- "dims" => SliceHint::LenForSlice("size", 1),
+ "size" => ArgumentOverride::Slice,
+ "dims" => ArgumentOverride::LenForSlice("size", 1),
},
FuncId::new("cv::mixChannels", ["src", "dst", "fromTo", "npairs"]) => hashmap! {
- "from_to" => SliceHint::Slice,
- "npairs" => SliceHint::LenForSlice("from_to", 2),
+ "from_to" => ArgumentOverride::Slice,
+ "npairs" => ArgumentOverride::LenForSlice("from_to", 2),
},
});

MODIFY
binding-generator/src/type_ref.rs
binding-generator/src/type_ref.rs
@@ -85,6 +85,7 @@ pub enum Kind<'tu, 'ge> {
#[derive(Clone, Copy, Debug)]
pub enum TypeRefTypeHint<'tu> {
None,
+ Nullable,
Slice,
NullableSlice,
Specialized(Type<'tu>),

Rework argument override settings