Skip to content

Commit d4f04f8

Browse files
committed
Split out TypeRef renderers into a separate module, improve const handling
1 parent 74ae5a3 commit d4f04f8

15 files changed

+639
-548
lines changed

binding-generator/src/class.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'tu> Class<'tu> {
254254
iter::from_fn({
255255
let fld_type_ref = fld.type_ref();
256256
let mut need_to_yield_read = true;
257-
let mut need_to_yield_write = !fld_type_ref.is_const() && !fld_type_ref.as_fixed_array().is_some();
257+
let mut need_to_yield_write = !fld_type_ref.constness().is_const() && !fld_type_ref.as_fixed_array().is_some();
258258
move || {
259259
if need_to_yield_read {
260260
need_to_yield_read = false;

binding-generator/src/func.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<'tu> Func<'tu> {
249249
else if let Some(fld) = self.as_field_accessor() {
250250
self.type_hint != FunctionTypeHint::FieldSetter && {
251251
let type_ref = fld.type_ref();
252-
type_ref.is_const() || type_ref.is_copy() || matches!(type_ref.as_string(), Some(Dir::In(StrType::CvString)) | Some(Dir::In(StrType::StdString)))
252+
type_ref.constness().is_const() || type_ref.is_copy() || matches!(type_ref.as_string(), Some(Dir::In(StrType::CvString)) | Some(Dir::In(StrType::StdString)))
253253
}
254254
} else {
255255
self.entity.is_const_method()
@@ -596,7 +596,7 @@ impl Element for Func<'_> {
596596
});
597597
if let Some(other) = class_arg {
598598
if cls == other {
599-
break 'ctor_name if arg_typeref.is_const() {
599+
break 'ctor_name if arg_typeref.constness().is_const() {
600600
"copy"
601601
} else {
602602
"copy_mut"

binding-generator/src/function.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Element for Function<'_> {
8787

8888
fn cpp_localname(&self) -> Cow<str> {
8989
let args = self.arguments().into_iter()
90-
.map(|a| a.type_ref().cpp_full_native("").into_owned())
90+
.map(|a| a.type_ref().cpp_full_ext("", false).into_owned())
9191
.join(", ");
9292
let ret = self.return_type();
9393
format!("{ret} (*)({args})", args=args, ret=ret.cpp_full()).into()

binding-generator/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use name_pool::NamePool;
5050
use return_type_wrapper::{DefinitionLocation, ReturnTypeWrapper};
5151
use smart_ptr::SmartPtr;
5252
pub use string_ext::{CompiledInterpolation, StrExt, StringExt};
53-
use type_ref::{Constness, DependentTypeMode, TypeRef, TypeRefTypeHint};
53+
use type_ref::{Constness, ConstnessOverride, DependentTypeMode, TypeRef, TypeRefTypeHint};
5454
pub use typedef::Typedef;
5555
use vector::Vector;
5656
pub use walker::{EntityWalker, EntityWalkerVisitor};

binding-generator/src/return_type_wrapper.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::borrow::Cow;
22

33
use crate::{
4+
ConstnessOverride,
45
GeneratorEnv,
56
TypeRef,
67
};
@@ -15,25 +16,25 @@ pub enum DefinitionLocation {
1516
#[derive(Debug)]
1617
pub struct ReturnTypeWrapper<'tu> {
1718
type_ref: TypeRef<'tu>,
18-
const_hint: Option<bool>,
19+
const_hint: ConstnessOverride,
1920
definition_location: DefinitionLocation,
2021
gen_env: &'tu GeneratorEnv<'tu>,
2122
}
2223

2324
impl<'tu> ReturnTypeWrapper<'tu> {
2425
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+
Self::new_ext(type_ref, ConstnessOverride::No, definition_location, gen_env)
2627
}
2728

28-
pub fn new_ext(type_ref: TypeRef<'tu>, const_hint: Option<bool>, definition_location: DefinitionLocation, gen_env: &'tu GeneratorEnv<'tu>) -> Self {
29+
pub fn new_ext(type_ref: TypeRef<'tu>, const_hint: ConstnessOverride, definition_location: DefinitionLocation, gen_env: &'tu GeneratorEnv<'tu>) -> Self {
2930
Self { type_ref, const_hint, definition_location, gen_env }
3031
}
3132

3233
pub fn type_ref(&self) -> &TypeRef<'tu> {
3334
&self.type_ref
3435
}
3536

36-
pub fn const_hint(&self) -> Option<bool> {
37+
pub fn const_hint(&self) -> ConstnessOverride {
3738
self.const_hint
3839
}
3940

binding-generator/src/smart_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Element for SmartPtr<'_> {
104104
}
105105

106106
fn rust_leafname(&self) -> Cow<str> {
107-
format!("Ptr::<{typ}>", typ=self.pointee().rust_full()).into()
107+
format!("Ptr::<{typ}>", typ=self.pointee().rust_full_ext(true, true)).into()
108108
}
109109

110110
fn rust_localname(&self) -> Cow<str> {

0 commit comments

Comments
 (0)