Skip to content

Commit 72ecc1e

Browse files
committed
Sort out const attribute generation
1 parent 20ee2d9 commit 72ecc1e

File tree

8 files changed

+255
-168
lines changed

8 files changed

+255
-168
lines changed

binding-generator/src/return_type_wrapper.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,28 @@ pub enum DefinitionLocation {
1515
#[derive(Debug)]
1616
pub struct ReturnTypeWrapper<'tu> {
1717
type_ref: TypeRef<'tu>,
18-
gen_env: &'tu GeneratorEnv<'tu>,
18+
const_hint: Option<bool>,
1919
definition_location: DefinitionLocation,
20+
gen_env: &'tu GeneratorEnv<'tu>,
2021
}
2122

2223
impl<'tu> ReturnTypeWrapper<'tu> {
23-
pub fn new(type_ref: TypeRef<'tu>, gen_env: &'tu GeneratorEnv<'tu>, definition_location: DefinitionLocation) -> Self {
24-
Self { type_ref, gen_env, definition_location }
24+
pub fn new(type_ref: TypeRef<'tu>, definition_location: DefinitionLocation, gen_env: &'tu GeneratorEnv<'tu>) -> Self {
25+
Self::new_ext(type_ref, None, definition_location, gen_env)
26+
}
27+
28+
pub fn new_ext(type_ref: TypeRef<'tu>, const_hint: Option<bool>, definition_location: DefinitionLocation, gen_env: &'tu GeneratorEnv<'tu>) -> Self {
29+
Self { type_ref, const_hint, definition_location, gen_env }
2530
}
2631

2732
pub fn type_ref(&self) -> &TypeRef<'tu> {
2833
&self.type_ref
2934
}
3035

36+
pub fn const_hint(&self) -> Option<bool> {
37+
self.const_hint
38+
}
39+
3140
pub fn definition_location(&self) -> Cow<str> {
3241
match &self.definition_location {
3342
DefinitionLocation::Module => {

binding-generator/src/settings.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ pub static FUNC_RENAME: Lazy<HashMap<&str, &str>> = Lazy::new(|| hashmap! {
1515
"cv_aruco_getPredefinedDictionary_int" => "+_i32",
1616

1717
// ### bioinspired ###
18-
"cv_bioinspired_Retina_create_Size_bool_int_bool_float_float" => "+_ext",
18+
"cv_bioinspired_Retina_create_Size_const_bool_int_const_bool_const_float_const_float" => "+_ext",
1919
"cv_bioinspired_Retina_getMagnoRAW_const__OutputArrayR" => "+_to",
2020
"cv_bioinspired_Retina_getParvoRAW_const__OutputArrayR" => "+_to",
21-
"cv_bioinspired_Retina_setup_FileStorageR_bool" => "+_from_storage",
22-
"cv_bioinspired_Retina_setup_String_bool" => "+_from_file",
21+
"cv_bioinspired_Retina_setup_FileStorageR_const_bool" => "+_from_storage",
22+
"cv_bioinspired_Retina_setup_String_const_bool" => "+_from_file",
2323
"cv_bioinspired_Retina_write_const_FileStorageR" => "+_to_storage",
24-
"cv_bioinspired_TransientAreasSegmentationModule_setup_FileStorageR_bool" => "+_from_storage",
25-
"cv_bioinspired_TransientAreasSegmentationModule_setup_String_bool" => "+_from_file",
24+
"cv_bioinspired_TransientAreasSegmentationModule_setup_FileStorageR_const_bool" => "+_from_storage",
25+
"cv_bioinspired_TransientAreasSegmentationModule_setup_String_const_bool" => "+_from_file",
2626
"cv_bioinspired_TransientAreasSegmentationModule_write_const_FileStorageR" => "+_to_storage",
27-
"cv_bioinspired_createRetina_OCL_Size_bool_int_bool_float_float" => "+_ext", // 3.2 only
27+
"cv_bioinspired_createRetina_OCL_Size_const_bool_int_const_bool_const_float_const_float" => "+_ext", // 3.2 only
2828

2929
// ### calib3d ###
3030
"cv_LMSolver_create_const_Ptr_Callback_R_int_double" => "+_ext",
3131
"cv_findEssentialMat_const__InputArrayR_const__InputArrayR_const__InputArrayR_int_double_double_const__OutputArrayR" => "+_matrix",
3232
"cv_findFundamentalMat_const__InputArrayR_const__InputArrayR_const__OutputArrayR_int_double_double" => "+_mask",
33-
"cv_findHomography_const__InputArrayR_const__InputArrayR_int_double_const__OutputArrayR_int_double" => "+_ext",
33+
"cv_findHomography_const__InputArrayR_const__InputArrayR_int_double_const__OutputArrayR_const_int_const_double" => "+_ext",
3434
"cv_fisheye_initUndistortRectifyMap_const__InputArrayR_const__InputArrayR_const__InputArrayR_const__InputArrayR_const_SizeR_int_const__OutputArrayR_const__OutputArrayR" => "fisheye_+",
3535
"cv_fisheye_projectPoints_const__InputArrayR_const__OutputArrayR_const_Affine3dR_const__InputArrayR_const__InputArrayR_double_const__OutputArrayR" => "fisheye_+",
3636
"cv_fisheye_projectPoints_const__InputArrayR_const__OutputArrayR_const__InputArrayR_const__InputArrayR_const__InputArrayR_const__InputArrayR_double_const__OutputArrayR" => "fisheye_+_vec",
@@ -211,7 +211,7 @@ pub static FUNC_RENAME: Lazy<HashMap<&str, &str>> = Lazy::new(|| hashmap! {
211211
"cv_cuda_GpuMat_GpuMat_int_int_int_voidX_size_t" => "+_rows_cols_with_data",
212212
"cv_cuda_GpuMat_download_const_const__OutputArrayR_StreamR" => "+_async",
213213
"cv_cuda_GpuMat_upload_const__InputArrayR_StreamR" => "+_async",
214-
"cv_directx_getTypeFromD3DFORMAT_int" => "get_type_from_d3d_format",
214+
"cv_directx_getTypeFromD3DFORMAT_const_int" => "get_type_from_d3d_format",
215215
"cv_divide_const__InputArrayR_const__InputArrayR_const__OutputArrayR_double_int" => "+2",
216216
"cv_getNumberOfCPUs" => "get_number_of_cpus",
217217
"cv_hconcat_const__InputArrayR_const__InputArrayR_const__OutputArrayR" => "+2",
@@ -349,12 +349,12 @@ pub static FUNC_RENAME: Lazy<HashMap<&str, &str>> = Lazy::new(|| hashmap! {
349349
"cv_dnn_Layer_finalize_const_vector_Mat_R" => "+_mat",
350350
"cv_dnn_Layer_finalize_const_vector_Mat_R_vector_Mat_R" => "+_mat_to",
351351
"cv_dnn_Layer_forward_vector_MatX_R_vector_Mat_R_vector_Mat_R" => "+_mat",
352-
"cv_dnn_NMSBoxes_const_vector_Rect2d_R_const_vector_float_R_float_float_vector_int_R_float_int" => "+_f64",
352+
"cv_dnn_NMSBoxes_const_vector_Rect2d_R_const_vector_float_R_const_float_const_float_vector_int_R_const_float_const_int" => "+_f64",
353353
"cv_dnn_Net_connect_String_String" => "+_first_second",
354354
"cv_dnn_Net_forward_const_StringR" => "+_single",
355355
"cv_dnn_Net_forward_const__OutputArrayR_const_StringR" => "+_layer",
356356
"cv_dnn_Net_getMemoryConsumption_const_const_vector_MatShape_R_vector_int_R_vector_size_t_R_vector_size_t_R" => "+_for_layers",
357-
"cv_dnn_Net_getMemoryConsumption_const_int_const_vector_MatShape_R_size_tR_size_tR" => "+_for_layer",
357+
"cv_dnn_Net_getMemoryConsumption_const_const_int_const_vector_MatShape_R_size_tR_size_tR" => "+_for_layer",
358358
"cv_dnn_blobFromImage_const__InputArrayR_const__OutputArrayR_double_const_SizeR_const_ScalarR_bool_bool_int" => "+_to",
359359
"cv_dnn_blobFromImages_const__InputArrayR_const__OutputArrayR_double_Size_const_ScalarR_bool_bool_int" => "+_to",
360360
"cv_dnn_readNetFromCaffe_const_charX_size_t_const_charX_size_t" => "+_str",
@@ -746,10 +746,10 @@ pub static FUNC_MANUAL: Lazy<HashMap<&str, CompiledInterpolation>> = Lazy::new(|
746746

747747
pub static FUNC_SPECIALIZE: Lazy<HashMap<&str, Vec<HashMap<&str, &str>>>> = Lazy::new(|| hashmap! {
748748
"cv_dnn_Dict_set_const_StringR_const_TR" => vec![
749-
hashmap! { "T" => "cv::String" },
750-
hashmap! { "T" => "cv::dnn::DictValue" },
751-
hashmap! { "T" => "double" },
752-
hashmap! { "T" => "int64_t" },
749+
hashmap! { "const T" => "cv::String" },
750+
hashmap! { "const T" => "cv::dnn::DictValue" },
751+
hashmap! { "const T" => "double" },
752+
hashmap! { "const T" => "int64_t" },
753753
],
754754
"cv_dnn_DictValue_get_const_int" => vec![
755755
hashmap! { "T" => "cv::String" },

binding-generator/src/smart_ptr.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ use clang::Entity;
77

88
use crate::{
99
DefaultElement,
10-
DefinitionLocation,
1110
DependentType,
1211
Element,
1312
EntityElement,
1413
GeneratorEnv,
15-
ReturnTypeWrapper,
1614
type_ref::TemplateArg,
1715
TypeRef,
1816
};
@@ -42,18 +40,15 @@ impl<'tu> SmartPtr<'tu> {
4240
}
4341

4442
pub fn dependent_types<D: DependentType<'tu>>(&self) -> Vec<D> {
45-
let canon = self.type_ref().canonical_clang();
46-
let mut out = vec![
47-
D::from_return_type_wrapper(ReturnTypeWrapper::new(canon.clone(), self.gen_env, DefinitionLocation::Module))
48-
];
4943
if self.pointee().as_typedef().is_some() {
50-
out.extend(canon.dependent_types())
44+
self.type_ref().canonical_clang().dependent_types()
45+
} else {
46+
vec![]
5147
}
52-
out
5348
}
5449

5550
pub fn rust_localalias(&self) -> Cow<str> {
56-
format!("PtrOf{typ}", typ=self.pointee().rust_safe_id()).into()
51+
format!("PtrOf{typ}", typ=self.pointee().rust_safe_id_ext(false)).into()
5752
}
5853

5954
pub fn rust_fullalias(&self) -> Cow<str> {

0 commit comments

Comments
 (0)