Skip to content

Commit

Permalink
Merge pull request #1461 from jf2048/shorten-traits
Browse files Browse the repository at this point in the history
codegen: only generate trait signatures once
  • Loading branch information
GuillaumeGomez committed Apr 28, 2023
2 parents 7193727 + deb4583 commit 8986bcf
Showing 1 changed file with 9 additions and 33 deletions.
42 changes: 9 additions & 33 deletions src/codegen/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,41 +484,10 @@ fn generate_builder(w: &mut dyn Write, env: &Env, analysis: &analysis::object::I
}

fn generate_trait(w: &mut dyn Write, env: &Env, analysis: &analysis::object::Info) -> Result<()> {
write!(w, "pub trait {}: 'static {{", analysis.trait_name)?;

for func_analysis in &analysis.methods() {
function::generate(
w,
env,
Some(analysis.type_id),
func_analysis,
Some(&analysis.specials),
analysis.version,
true,
true,
1,
)?;
}
for property in &analysis.properties {
properties::generate(w, env, property, true, true, 1)?;
}
for child_property in &analysis.child_properties {
child_properties::generate(w, env, child_property, true, true, 1)?;
}
for signal_analysis in analysis
.signals
.iter()
.chain(analysis.notify_signals.iter())
{
signal::generate(w, env, signal_analysis, true, true, 1)?;
}
writeln!(w, "}}")?;

writeln!(w)?;
write!(
w,
"impl<O: IsA<{}>> {} for O {{",
analysis.name, analysis.trait_name,
"pub trait {}: IsA<{}> + 'static {{",
analysis.trait_name, analysis.name
)?;

for func_analysis in &analysis.methods() {
Expand Down Expand Up @@ -549,6 +518,13 @@ fn generate_trait(w: &mut dyn Write, env: &Env, analysis: &analysis::object::Inf
}
writeln!(w, "}}")?;

writeln!(w)?;
writeln!(
w,
"impl<O: IsA<{}>> {} for O {{}}",
analysis.name, analysis.trait_name,
)?;

Ok(())
}

Expand Down

0 comments on commit 8986bcf

Please sign in to comment.