Skip to content

Commit

Permalink
feat: more
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed Jun 8, 2024
1 parent c0e4be4 commit d96c853
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
12 changes: 9 additions & 3 deletions frb_codegen/src/library/codegen/parser/early_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ pub(crate) mod trait_impl_enum;

use crate::codegen::dumper::Dumper;
use crate::codegen::ir::hir::flat::pack::HirFlatPack;
use crate::codegen::parser::hir::flat::extra_code_injector::inject_extra_code;
use crate::codegen::parser::hir::internal_config::ParserHirInternalConfig;
use crate::codegen::parser::mir;
use crate::codegen::parser::mir::internal_config::ParserMirInternalConfig;

pub(crate) fn execute(
pack: HirFlatPack,
mut pack: HirFlatPack,
config_mir: &ParserMirInternalConfig,
config_hir: &ParserHirInternalConfig,
dumper: &Dumper,
) -> anyhow::Result<HirFlatPack> {
let dumper_tentative_mir = dumper.with_add_name_prefix("tentative_mir/");
let tentative_mir_pack = mir::parse(config_mir, &pack, &dumper_tentative_mir)?;

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

inject_extra_code(
&mut pack,
&extra_code,
&(config_mir.rust_input_namespace_pack).rust_output_path_namespace,
)?;

Ok(pack)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ use convert_case::{Case, Casing};
use itertools::Itertools;
use strum_macros::Display;

pub(crate) fn transform(
mut pack: HirFlatPack,
pub(crate) fn generate(
pack: &HirFlatPack,
tentative_mir_pack: &MirPack,
config: &ParserHirInternalConfig,
) -> anyhow::Result<HirFlatPack> {
let extra_code = (pack.traits.iter())
) -> anyhow::Result<String> {
Ok((pack.traits.iter())
.filter(|x| {
FrbAttributes::parse(&x.attrs)
.unwrap()
Expand All @@ -27,13 +26,7 @@ pub(crate) fn transform(
.map(|x| generate_trait_impl_enum(x, &tentative_mir_pack.trait_impls))
.collect::<anyhow::Result<Vec<_>>>()?
.into_iter()
.join("");

let namespace = &config.rust_input_namespace_pack.rust_output_path_namespace;

inject_extra_code(&mut pack, &extra_code, namespace)?;

Ok(pack)
.join(""))
}

fn generate_trait_impl_enum(
Expand Down
3 changes: 1 addition & 2 deletions frb_codegen/src/library/codegen/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ fn parse_inner(
let hir_tree = hir::tree::parse(&config.hir, hir_raw, &dumper_hir_tree)?;
let hir_naive_flat = hir::naive_flat::parse(&config.hir, hir_tree, &dumper_hir_naive_flat)?;
let hir_flat = hir::flat::parse(&config.hir, hir_naive_flat, &dumper_hir_flat)?;
let hir_flat =
early_generator::execute(hir_flat, &config.mir, &config.hir, &dumper_early_generator)?;
let hir_flat = early_generator::execute(hir_flat, &config.mir, &dumper_early_generator)?;
on_hir_flat(&hir_flat)?;
drop(pb);

Expand Down

0 comments on commit d96c853

Please sign in to comment.