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

MODIFY
binding-generator/src/settings.rs
binding-generator/src/settings.rs
@@ -899,95 +899,96 @@ pub static IMPLEMENTED_CONST_GENERICS: Lazy<HashSet<&str>> = Lazy::new(|| hashse
});
#[derive(Clone, Copy, Debug)]
-pub enum ArgumentOverride {
+pub enum ArgOverride {
Nullable,
- Slice,
NullableSlice,
+ Slice,
LenForSlice(&'static str, usize),
+ StringAsBytes,
}
-pub static ARGUMENT_OVERRIDE: Lazy<HashMap<FuncId, HashMap<&str, ArgumentOverride>>> = Lazy::new(|| hashmap! {
+pub static ARGUMENT_OVERRIDE: Lazy<HashMap<FuncId, HashMap<&str, ArgOverride>>> = Lazy::new(|| hashmap! {
FuncId::new("cv::Mat::at", ["idx"]) => hashmap! {
- "idx" => ArgumentOverride::Slice
+ "idx" => ArgOverride::Slice
},
FuncId::new("cv::Mat::ptr", ["idx"]) => hashmap! {
- "idx" => ArgumentOverride::Slice
+ "idx" => ArgOverride::Slice
},
FuncId::new("cv::Mat::Mat", ["sizes", "type", "data", "steps"]) => hashmap! {
- "steps" => ArgumentOverride::NullableSlice,
- "sizes" => ArgumentOverride::Slice,
- "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
+ "steps" => ArgOverride::NullableSlice,
+ "sizes" => ArgOverride::Slice,
+ "ndims" => ArgOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::Mat::Mat", ["ndims", "sizes", "type", "s"]) => hashmap! {
- "steps" => ArgumentOverride::NullableSlice,
- "sizes" => ArgumentOverride::Slice,
- "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
+ "steps" => ArgOverride::NullableSlice,
+ "sizes" => ArgOverride::Slice,
+ "ndims" => ArgOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::Mat::Mat", ["ndims", "sizes", "type", "data", "steps"]) => hashmap! {
- "steps" => ArgumentOverride::NullableSlice,
- "sizes" => ArgumentOverride::Slice,
- "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
+ "steps" => ArgOverride::NullableSlice,
+ "sizes" => ArgOverride::Slice,
+ "ndims" => ArgOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::Mat::zeros", ["ndims", "sz", "type"]) => hashmap! {
- "sz" => ArgumentOverride::Slice,
- "ndims" => ArgumentOverride::LenForSlice("sz", 1),
+ "sz" => ArgOverride::Slice,
+ "ndims" => ArgOverride::LenForSlice("sz", 1),
},
FuncId::new("cv::Mat::ones", ["ndims", "sz", "type"]) => hashmap! {
- "sz" => ArgumentOverride::Slice,
- "ndims" => ArgumentOverride::LenForSlice("sz", 1),
+ "sz" => ArgOverride::Slice,
+ "ndims" => ArgOverride::LenForSlice("sz", 1),
},
FuncId::new("cv::Mat::create", ["ndims", "sizes", "type"]) => hashmap! {
- "sizes" => ArgumentOverride::Slice,
- "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
+ "sizes" => ArgOverride::Slice,
+ "ndims" => ArgOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::Mat::reshape", ["cn", "newndims", "newsz"]) => hashmap! {
- "newsz" => ArgumentOverride::Slice,
- "newndims" => ArgumentOverride::LenForSlice("newsz", 1),
+ "newsz" => ArgOverride::Slice,
+ "newndims" => ArgOverride::LenForSlice("newsz", 1),
},
FuncId::new("cv::SparseMat::Hdr::Hdr", ["_dims", "_sizes", "_type"]) => hashmap! {
- "_sizes" => ArgumentOverride::Slice,
- "_dims" => ArgumentOverride::LenForSlice("_sizes", 1),
+ "_sizes" => ArgOverride::Slice,
+ "_dims" => ArgOverride::LenForSlice("_sizes", 1),
},
FuncId::new("cv::UMat::UMat", ["ndims", "sizes", "type", "usageFlags"]) => hashmap! {
- "sizes" => ArgumentOverride::Slice,
- "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
+ "sizes" => ArgOverride::Slice,
+ "ndims" => ArgOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::UMat::UMat", ["ndims", "sizes", "type", "s", "usageFlags"]) => hashmap! {
- "sizes" => ArgumentOverride::Slice,
- "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
+ "sizes" => ArgOverride::Slice,
+ "ndims" => ArgOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::UMat::create", ["ndims", "sizes", "type", "usageFlags"]) => hashmap! {
- "sizes" => ArgumentOverride::Slice,
- "ndims" => ArgumentOverride::LenForSlice("sizes", 1),
+ "sizes" => ArgOverride::Slice,
+ "ndims" => ArgOverride::LenForSlice("sizes", 1),
},
FuncId::new("cv::_OutputArray::create", ["dims", "size", "type", "i", "allowTransposed", "fixedDepthMask"]) => hashmap! {
- "size" => ArgumentOverride::Slice,
- "dims" => ArgumentOverride::LenForSlice("size", 1),
+ "size" => ArgOverride::Slice,
+ "dims" => ArgOverride::LenForSlice("size", 1),
},
FuncId::new("cv::mixChannels", ["src", "dst", "fromTo", "npairs"]) => hashmap! {
- "fromTo" => ArgumentOverride::Slice,
- "npairs" => ArgumentOverride::LenForSlice("from_to", 2),
+ "fromTo" => ArgOverride::Slice,
+ "npairs" => ArgOverride::LenForSlice("from_to", 2),
},
FuncId::new("cv::createTrackbar", ["trackbarname", "winname", "value", "count", "onChange", "userdata"]) => hashmap! {
- "value" => ArgumentOverride::Nullable,
+ "value" => ArgOverride::Nullable,
},
FuncId::new("cv::minMaxLoc", ["src", "minVal", "maxVal", "minLoc", "maxLoc", "mask"]) => hashmap! {
- "minVal" => ArgumentOverride::Nullable,
- "maxVal" => ArgumentOverride::Nullable,
- "minLoc" => ArgumentOverride::Nullable,
- "maxLoc" => ArgumentOverride::Nullable,
+ "minVal" => ArgOverride::Nullable,
+ "maxVal" => ArgOverride::Nullable,
+ "minLoc" => ArgOverride::Nullable,
+ "maxLoc" => ArgOverride::Nullable,
},
FuncId::new("cv::minMaxLoc", ["a", "minVal", "maxVal", "minIdx", "maxIdx"]) => hashmap! {
- "minVal" => ArgumentOverride::Nullable,
- "maxVal" => ArgumentOverride::Nullable,
- "minIdx" => ArgumentOverride::Nullable,
- "maxIdx" => ArgumentOverride::Nullable,
+ "minVal" => ArgOverride::Nullable,
+ "maxVal" => ArgOverride::Nullable,
+ "minIdx" => ArgOverride::Nullable,
+ "maxIdx" => ArgOverride::Nullable,
},
FuncId::new("cv::minMaxIdx", ["src", "minVal", "maxVal", "minIdx", "maxIdx", "mask"]) => hashmap! {
- "minVal" => ArgumentOverride::Nullable,
- "maxVal" => ArgumentOverride::Nullable,
- "minIdx" => ArgumentOverride::Nullable,
- "maxIdx" => ArgumentOverride::Nullable,
+ "minVal" => ArgOverride::Nullable,
+ "maxVal" => ArgOverride::Nullable,
+ "minIdx" => ArgOverride::Nullable,
+ "maxIdx" => ArgOverride::Nullable,
},
});

MODIFY
binding-generator/src/type_ref.rs
binding-generator/src/type_ref.rs
@@ -42,6 +42,7 @@ use crate::{
Typedef,
Vector,
};
+use crate::settings::ArgOverride;
mod renderer;
@@ -85,9 +86,7 @@ pub enum Kind<'tu, 'ge> {
#[derive(Clone, Copy, Debug)]
pub enum TypeRefTypeHint<'tu> {
None,
- Nullable,
- Slice,
- NullableSlice,
+ ArgOverride(ArgOverride),
PrimitiveRefAsPointer,
Specialized(Type<'tu>),
}
@@ -161,7 +160,7 @@ impl<'tu, 'ge> TypeRef<'tu, 'ge> {
let pointee_typeref = TypeRef::new_ext(pointee, self.type_hint, self.parent_entity, self.gen_env);
if pointee_typeref.as_function().is_some() {
pointee_typeref.kind()
- } else if matches!(self.type_hint, TypeRefTypeHint::Slice | TypeRefTypeHint::NullableSlice) {
+ } else if matches!(self.type_hint, TypeRefTypeHint::ArgOverride(ArgOverride::Slice) | TypeRefTypeHint::ArgOverride(ArgOverride::NullableSlice)) {
Kind::Array(TypeRef::new_ext(pointee, self.type_hint, self.parent_entity, self.gen_env), None)
} else {
Kind::Pointer(TypeRef::new_ext(pointee, self.type_hint, self.parent_entity, self.gen_env))
@@ -683,7 +682,7 @@ impl<'tu, 'ge> TypeRef<'tu, 'ge> {
}
pub fn is_nullable(&self) -> bool {
- matches!(self.type_hint, TypeRefTypeHint::NullableSlice | TypeRefTypeHint::Nullable)
+ matches!(self.type_hint, TypeRefTypeHint::ArgOverride(ArgOverride::NullableSlice) | TypeRefTypeHint::ArgOverride(ArgOverride::Nullable))
}
pub fn as_class(&self) -> Option<Class<'tu, 'ge>> {

Reorganize argument overriding