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 to extract early_generator between high-level intermediate representation and mid-level intermediate representation #2049

Merged
merged 23 commits into from
Jun 8, 2024
Merged
Prev Previous commit
Next Next commit
refactor: dumper ty
  • Loading branch information
fzyzcjy committed Jun 8, 2024
commit d9df27628a30a8283b72576051b2fa4b0a3d4000
14 changes: 10 additions & 4 deletions frb_codegen/src/library/codegen/dumper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ use strum::IntoEnumIterator;

pub(super) mod internal_config;

pub(crate) struct Dumper<'a>(pub &'a DumperInternalConfig);
pub(crate) struct Dumper<'a> {
config: &'a DumperInternalConfig,
}

impl<'a> Dumper<'a> {
pub fn new(config: &'a DumperInternalConfig) -> Self {
Self { config }
}

impl Dumper<'_> {
pub(crate) fn dump<T: Serialize>(
&self,
content: ConfigDumpContent,
Expand Down Expand Up @@ -90,7 +96,7 @@ impl Dumper<'_> {
}

let path = self
.0
.config
.dump_directory
.join(content.to_string().to_case(Case::Snake))
.join(name);
Expand All @@ -100,6 +106,6 @@ impl Dumper<'_> {
}

fn is_enabled(&self, content: ConfigDumpContent) -> bool {
self.0.dump_contents.contains(&content)
self.config.dump_contents.contains(&content)
}
}
4 changes: 2 additions & 2 deletions frb_codegen/src/library/codegen/generator/api_dart/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ mod tests {
let internal_config = InternalConfig::parse(&config, &MetaConfig { watch: false })?;
let mir_pack = crate::codegen::parser::parse(
&internal_config.parser,
&Dumper(&Default::default()),
&Dumper::new(&Default::default()),
&GeneratorProgressBarPack::new(),
)?;
let actual = generate(
&mir_pack,
&internal_config.generator.api_dart,
&Dumper(&Default::default()),
&Dumper::new(&Default::default()),
)?;

let output_texts = actual.output_texts;
Expand Down
2 changes: 1 addition & 1 deletion frb_codegen/src/library/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn generate(config: Config, meta_config: MetaConfig) -> anyhow::Result<()> {
let internal_config = InternalConfig::parse(&config, &meta_config)?;
debug!("internal_config={internal_config:?}");

let dumper = Dumper(&internal_config.dumper);
let dumper = Dumper::new(&internal_config.dumper);
dumper.dump(ContentConfig, "config.json", &config)?;

controller::run(&internal_config.controller, &|| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) fn execute(
config_mir: &ParserMirInternalConfig,
config_hir: &ParserHirInternalConfig,
) -> anyhow::Result<HirFlatPack> {
let tentative_mir_pack = mir::parse(config_mir, &pack, TODO)?;
let tentative_mir_pack = mir::parse(config_mir, &pack, todo!())?;

let pack = trait_impl_enum::transform(pack, &tentative_mir_pack, config_hir)?;

Expand Down
2 changes: 1 addition & 1 deletion frb_codegen/src/library/codegen/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ mod tests {

let pack = parse_inner(
&config,
&Dumper(&Default::default()),
&Dumper::new(&Default::default()),
&GeneratorProgressBarPack::new(),
|hir_flat| {
json_golden_test(
Expand Down