Skip to content

Commit

Permalink
replace builders with generated traits on ObjectBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
jf2048 committed Dec 11, 2022
1 parent b83667d commit 17e6a81
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 363 deletions.
146 changes: 0 additions & 146 deletions src/analysis/class_builder.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::collections::BTreeMap;
pub mod bounds;
pub mod c_type;
pub mod child_properties;
pub mod class_builder;
pub mod class_hierarchy;
pub mod constants;
pub mod conversion_type;
Expand Down
27 changes: 9 additions & 18 deletions src/analysis/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ pub struct Info {
pub trait_name: String,
pub has_constructors: bool,
pub has_functions: bool,
pub generate_builder: bool,
pub signals: Vec<signals::Info>,
pub notify_signals: Vec<signals::Info>,
pub properties: Vec<properties::Property>,
pub builder_properties: Vec<(Vec<properties::Property>, TypeId)>,
pub builder_postprocess: Option<String>,
pub child_properties: ChildProperties,
pub signatures: Signatures,
/// Specific to fundamental types
Expand All @@ -60,7 +59,7 @@ impl Info {
/// - Is a final type & doesn't have either methods / properties / child properties / signals
pub fn should_generate_impl_block(&self) -> bool {
self.has_constructors
|| has_builder_properties(&self.builder_properties)
|| self.has_builder_properties()
|| !(self.need_generate_trait()
&& self.methods().is_empty()
&& self.properties.is_empty()
Expand All @@ -73,7 +72,7 @@ impl Info {
self.has_constructors
|| self.has_functions
|| !self.need_generate_trait()
|| has_builder_properties(&self.builder_properties)
|| self.has_builder_properties()
}

pub fn need_generate_trait(&self) -> bool {
Expand All @@ -84,6 +83,10 @@ impl Info {
self.signals.iter().any(|s| s.action_emit_name.is_some())
}

pub fn has_builder_properties(&self) -> bool {
self.generate_builder && !self.properties.is_empty()
}

/// Returns the location of the function within this object
pub fn function_location(&self, fn_info: &functions::Info) -> LocationInObject {
if self.final_type
Expand Down Expand Up @@ -133,14 +136,6 @@ impl Deref for Info {
}
}

pub fn has_builder_properties(builder_properties: &[(Vec<properties::Property>, TypeId)]) -> bool {
builder_properties
.iter()
.map(|b| b.0.iter().len())
.sum::<usize>()
> 0
}

pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info> {
info!("Analyzing class {}", obj.name);
let full_name = obj.name.clone();
Expand Down Expand Up @@ -230,9 +225,6 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>
deps,
);

let builder_properties =
class_builder::analyze(env, &klass.properties, class_tid, obj, &mut imports);

let child_properties =
child_properties::analyze(env, obj.child_properties.as_ref(), class_tid, &mut imports);

Expand All @@ -254,7 +246,7 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>
imports.add("glib::translate::*");
}

if has_builder_properties(&builder_properties) {
if obj.generate_builder && !properties.is_empty() {
imports.add("glib::prelude::*");
}

Expand Down Expand Up @@ -302,11 +294,10 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>
trait_name,
has_constructors,
has_functions,
generate_builder: obj.generate_builder,
signals,
notify_signals,
properties,
builder_properties,
builder_postprocess: obj.builder_postprocess.clone(),
child_properties,
signatures,
ref_fn: klass.ref_fn.clone(),
Expand Down
18 changes: 3 additions & 15 deletions src/codegen/doc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ fn create_object_doc(w: &mut dyn Write, env: &Env, info: &analysis::object::Info
signals = &cl.signals;
properties = &cl.properties;
is_abstract = env.library.type_(info.type_id).is_abstract();
has_builder = obj.generate_builder;
has_builder = obj.generate_builder && !obj.properties.is_empty();
}
Type::Interface(iface) => {
doc = iface.doc.as_ref();
Expand Down Expand Up @@ -340,21 +340,9 @@ fn create_object_doc(w: &mut dyn Write, env: &Env, info: &analysis::object::Info
})?;

if has_builder {
let builder_ty = TypeStruct::new(SType::Impl, &format!("{}Builder", info.name));
let builder_ty = TypeStruct::new(SType::Trait, &format!("{}BuilderExt", info.name));

let mut builder_properties: Vec<_> = properties.iter().collect();
for parent_info in &info.supertypes {
match env.library.type_(parent_info.type_id) {
Type::Class(cl) => {
builder_properties.extend(cl.properties.iter().filter(|p| p.writable));
}
Type::Interface(iface) => {
builder_properties.extend(iface.properties.iter().filter(|p| p.writable));
}
_ => (),
}
}
for property in &builder_properties {
for property in properties {
let ty = TypeStruct {
ty: SType::Fn,
name: nameutil::signal_to_snake(&property.name),
Expand Down
6 changes: 0 additions & 6 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ pub fn generate_mod_rs(
writeln!(w, "#[doc(hidden)]")?;
writeln!(w, "pub mod traits {{")?;
general::write_vec(w, traits)?;
writeln!(w, "}}")?;
}

if !builders.is_empty() {
writeln!(w, "#[doc(hidden)]")?;
writeln!(w, "pub mod builders {{")?;
general::write_vec(w, builders)?;
writeln!(w, "}}")?;
}
Expand Down
Loading

0 comments on commit 17e6a81

Please sign in to comment.