Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ast_codegen): abstract passes and generators behind Runner trait. #4556

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tasks/ast_codegen/src/generators/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ use crate::{
CodegenCtx, Generator, GeneratorOutput, TypeRef,
};

pub struct AstBuilderGenerator;
use super::define_generator;

define_generator! {
pub struct AstBuilderGenerator;
}

impl Generator for AstBuilderGenerator {
fn name(&self) -> &'static str {
Expand Down
6 changes: 4 additions & 2 deletions tasks/ast_codegen/src/generators/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use crate::{
GeneratorOutput, TypeRef,
};

use super::generated_header;
use super::{define_generator, generated_header};

pub struct AstKindGenerator;
define_generator! {
pub struct AstKindGenerator;
}

pub const BLACK_LIST: [&str; 61] = [
"Expression",
Expand Down
6 changes: 4 additions & 2 deletions tasks/ast_codegen/src/generators/impl_get_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ use crate::{
CodegenCtx, Generator, GeneratorOutput,
};

use super::generated_header;
use super::{define_generator, generated_header};

pub struct ImplGetSpanGenerator;
define_generator! {
pub struct ImplGetSpanGenerator;
}

impl Generator for ImplGetSpanGenerator {
fn name(&self) -> &'static str {
Expand Down
24 changes: 24 additions & 0 deletions tasks/ast_codegen/src/generators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,27 @@ pub use ast_builder::AstBuilderGenerator;
pub use ast_kind::AstKindGenerator;
pub use impl_get_span::ImplGetSpanGenerator;
pub use visit::{VisitGenerator, VisitMutGenerator};

use crate::{CodegenCtx, GeneratorOutput};

pub trait Generator {
fn name(&self) -> &'static str;
fn generate(&mut self, ctx: &CodegenCtx) -> GeneratorOutput;
}

macro_rules! define_generator {
($vis:vis struct $ident:ident $($lifetime:lifetime)? $($rest:tt)*) => {
$vis struct $ident $($lifetime)? $($rest)*
impl $($lifetime)? $crate::Runner for $ident $($lifetime)? {
fn name(&self) -> &'static str {
$crate::Generator::name(self)
}

fn run(&mut self, ctx: &$crate::CodegenCtx) -> $crate::Result<$crate::GeneratorOutput> {
Ok(self.generate(ctx))
}
}
};
}

pub(crate) use define_generator;
11 changes: 8 additions & 3 deletions tasks/ast_codegen/src/generators/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ use crate::{
CodegenCtx, Generator, GeneratorOutput, TypeRef,
};

use super::generated_header;
use super::{define_generator, generated_header};

pub struct VisitGenerator;
pub struct VisitMutGenerator;
define_generator! {
pub struct VisitGenerator;
}

define_generator! {
pub struct VisitMutGenerator;
}

impl Generator for VisitGenerator {
fn name(&self) -> &'static str {
Expand Down
110 changes: 0 additions & 110 deletions tasks/ast_codegen/src/linker.rs

This file was deleted.

Loading
Loading