From 6671b54c9f71b3ebbfa2307d9a0bf630f4cb8478 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:29:00 +0800 Subject: [PATCH 01/60] feat: more --- .../src/library/codegen/parser/hir/hierarchical/mod.rs | 7 +++++++ .../hir/hierarchical/third_party_override_transformer.rs | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs index 5b2152284c..0a1c913936 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs @@ -10,12 +10,19 @@ pub(crate) mod mirror_ident; pub(crate) mod module; mod pub_use; pub(crate) mod struct_or_enum; +mod third_party_override_transformer; pub(crate) mod visibility; pub(crate) fn parse( config: &ParserHirInternalConfig, hir_raw: &HirRawPack, ) -> anyhow::Result { + let pack = parse_raw(config, hir_raw)?; + let pack = third_party_override_transformer::transform(pack)?; + Ok(pack) +} + +fn parse_raw(config: &ParserHirInternalConfig, hir_raw: &HirRawPack) -> anyhow::Result { let crates = hir_raw .crates .iter() diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs new file mode 100644 index 0000000000..b283837dc7 --- /dev/null +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -0,0 +1,6 @@ +use crate::codegen::ir::hir::hierarchical::pack::HirPack; + +pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { + TODO; + Ok(pack) +} From 3cc5ed4a0134ab5e7eebb2b6360ca83631f73d82 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:33:21 +0800 Subject: [PATCH 02/60] feat: more --- .../library/codegen/ir/hir/hierarchical/module.rs | 12 +++++++++++- .../hierarchical/third_party_override_transformer.rs | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs index 85c9b92399..9ac07563cf 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs @@ -54,8 +54,18 @@ pub enum HirVisibility { } impl HirModuleContent { + pub(crate) fn get_module_index_by_name(&self, mod_name: &str) -> Option { + self.modules + .iter() + .enumerate() + .filter(|(_, m)| *m.meta.namespace.path().last().unwrap() == mod_name) + .map(|(i, _)| i) + .next() + } + pub(crate) fn get_module_by_name(&self, mod_name: &str) -> Option<&HirModule> { - (self.modules.iter()).find(|m| *m.meta.namespace.path().last().unwrap() == mod_name) + self.get_module_index_by_name(mod_name) + .map(|i| &self.modules[i]) } pub(crate) fn get_module_nested(&self, mod_names: &[&str]) -> Option<&HirModule> { diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index b283837dc7..cb82ee8a4e 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -1,6 +1,15 @@ +use crate::codegen::ir::hir::hierarchical::module::HirModule; use crate::codegen::ir::hir::hierarchical::pack::HirPack; +use crate::codegen::misc::THIRD_PARTY_DIR_NAME; +use crate::utils::crate_name::CrateName; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { + let module_third_party_root = remove_module_third_party_root(&mut pack); TODO; Ok(pack) } + +fn remove_module_third_party_root(pack: &mut HirPack) -> HirModule { + let hir_crate = pack.crates.get_mut(&CrateName::self_crate()).unwrap(); + hir_crate.root_module.content.get_module_nested(&[THIRD_PARTY_DIR_NAME]) +} From e63492f3358355da6eca31f4d570259cbc30c010 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:34:20 +0800 Subject: [PATCH 03/60] feat: more --- .../src/library/codegen/ir/hir/hierarchical/module.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs index 9ac07563cf..9d7bcab364 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs @@ -68,6 +68,11 @@ impl HirModuleContent { .map(|i| &self.modules[i]) } + pub(crate) fn remove_module_by_name(&mut self, mod_name: &str) -> Option { + self.get_module_index_by_name(mod_name) + .map(|index| self.modules.remove(index)) + } + pub(crate) fn get_module_nested(&self, mod_names: &[&str]) -> Option<&HirModule> { let m = self.get_module_by_name(mod_names[0])?; if mod_names.len() == 1 { From 81e9b9772f636d36c69f5e2f107b5ba2d5d79e57 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:34:47 +0800 Subject: [PATCH 04/60] feat: more --- .../hir/hierarchical/third_party_override_transformer.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index cb82ee8a4e..f3a29b5ea8 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -4,12 +4,13 @@ use crate::codegen::misc::THIRD_PARTY_DIR_NAME; use crate::utils::crate_name::CrateName; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { - let module_third_party_root = remove_module_third_party_root(&mut pack); - TODO; + if let Some(module_third_party_root) = remove_module_third_party_root(&mut pack) { + TODO; + } Ok(pack) } -fn remove_module_third_party_root(pack: &mut HirPack) -> HirModule { +fn remove_module_third_party_root(pack: &mut HirPack) -> Option { let hir_crate = pack.crates.get_mut(&CrateName::self_crate()).unwrap(); - hir_crate.root_module.content.get_module_nested(&[THIRD_PARTY_DIR_NAME]) + hir_crate.root_module.content.remove_module_by_name(THIRD_PARTY_DIR_NAME) } From 7e3453bdd261f663bb9528b8f9e6b062c6740531 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:43:17 +0800 Subject: [PATCH 05/60] feat: more --- .../third_party_override_transformer.rs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index f3a29b5ea8..3d86c05c0a 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -5,12 +5,28 @@ use crate::utils::crate_name::CrateName; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { if let Some(module_third_party_root) = remove_module_third_party_root(&mut pack) { - TODO; + for module_third_party_crate in module_third_party_root.content.modules { + transform_crate(&mut pack, module_third_party_crate)?; + } } Ok(pack) } fn remove_module_third_party_root(pack: &mut HirPack) -> Option { let hir_crate = pack.crates.get_mut(&CrateName::self_crate()).unwrap(); - hir_crate.root_module.content.remove_module_by_name(THIRD_PARTY_DIR_NAME) + hir_crate + .root_module + .content + .remove_module_by_name(THIRD_PARTY_DIR_NAME) +} + +fn transform_crate(pack: &mut HirPack, src: HirModule) -> anyhow::Result<()> { + if let Some(target_crate) = pack.crates.get_mut() { + TODO; + } else { + log::warn!( + "Skip `{}` since there is no corresponding scanned third party crate.", + src.meta.namespace, + ); + } } From 14a9817b4109273156568859cb1c9a03a1036256 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:43:57 +0800 Subject: [PATCH 06/60] feat: more --- .../third_party_override_transformer.rs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 3d86c05c0a..d39d38ee5c 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -1,3 +1,4 @@ +use crate::codegen::ir::hir::hierarchical::crates::HirCrate; use crate::codegen::ir::hir::hierarchical::module::HirModule; use crate::codegen::ir::hir::hierarchical::pack::HirPack; use crate::codegen::misc::THIRD_PARTY_DIR_NAME; @@ -6,7 +7,14 @@ use crate::utils::crate_name::CrateName; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { if let Some(module_third_party_root) = remove_module_third_party_root(&mut pack) { for module_third_party_crate in module_third_party_root.content.modules { - transform_crate(&mut pack, module_third_party_crate)?; + if let Some(target_crate) = pack.crates.get_mut() { + transform_crate(target_crate, module_third_party_crate) + } else { + log::warn!( + "Skip `{}` since there is no corresponding scanned third party crate.", + module_third_party_crate.meta.namespace, + ); + } } } Ok(pack) @@ -20,13 +28,6 @@ fn remove_module_third_party_root(pack: &mut HirPack) -> Option { .remove_module_by_name(THIRD_PARTY_DIR_NAME) } -fn transform_crate(pack: &mut HirPack, src: HirModule) -> anyhow::Result<()> { - if let Some(target_crate) = pack.crates.get_mut() { - TODO; - } else { - log::warn!( - "Skip `{}` since there is no corresponding scanned third party crate.", - src.meta.namespace, - ); - } +fn transform_crate(target: &mut HirCrate, src: HirModule) -> anyhow::Result<()> { + TODO; } From f3db19995f3b94280c14875ad6254019a2275575 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:44:44 +0800 Subject: [PATCH 07/60] chore: more --- .../parser/hir/hierarchical/third_party_override_transformer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index d39d38ee5c..f128c88f6e 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -29,5 +29,5 @@ fn remove_module_third_party_root(pack: &mut HirPack) -> Option { } fn transform_crate(target: &mut HirCrate, src: HirModule) -> anyhow::Result<()> { - TODO; + todo!() } From bfd836b738bbc847f524c08c5cad8ded933e05ed Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:46:10 +0800 Subject: [PATCH 08/60] feat: more --- .../hierarchical/third_party_override_transformer.rs | 3 ++- frb_codegen/src/library/utils/crate_name.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index f128c88f6e..28550da2be 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -7,7 +7,8 @@ use crate::utils::crate_name::CrateName; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { if let Some(module_third_party_root) = remove_module_third_party_root(&mut pack) { for module_third_party_crate in module_third_party_root.content.modules { - if let Some(target_crate) = pack.crates.get_mut() { + let crate_name = (module_third_party_crate.meta.namespace.path().last()).unwrap(); + if let Some(target_crate) = pack.crates.get_mut(crate_name) { transform_crate(target_crate, module_third_party_crate) } else { log::warn!( diff --git a/frb_codegen/src/library/utils/crate_name.rs b/frb_codegen/src/library/utils/crate_name.rs index d84ada8bf2..cfece0dd65 100644 --- a/frb_codegen/src/library/utils/crate_name.rs +++ b/frb_codegen/src/library/utils/crate_name.rs @@ -2,10 +2,18 @@ use crate::utils::namespace::Namespace; use serde::{Deserialize, Serialize}; /// e.g. `web-audio-api` (note the `-` instead of `_`) -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Serialize, Deserialize, Hash)] #[serde(transparent)] pub(crate) struct CrateName(String); +impl PartialEq for CrateName { + fn eq(&self, other: &Self) -> bool { + self.namespace() == other.namespace() + } +} + +impl Eq for CrateName {} + impl CrateName { pub(crate) const SELF_CRATE: &'static str = "crate"; From 734be92e32dcd49ac13038dcfe90a5de4bb36de1 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:46:28 +0800 Subject: [PATCH 09/60] fix: err --- .../hir/hierarchical/third_party_override_transformer.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 28550da2be..41d76343a4 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -7,8 +7,9 @@ use crate::utils::crate_name::CrateName; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { if let Some(module_third_party_root) = remove_module_third_party_root(&mut pack) { for module_third_party_crate in module_third_party_root.content.modules { - let crate_name = (module_third_party_crate.meta.namespace.path().last()).unwrap(); - if let Some(target_crate) = pack.crates.get_mut(crate_name) { + let crate_name = + CrateName::new((module_third_party_crate.meta.namespace.path().last()).unwrap()); + if let Some(target_crate) = pack.crates.get_mut(&crate_name) { transform_crate(target_crate, module_third_party_crate) } else { log::warn!( From 70916f45697d663ebaa42b7311accd6d12d8820f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:46:54 +0800 Subject: [PATCH 10/60] fix: err --- .../hir/hierarchical/third_party_override_transformer.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 41d76343a4..b2bca5c54a 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -7,10 +7,13 @@ use crate::utils::crate_name::CrateName; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { if let Some(module_third_party_root) = remove_module_third_party_root(&mut pack) { for module_third_party_crate in module_third_party_root.content.modules { - let crate_name = - CrateName::new((module_third_party_crate.meta.namespace.path().last()).unwrap()); + let crate_name = CrateName::new( + (module_third_party_crate.meta.namespace.path().last()) + .unwrap() + .to_string(), + ); if let Some(target_crate) = pack.crates.get_mut(&crate_name) { - transform_crate(target_crate, module_third_party_crate) + transform_crate(target_crate, module_third_party_crate)?; } else { log::warn!( "Skip `{}` since there is no corresponding scanned third party crate.", From a4bdf6c26f8b8fafecae0a4f065160c317e911e0 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:48:29 +0800 Subject: [PATCH 11/60] refactor: ir --- .../ir/hir/hierarchical/struct_or_enum.rs | 40 +++---------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs index 8e733f8158..396215b8d9 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs @@ -23,42 +23,14 @@ pub struct HirStructOrEnum { } // frb-coverage:ignore-end -#[derive(Clone, Debug, Serialize)] -pub struct HirStruct(pub HirStructOrEnum); - -#[derive(Clone, Debug, Serialize)] -pub struct HirEnum(pub HirStructOrEnum); - -pub trait HirStructOrEnumWrapper { - fn inner(&self) -> &HirStructOrEnum; - - fn attrs(&self) -> &[Attribute]; - - fn with_namespace(&self, namespace: Namespace) -> Self; -} - -macro_rules! struct_or_enum_wrapper { - ($name:ident, $item:ident) => { - impl HirStructOrEnumWrapper<$item> for $name { - fn inner(&self) -> &HirStructOrEnum<$item> { - &self.0 - } - - fn attrs(&self) -> &[Attribute] { - &self.0.src.attrs - } - - fn with_namespace(&self, namespace: Namespace) -> Self { - Self(self.0.with_namespace(namespace)) - } - } - }; -} - -struct_or_enum_wrapper!(HirStruct, ItemStruct); -struct_or_enum_wrapper!(HirEnum, ItemEnum); +pub type HirStruct = HirStructOrEnum; +pub type HirEnum = HirEnumOrEnum; impl HirStructOrEnum { + fn attrs(&self) -> &[Attribute] { + &self.src.attrs + } + fn with_namespace(&self, namespace: Namespace) -> Self { Self { namespaced_name: NamespacedName::new(namespace, self.namespaced_name.name.clone()), From 11e8d41c9237f135d42a15db80dac9a5c09b6e5f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:48:53 +0800 Subject: [PATCH 12/60] feat: more --- .../ir/hir/hierarchical/struct_or_enum.rs | 2 +- .../parser/hir/hierarchical/pub_use.rs | 1 - .../parser/hir/hierarchical/struct_or_enum.rs | 28 ++++--------------- .../src/library/codegen/parser/mir/misc.rs | 8 +++--- .../parser/mir/type_parser/enum_or_struct.rs | 9 +++--- 5 files changed, 14 insertions(+), 34 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs index 396215b8d9..25fceebf87 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs @@ -24,7 +24,7 @@ pub struct HirStructOrEnum { // frb-coverage:ignore-end pub type HirStruct = HirStructOrEnum; -pub type HirEnum = HirEnumOrEnum; +pub type HirEnum = HirStructOrEnum; impl HirStructOrEnum { fn attrs(&self) -> &[Attribute] { diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/pub_use.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/pub_use.rs index 336af5854b..64bd42eabb 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/pub_use.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/pub_use.rs @@ -1,5 +1,4 @@ use crate::codegen::ir::hir::hierarchical::module::HirModule; -use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnumWrapper; use crate::utils::namespace::Namespace; use itertools::Itertools; diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs index 99f5a9238a..a5bfcc5a3a 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs @@ -12,28 +12,14 @@ pub(crate) fn parse_syn_item_struct( item: &ItemStruct, namespace: &Namespace, ) -> anyhow::Result> { - parse_syn_item_struct_or_enum( - item, - namespace, - &item.ident, - &item.attrs, - &item.vis, - HirStruct, - ) + parse_syn_item_struct_or_enum(item, namespace, &item.ident, &item.attrs, &item.vis) } pub(crate) fn parse_syn_item_enum( item: &ItemEnum, namespace: &Namespace, ) -> anyhow::Result> { - parse_syn_item_struct_or_enum( - item, - namespace, - &item.ident, - &item.attrs, - &item.vis, - HirEnum, - ) + parse_syn_item_struct_or_enum(item, namespace, &item.ident, &item.attrs, &item.vis) } fn parse_syn_item_struct_or_enum( @@ -42,11 +28,7 @@ fn parse_syn_item_struct_or_enum( item_ident: &Ident, item_attrs: &[Attribute], item_vis: &syn::Visibility, - constructor: F, -) -> anyhow::Result> -where - F: Fn(HirStructOrEnum) -> T, -{ +) -> anyhow::Result> { debug!("parse_syn_item_struct_or_enum item_ident={item_ident:?}"); let ParseMirrorIdentOutput { idents, mirror } = parse_mirror_ident(item_ident, item_attrs)?; @@ -55,13 +37,13 @@ where .into_iter() .map(|ident| { let ident_str = ident.to_string(); - constructor(HirStructOrEnum { + HirStructOrEnum { ident, src: item.clone(), visibility: item_vis.into(), namespaced_name: NamespacedName::new(namespace.to_owned(), ident_str), mirror, - }) + } }) .collect_vec()) } diff --git a/frb_codegen/src/library/codegen/parser/mir/misc.rs b/frb_codegen/src/library/codegen/parser/mir/misc.rs index 97ca06a1ad..32965422ca 100644 --- a/frb_codegen/src/library/codegen/parser/mir/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/misc.rs @@ -1,16 +1,16 @@ -use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnumWrapper; +use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnum; use crate::codegen::parser::mir::internal_config::RustInputNamespacePack; use crate::utils::namespace::NamespacedName; use itertools::Itertools; use std::collections::HashMap; -pub(crate) fn extract_src_types_in_paths, I>( - src_items: &HashMap, +pub(crate) fn extract_src_types_in_paths( + src_items: &HashMap>, rust_input_namespace_pack: &RustInputNamespacePack, ) -> anyhow::Result> { Ok((src_items.iter()) .filter_map(|(k, v)| { - let namespace = &v.inner().namespaced_name.namespace; + let namespace = &v.namespaced_name.namespace; if rust_input_namespace_pack.is_interest(namespace) { Some(NamespacedName::new(namespace.to_owned(), k.to_owned())) } else { diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs index 8bc4aacb07..72389423a2 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs @@ -1,4 +1,3 @@ -use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnumWrapper; use crate::codegen::ir::mir::ty::MirType; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::external_impl; @@ -10,11 +9,11 @@ use std::collections::{HashMap, HashSet}; use std::fmt::Debug; use std::hash::Hash; use syn::{Ident, Type}; +use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnum; -pub(super) trait EnumOrStructParser +pub(super) trait EnumOrStructParser where Id: From + Clone + PartialEq + Eq + Hash, - SrcObj: HirStructOrEnumWrapper + Clone + Debug, { fn parse( &mut self, @@ -100,14 +99,14 @@ where fn parse_inner_impl( &mut self, - src_object: &SrcObj, + src_object: &HirStructOrEnum, name: NamespacedName, wrapper_name: Option, ) -> anyhow::Result; fn construct_output(&self, ident: Id) -> anyhow::Result; - fn src_objects(&self) -> &HashMap; + fn src_objects(&self) -> &HashMap>; fn parser_info(&mut self) -> &mut EnumOrStructParserInfo; From ea3d0be02c8be106ca03eec387a333e9cd3aa699 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:50:34 +0800 Subject: [PATCH 13/60] fix: err --- .../codegen/parser/mir/type_parser/enumeration.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs index 7c4b24a6f4..7568958d7a 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs @@ -39,7 +39,6 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { ) -> anyhow::Result { let comments = parse_comments(&src_enum.0.src.attrs); let raw_variants = src_enum - .0 .src .variants .iter() @@ -65,7 +64,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { ) -> anyhow::Result { Ok(MirVariant { name: MirIdent::new(variant.ident.to_string()), - wrapper_name: MirIdent::new(format!("{}_{}", src_enum.0.ident, variant.ident)), + wrapper_name: MirIdent::new(format!("{}_{}", src_enum.ident, variant.ident)), comments: parse_comments(&variant.attrs), kind: match variant.fields.iter().next() { None => MirVariantKind::Value, @@ -86,7 +85,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { field_ident: &Option, ) -> anyhow::Result { let variant_ident = variant.ident.to_string(); - let enum_name = &src_enum.0.namespaced_name; + let enum_name = &src_enum.namespaced_name; let variant_namespace = enum_name.namespace.join(&enum_name.name); let attributes = FrbAttributes::parse(attrs)?; Ok(MirVariantKind::Struct(MirStruct { @@ -117,7 +116,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { comments: parse_comments(&field.attrs), default: FrbAttributes::parse(&field.attrs)?.default_value(), settings: MirFieldSettings { - is_in_mirrored_enum: src_enum.0.mirror, + is_in_mirrored_enum: src_enum.mirror, }, }) }) @@ -128,7 +127,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { struct EnumOrStructParserEnum<'a, 'b, 'c, 'd>(&'d mut TypeParserWithContext<'a, 'b, 'c>); -impl EnumOrStructParser +impl EnumOrStructParser for EnumOrStructParserEnum<'_, '_, '_, '_> { fn parse_inner_impl( From 84271bfd6613be170355b9c0717368870c5f3b6d Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:51:11 +0800 Subject: [PATCH 14/60] fix: more --- .../codegen/ir/hir/hierarchical/struct_or_enum.rs | 4 ++-- frb_codegen/src/library/codegen/parser/hir/flat/mod.rs | 4 ++-- .../codegen/parser/hir/hierarchical/struct_or_enum.rs | 4 ++-- .../codegen/parser/mir/type_parser/structure.rs | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs index 25fceebf87..a9d65f0c56 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs @@ -27,11 +27,11 @@ pub type HirStruct = HirStructOrEnum; pub type HirEnum = HirStructOrEnum; impl HirStructOrEnum { - fn attrs(&self) -> &[Attribute] { + pub(crate) fn attrs(&self) -> &[Attribute] { &self.src.attrs } - fn with_namespace(&self, namespace: Namespace) -> Self { + pub(crate) fn with_namespace(&self, namespace: Namespace) -> Self { Self { namespaced_name: NamespacedName::new(namespace, self.namespaced_name.name.clone()), ..self.to_owned() diff --git a/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs b/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs index 72d7c5a304..57f91a79c8 100644 --- a/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs @@ -48,7 +48,7 @@ fn collect_structs(hir_pack: &HirPack) -> HashMap { collect_objects_map( hir_pack, |module| &module.content.structs, - |x| (x.0.ident.to_string(), x), + |x| (x.ident.to_string(), x), ) } @@ -56,7 +56,7 @@ fn collect_enums(hir_pack: &HirPack) -> HashMap { collect_objects_map( hir_pack, |module| &module.content.enums, - |x| (x.0.ident.to_string(), x), + |x| (x.ident.to_string(), x), ) } diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs index a5bfcc5a3a..e182568105 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs @@ -22,13 +22,13 @@ pub(crate) fn parse_syn_item_enum( parse_syn_item_struct_or_enum(item, namespace, &item.ident, &item.attrs, &item.vis) } -fn parse_syn_item_struct_or_enum( +fn parse_syn_item_struct_or_enum( item: &I, namespace: &Namespace, item_ident: &Ident, item_attrs: &[Attribute], item_vis: &syn::Visibility, -) -> anyhow::Result> { +) -> anyhow::Result>> { debug!("parse_syn_item_struct_or_enum item_ident={item_ident:?}"); let ParseMirrorIdentOutput { idents, mirror } = parse_mirror_ident(item_ident, item_attrs)?; diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs index 2a65000cd8..4c241070a3 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/structure.rs @@ -31,12 +31,12 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { name: NamespacedName, wrapper_name: Option, ) -> anyhow::Result { - let (is_fields_named, struct_fields) = match &src_struct.0.src.fields { + let (is_fields_named, struct_fields) = match &src_struct.src.fields { Fields::Named(FieldsNamed { named, .. }) => (true, named), Fields::Unnamed(FieldsUnnamed { unnamed, .. }) => (false, unnamed), // This will stop the whole generator and tell the users, so we do not care about testing it // frb-coverage:ignore-start - Fields::Unit => bail!("struct with unit fields are not supported yet, what about using `struct {} {{}}` instead", src_struct.0.ident), + Fields::Unit => bail!("struct with unit fields are not supported yet, what about using `struct {} {{}}` instead", src_struct.ident), // frb-coverage:ignore-end }; @@ -46,9 +46,9 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { .map(|(idx, field)| self.parse_struct_field(idx, field)) .collect::>>()?; - let comments = parse_comments(&src_struct.0.src.attrs); + let comments = parse_comments(&src_struct.src.attrs); - let attributes = FrbAttributes::parse(&src_struct.0.src.attrs)?; + let attributes = FrbAttributes::parse(&src_struct.src.attrs)?; let dart_metadata = attributes.dart_metadata(); Ok(MirStruct { @@ -85,7 +85,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { struct EnumOrStructParserStruct<'a, 'b, 'c, 'd>(&'d mut TypeParserWithContext<'a, 'b, 'c>); -impl EnumOrStructParser +impl EnumOrStructParser for EnumOrStructParserStruct<'_, '_, '_, '_> { fn parse_inner_impl( From 78b394302ab1f1189dd3b482bd83e557f052e0b2 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:51:55 +0800 Subject: [PATCH 15/60] fix: more --- .../codegen/parser/mir/type_parser/enum_or_struct.rs | 6 +++--- .../library/codegen/parser/mir/type_parser/enumeration.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs index 72389423a2..780f8a15fd 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs @@ -36,7 +36,7 @@ where if let Some(src_object) = self.src_objects().get(&name) { let src_object = (*src_object).clone(); - let namespace = &src_object.inner().namespaced_name.namespace; + let namespace = &src_object.namespaced_name.namespace; let namespaced_name = NamespacedName::new(namespace.clone(), name.clone()); let attrs = FrbAttributes::parse(src_object.attrs())?; @@ -51,8 +51,8 @@ where if (self.parser_info().parsing_or_parsed_objects).insert(namespaced_name.clone()) { let (name, wrapper_name) = compute_name_and_wrapper_name( &namespaced_name.namespace, - &src_object.inner().ident, - src_object.inner().mirror, + &src_object.ident, + src_object.mirror, ); let parsed_object = self.parse_inner_impl(&src_object, name, wrapper_name)?; (self.parser_info().object_pool).insert(ident.clone(), parsed_object); diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs index 7568958d7a..3c2ad40fb9 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enumeration.rs @@ -37,7 +37,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { name: NamespacedName, wrapper_name: Option, ) -> anyhow::Result { - let comments = parse_comments(&src_enum.0.src.attrs); + let comments = parse_comments(&src_enum.src.attrs); let raw_variants = src_enum .src .variants From fc1be481ce5cdefd6f22fc7b8a609228bb046264 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 16:52:20 +0800 Subject: [PATCH 16/60] fix: more --- .../src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs index a9d65f0c56..8a49e2f9e3 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs @@ -26,11 +26,13 @@ pub struct HirStructOrEnum { pub type HirStruct = HirStructOrEnum; pub type HirEnum = HirStructOrEnum; -impl HirStructOrEnum { +impl HirStructOrEnum { pub(crate) fn attrs(&self) -> &[Attribute] { &self.src.attrs } +} +impl HirStructOrEnum { pub(crate) fn with_namespace(&self, namespace: Namespace) -> Self { Self { namespaced_name: NamespacedName::new(namespace, self.namespaced_name.name.clone()), From 70ff7c18c24c535501071f2c377096671cc4eba9 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:12:11 +0800 Subject: [PATCH 17/60] feat: more --- .../library/codegen/ir/hir/hierarchical/mod.rs | 1 + .../hir/hierarchical/syn_item_struct_or_enum.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs index abf94fe33b..fe5f0893c5 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs @@ -4,3 +4,4 @@ pub(crate) mod module; pub(crate) mod pack; pub(crate) mod struct_or_enum; pub(crate) mod type_alias; +mod syn_item_struct_or_enum; diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs new file mode 100644 index 0000000000..04db052110 --- /dev/null +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs @@ -0,0 +1,16 @@ +pub(crate) trait SynItemStructOrEnum { + +} + +macro_rules! impl_trait { + ($name:ident) => { + impl SynItemStructOrEnum for $name { + fn attrs(&self) -> &[syn::Attribute] { + &self.attrs + } + } + }; +} + +impl_trait!(syn::ItemStruct); +impl_trait!(syn::ItemEnum); \ No newline at end of file From 112a708400b68ee53603279d508d9e91286d3f98 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:13:07 +0800 Subject: [PATCH 18/60] feat: more --- .../codegen/ir/hir/hierarchical/struct_or_enum.rs | 11 +++-------- .../ir/hir/hierarchical/syn_item_struct_or_enum.rs | 6 +++--- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs index 8a49e2f9e3..2669e24a62 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs @@ -5,13 +5,14 @@ use proc_macro2::Ident; use quote::ToTokens; use serde::{Serialize, Serializer}; use syn::{Attribute, ItemEnum, ItemStruct}; +use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; // This struct is surely used many times, but coverage tool thinks it is never used // (possibly because of the macro?), so we manually exclude it from coverage report // frb-coverage:ignore-start #[derive(Clone, Derivative, Serialize)] #[derivative(Debug)] -pub struct HirStructOrEnum { +pub struct HirStructOrEnum { #[serde(serialize_with = "serialize_syn")] pub(crate) ident: Ident, #[derivative(Debug = "ignore")] @@ -26,13 +27,7 @@ pub struct HirStructOrEnum { pub type HirStruct = HirStructOrEnum; pub type HirEnum = HirStructOrEnum; -impl HirStructOrEnum { - pub(crate) fn attrs(&self) -> &[Attribute] { - &self.src.attrs - } -} - -impl HirStructOrEnum { +impl HirStructOrEnum { pub(crate) fn with_namespace(&self, namespace: Namespace) -> Self { Self { namespaced_name: NamespacedName::new(namespace, self.namespaced_name.name.clone()), diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs index 04db052110..9cf494451e 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs @@ -1,5 +1,5 @@ -pub(crate) trait SynItemStructOrEnum { - +pub(crate) trait SynItemStructOrEnum: Clone { + fn attrs(&self) -> &[syn::Attribute]; } macro_rules! impl_trait { @@ -13,4 +13,4 @@ macro_rules! impl_trait { } impl_trait!(syn::ItemStruct); -impl_trait!(syn::ItemEnum); \ No newline at end of file +impl_trait!(syn::ItemEnum); From 4b95632c314db6791f56aa07ac1d977367ceac17 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:13:26 +0800 Subject: [PATCH 19/60] fix: err --- .../ir/hir/hierarchical/syn_item_struct_or_enum.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs index 9cf494451e..f788403c85 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs @@ -1,5 +1,7 @@ +use syn::*; + pub(crate) trait SynItemStructOrEnum: Clone { - fn attrs(&self) -> &[syn::Attribute]; + fn attrs(&self) -> &[Attribute]; } macro_rules! impl_trait { @@ -12,5 +14,5 @@ macro_rules! impl_trait { }; } -impl_trait!(syn::ItemStruct); -impl_trait!(syn::ItemEnum); +impl_trait!(ItemStruct); +impl_trait!(ItemEnum); From 21850635fff0bb6c38e00b7923629722a08286b1 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:14:07 +0800 Subject: [PATCH 20/60] feat: more --- frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs | 2 +- .../codegen/parser/hir/hierarchical/struct_or_enum.rs | 3 ++- frb_codegen/src/library/codegen/parser/mir/misc.rs | 3 ++- .../library/codegen/parser/mir/type_parser/enum_or_struct.rs | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs index fe5f0893c5..8a6bd5a804 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs @@ -4,4 +4,4 @@ pub(crate) mod module; pub(crate) mod pack; pub(crate) mod struct_or_enum; pub(crate) mod type_alias; -mod syn_item_struct_or_enum; +pub(crate) mod syn_item_struct_or_enum; diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs index e182568105..2d75e37ccb 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs @@ -7,6 +7,7 @@ use itertools::Itertools; use log::debug; use proc_macro2::Ident; use syn::{Attribute, ItemEnum, ItemStruct}; +use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; pub(crate) fn parse_syn_item_struct( item: &ItemStruct, @@ -22,7 +23,7 @@ pub(crate) fn parse_syn_item_enum( parse_syn_item_struct_or_enum(item, namespace, &item.ident, &item.attrs, &item.vis) } -fn parse_syn_item_struct_or_enum( +fn parse_syn_item_struct_or_enum( item: &I, namespace: &Namespace, item_ident: &Ident, diff --git a/frb_codegen/src/library/codegen/parser/mir/misc.rs b/frb_codegen/src/library/codegen/parser/mir/misc.rs index 32965422ca..e96cbcdd39 100644 --- a/frb_codegen/src/library/codegen/parser/mir/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/misc.rs @@ -1,10 +1,11 @@ use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnum; +use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; use crate::codegen::parser::mir::internal_config::RustInputNamespacePack; use crate::utils::namespace::NamespacedName; use itertools::Itertools; use std::collections::HashMap; -pub(crate) fn extract_src_types_in_paths( +pub(crate) fn extract_src_types_in_paths( src_items: &HashMap>, rust_input_namespace_pack: &RustInputNamespacePack, ) -> anyhow::Result> { diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs index 780f8a15fd..3927dafaab 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs @@ -1,3 +1,5 @@ +use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnum; +use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; use crate::codegen::ir::mir::ty::MirType; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::external_impl; @@ -9,9 +11,8 @@ use std::collections::{HashMap, HashSet}; use std::fmt::Debug; use std::hash::Hash; use syn::{Ident, Type}; -use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnum; -pub(super) trait EnumOrStructParser +pub(super) trait EnumOrStructParser where Id: From + Clone + PartialEq + Eq + Hash, { From 36e4a7a3c6bd2e8a5cfadcffe7ca692e155376d8 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:14:12 +0800 Subject: [PATCH 21/60] fix: err --- .../library/codegen/parser/mir/type_parser/enum_or_struct.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs index 3927dafaab..5833e69f26 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/enum_or_struct.rs @@ -40,7 +40,7 @@ where let namespace = &src_object.namespaced_name.namespace; let namespaced_name = NamespacedName::new(namespace.clone(), name.clone()); - let attrs = FrbAttributes::parse(src_object.attrs())?; + let attrs = FrbAttributes::parse(src_object.src.attrs())?; let attrs_opaque = override_opaque.or(attrs.opaque()); if attrs_opaque == Some(true) { debug!("Treat {name} as opaque since attribute says so"); From d396e02e86de9b3c2066ddc4dc2db0f7a5527e1e Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:14:24 +0800 Subject: [PATCH 22/60] chore: lint --- .../src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs index 2669e24a62..41b3e954c4 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs @@ -4,7 +4,7 @@ use derivative::Derivative; use proc_macro2::Ident; use quote::ToTokens; use serde::{Serialize, Serializer}; -use syn::{Attribute, ItemEnum, ItemStruct}; +use syn::{ItemEnum, ItemStruct}; use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; // This struct is surely used many times, but coverage tool thinks it is never used From bffe6e2d7735d0b179940cf91a3a75789030c62f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:15:36 +0800 Subject: [PATCH 23/60] feat: more --- .../third_party_override_transformer.rs | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index b2bca5c54a..f981a470ac 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -6,20 +6,8 @@ use crate::utils::crate_name::CrateName; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { if let Some(module_third_party_root) = remove_module_third_party_root(&mut pack) { - for module_third_party_crate in module_third_party_root.content.modules { - let crate_name = CrateName::new( - (module_third_party_crate.meta.namespace.path().last()) - .unwrap() - .to_string(), - ); - if let Some(target_crate) = pack.crates.get_mut(&crate_name) { - transform_crate(target_crate, module_third_party_crate)?; - } else { - log::warn!( - "Skip `{}` since there is no corresponding scanned third party crate.", - module_third_party_crate.meta.namespace, - ); - } + for src in module_third_party_root.content.modules { + transform_crate(&mut pack, src); } } Ok(pack) @@ -33,6 +21,22 @@ fn remove_module_third_party_root(pack: &mut HirPack) -> Option { .remove_module_by_name(THIRD_PARTY_DIR_NAME) } -fn transform_crate(target: &mut HirCrate, src: HirModule) -> anyhow::Result<()> { - todo!() +fn transform_crate(pack: &mut HirPack, src: HirModule) -> anyhow::Result<()> { + let crate_name = CrateName::new( + (module_third_party_crate.meta.namespace.path().last()) + .unwrap() + .to_string(), + ); + if let Some(target_crate) = pack.crates.get_mut(&crate_name) { + transform_module(target_crate.root_module, module_third_party_crate)?; + } else { + log::warn!( + "Skip `{}` since there is no corresponding scanned third party crate.", + module_third_party_crate.meta.namespace, + ); + } +} + +fn transform_module(target: &mut HirModule, src: HirModule) -> anyhow::Result<()> { + TODO } From 77b7b6c8d9d29933a8fd784cd15e9cd08bc21298 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:16:26 +0800 Subject: [PATCH 24/60] feat: more --- .../third_party_override_transformer.rs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index f981a470ac..bbd88bb873 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -35,8 +35,31 @@ fn transform_crate(pack: &mut HirPack, src: HirModule) -> anyhow::Result<()> { module_third_party_crate.meta.namespace, ); } + + Ok(()) } fn transform_module(target: &mut HirModule, src: HirModule) -> anyhow::Result<()> { - TODO + transform_module_content_function(target, src)?; + transform_module_content_struct_or_enum(target, src)?; + transform_module_content_module(target, src)?; + Ok(()) +} + +fn transform_module_content_function(target: &mut HirModule, src: HirModule) -> anyhow::Result<()> { + TODO; + Ok(()) +} + +fn transform_module_content_struct_or_enum( + target: &mut HirModule, + src: HirModule, +) -> anyhow::Result<()> { + TODO; + Ok(()) +} + +fn transform_module_content_module(target: &mut HirModule, src: HirModule) -> anyhow::Result<()> { + TODO; + Ok(()) } From c3f6a27af028a8949e69c5e5d7662656868873cb Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:17:27 +0800 Subject: [PATCH 25/60] feat: more --- .../third_party_override_transformer.rs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index bbd88bb873..48e45b0a3a 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -40,26 +40,32 @@ fn transform_crate(pack: &mut HirPack, src: HirModule) -> anyhow::Result<()> { } fn transform_module(target: &mut HirModule, src: HirModule) -> anyhow::Result<()> { - transform_module_content_function(target, src)?; - transform_module_content_struct_or_enum(target, src)?; - transform_module_content_module(target, src)?; + transform_module_content_function(target, src.content.functions)?; + transform_module_content_struct_or_enum(target, src.content.structs)?; + transform_module_content_struct_or_enum(target, src.content.enums)?; + transform_module_content_module(target, src.content.modules)?; Ok(()) } -fn transform_module_content_function(target: &mut HirModule, src: HirModule) -> anyhow::Result<()> { +fn transform_module_content_function( + target: &mut HirModule, + src_content_functions: TODO, +) -> anyhow::Result<()> { TODO; Ok(()) } fn transform_module_content_struct_or_enum( target: &mut HirModule, - src: HirModule, + src_content_struct_or_enums: TODO, ) -> anyhow::Result<()> { TODO; Ok(()) } -fn transform_module_content_module(target: &mut HirModule, src: HirModule) -> anyhow::Result<()> { - TODO; +fn transform_module_content_module( + target: &mut HirModule, + src_content_modules: Vec, +) -> anyhow::Result<()> { Ok(()) } From 144e91a98caa4753dc8efd781d5329e5d6940b30 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:18:58 +0800 Subject: [PATCH 26/60] feat: more --- .../src/library/codegen/ir/hir/hierarchical/module.rs | 5 +++++ .../hierarchical/third_party_override_transformer.rs | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs index 9d7bcab364..7a54b5cff4 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs @@ -68,6 +68,11 @@ impl HirModuleContent { .map(|i| &self.modules[i]) } + pub(crate) fn get_mut_module_by_name(&self, mod_name: &str) -> Option<&mut HirModule> { + self.get_module_index_by_name(mod_name) + .map(|i| &self.modules.get_mut(i)) + } + pub(crate) fn remove_module_by_name(&mut self, mod_name: &str) -> Option { self.get_module_index_by_name(mod_name) .map(|index| self.modules.remove(index)) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 48e45b0a3a..241e9efdc5 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -67,5 +67,16 @@ fn transform_module_content_module( target: &mut HirModule, src_content_modules: Vec, ) -> anyhow::Result<()> { + for src_child_module in src_content_modules { + let name = TODO; + if let Some(target_child_module) = target.content.get_mut_module_by_name(name) { + transform_module(target_child_module, src_child_module)?; + } else { + log::warn!( + "Skip `{}` since there is no corresponding scanned third party crate target module.", + src_child_module.meta.namespace, + ); + } + } Ok(()) } From 8387f301eb4a7f974bf210225f26497b78015661 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:19:14 +0800 Subject: [PATCH 27/60] feat: more --- .../parser/hir/hierarchical/third_party_override_transformer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 241e9efdc5..47a2d36ade 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -68,7 +68,7 @@ fn transform_module_content_module( src_content_modules: Vec, ) -> anyhow::Result<()> { for src_child_module in src_content_modules { - let name = TODO; + let name = *src_child_module.meta.namespace.path().last().unwrap(); if let Some(target_child_module) = target.content.get_mut_module_by_name(name) { transform_module(target_child_module, src_child_module)?; } else { From f0b38cea953819c071c8a8e019f074b487889a72 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:19:34 +0800 Subject: [PATCH 28/60] feat: more --- .../hir/hierarchical/third_party_override_transformer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 47a2d36ade..150a879402 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -1,4 +1,5 @@ use crate::codegen::ir::hir::hierarchical::crates::HirCrate; +use crate::codegen::ir::hir::hierarchical::function::HirFunction; use crate::codegen::ir::hir::hierarchical::module::HirModule; use crate::codegen::ir::hir::hierarchical::pack::HirPack; use crate::codegen::misc::THIRD_PARTY_DIR_NAME; @@ -49,7 +50,7 @@ fn transform_module(target: &mut HirModule, src: HirModule) -> anyhow::Result<() fn transform_module_content_function( target: &mut HirModule, - src_content_functions: TODO, + src_content_functions: Vec, ) -> anyhow::Result<()> { TODO; Ok(()) From 924f61a4f05303245a8bfec78e417ae29b9c0569 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:19:53 +0800 Subject: [PATCH 29/60] chore: more --- .../third_party_override_transformer.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 150a879402..f2f44bcdf9 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -41,22 +41,24 @@ fn transform_crate(pack: &mut HirPack, src: HirModule) -> anyhow::Result<()> { } fn transform_module(target: &mut HirModule, src: HirModule) -> anyhow::Result<()> { - transform_module_content_function(target, src.content.functions)?; - transform_module_content_struct_or_enum(target, src.content.structs)?; - transform_module_content_struct_or_enum(target, src.content.enums)?; - transform_module_content_module(target, src.content.modules)?; + transform_module_content_functions(target, src.content.functions)?; + transform_module_content_struct_or_enums(target, src.content.structs)?; + transform_module_content_struct_or_enums(target, src.content.enums)?; + transform_module_content_modules(target, src.content.modules)?; Ok(()) } -fn transform_module_content_function( +fn transform_module_content_functions( target: &mut HirModule, src_content_functions: Vec, ) -> anyhow::Result<()> { - TODO; + for src_function in src_content_functions { + TODO; + } Ok(()) } -fn transform_module_content_struct_or_enum( +fn transform_module_content_struct_or_enums( target: &mut HirModule, src_content_struct_or_enums: TODO, ) -> anyhow::Result<()> { @@ -64,7 +66,7 @@ fn transform_module_content_struct_or_enum( Ok(()) } -fn transform_module_content_module( +fn transform_module_content_modules( target: &mut HirModule, src_content_modules: Vec, ) -> anyhow::Result<()> { From 5d99a173d8ee61cfe262ff84e7d445ab6928ad37 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:20:58 +0800 Subject: [PATCH 30/60] fix: err --- .../src/library/codegen/ir/hir/hierarchical/module.rs | 2 +- .../hierarchical/third_party_override_transformer.rs | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs index 7a54b5cff4..8f4a19db56 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs @@ -70,7 +70,7 @@ impl HirModuleContent { pub(crate) fn get_mut_module_by_name(&self, mod_name: &str) -> Option<&mut HirModule> { self.get_module_index_by_name(mod_name) - .map(|i| &self.modules.get_mut(i)) + .map(|i| &self.modules.get_mut(i).unwrap()) } pub(crate) fn remove_module_by_name(&mut self, mod_name: &str) -> Option { diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index f2f44bcdf9..f02319d8c2 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -23,17 +23,13 @@ fn remove_module_third_party_root(pack: &mut HirPack) -> Option { } fn transform_crate(pack: &mut HirPack, src: HirModule) -> anyhow::Result<()> { - let crate_name = CrateName::new( - (module_third_party_crate.meta.namespace.path().last()) - .unwrap() - .to_string(), - ); + let crate_name = CrateName::new((src.meta.namespace.path().last()).unwrap().to_string()); if let Some(target_crate) = pack.crates.get_mut(&crate_name) { - transform_module(target_crate.root_module, module_third_party_crate)?; + transform_module(&mut target_crate.root_module, src)?; } else { log::warn!( "Skip `{}` since there is no corresponding scanned third party crate.", - module_third_party_crate.meta.namespace, + src.meta.namespace, ); } From 2e44a67e081c2c0baf0a9cd7e91823a625e88674 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:21:29 +0800 Subject: [PATCH 31/60] chore: compile --- .../hir/hierarchical/third_party_override_transformer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index f02319d8c2..4ae167042d 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -49,16 +49,16 @@ fn transform_module_content_functions( src_content_functions: Vec, ) -> anyhow::Result<()> { for src_function in src_content_functions { - TODO; + todo!(); } Ok(()) } fn transform_module_content_struct_or_enums( target: &mut HirModule, - src_content_struct_or_enums: TODO, + src_content_struct_or_enums: (), // TODO ) -> anyhow::Result<()> { - TODO; + todo!(); Ok(()) } From 704b0a6029e13339d7ebf0213c13882f94ce95f0 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:22:11 +0800 Subject: [PATCH 32/60] fix: more --- frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs | 4 ++-- .../hir/hierarchical/third_party_override_transformer.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs index 8f4a19db56..3cbeee5fc1 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/module.rs @@ -68,9 +68,9 @@ impl HirModuleContent { .map(|i| &self.modules[i]) } - pub(crate) fn get_mut_module_by_name(&self, mod_name: &str) -> Option<&mut HirModule> { + pub(crate) fn get_mut_module_by_name(&mut self, mod_name: &str) -> Option<&mut HirModule> { self.get_module_index_by_name(mod_name) - .map(|i| &self.modules.get_mut(i).unwrap()) + .map(|i| self.modules.get_mut(i).unwrap()) } pub(crate) fn remove_module_by_name(&mut self, mod_name: &str) -> Option { diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 4ae167042d..a61153a8bc 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -54,9 +54,9 @@ fn transform_module_content_functions( Ok(()) } -fn transform_module_content_struct_or_enums( +fn transform_module_content_struct_or_enums( target: &mut HirModule, - src_content_struct_or_enums: (), // TODO + src_content_struct_or_enums: T, ) -> anyhow::Result<()> { todo!(); Ok(()) From 3fd0b215ffbf84c8cbd62853596b4ba54fdd902a Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:22:28 +0800 Subject: [PATCH 33/60] refactor: vis --- frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs index c77adc2d4b..b5a9f6248c 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -32,7 +32,7 @@ impl HirFunction { } impl HirFunctionInner { - pub(crate) fn sig(&self) -> &Signature { + fn sig(&self) -> &Signature { match self { HirFunctionInner::Function { item_fn } => &item_fn.sig, HirFunctionInner::Method { impl_item_fn, .. } => &impl_item_fn.sig, From 4d43217e43c80be5684bf9926d5f94f1472aae78 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:23:30 +0800 Subject: [PATCH 34/60] feat: more --- .../src/library/codegen/parser/mir/function_parser/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs index db3c5e1ca8..8fb854aaf1 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs @@ -103,7 +103,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { return Ok(create_output_skip(func, namespace_naive, IgnoredMisc)); }; - let func_name = parse_name(sig, &owner); + let func_name = parse_name(sig.ident, &owner); if attributes.ignore() { return Ok(create_output_skip(func, namespace_naive, IgnoredMisc)); @@ -227,9 +227,9 @@ fn compute_func_mode(attributes: &FrbAttributes, info: &FunctionPartialInfo) -> }) } -fn parse_name(sig: &Signature, owner: &MirFuncOwnerInfo) -> String { +fn parse_name(sig_ident: &Ident, owner: &MirFuncOwnerInfo) -> String { match owner { - MirFuncOwnerInfo::Function => sig.ident.to_string(), + MirFuncOwnerInfo::Function => sig_ident.to_string(), MirFuncOwnerInfo::Method(method) => parse_effective_function_name_of_method(method), } } From 6f33f0bcbdf212fe1e2f7b9e119a3bc5982eed7d Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:24:23 +0800 Subject: [PATCH 35/60] feat: more --- .../codegen/ir/hir/hierarchical/function.rs | 4 ++++ .../codegen/parser/mir/function_parser/mod.rs | 19 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs index b5a9f6248c..f29250848e 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -39,6 +39,10 @@ impl HirFunctionInner { } } + pub(crate) fn name(&self) -> String { + self.sig().ident.to_string() + } + pub(crate) fn attrs(&self) -> &Vec { match self { HirFunctionInner::Function { item_fn } => &item_fn.attrs, diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs index 8fb854aaf1..85c44aab75 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/mod.rs @@ -57,7 +57,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { .unwrap_or_else(|err| { log::debug!( "parse_function see error and skip function: function={:?} error={:?}", - func.sig().ident, + func.name(), err ); create_output_skip(func, namespace_naive, MirSkipReason::Err) @@ -73,7 +73,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { default_stream_sink_codec: CodecMode, default_rust_opaque_codec: RustOpaqueCodecMode, ) -> anyhow::Result { - debug!("parse_function function name: {:?}", func.sig().ident); + debug!("parse_function function name: {:?}", func.name()); if !matches!(func.vis(), Visibility::Public(_)) { return Ok(create_output_skip( @@ -83,7 +83,6 @@ impl<'a, 'b> FunctionParser<'a, 'b> { )); } - let sig = func.sig(); let src_lineno = func.span().start().line; let attributes = FrbAttributes::parse(func.attrs())?; @@ -103,7 +102,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { return Ok(create_output_skip(func, namespace_naive, IgnoredMisc)); }; - let func_name = parse_name(sig.ident, &owner); + let func_name = parse_name(&func.name(), &owner); if attributes.ignore() { return Ok(create_output_skip(func, namespace_naive, IgnoredMisc)); @@ -111,10 +110,10 @@ impl<'a, 'b> FunctionParser<'a, 'b> { let context = create_context(Some(owner.clone())); let mut info = FunctionPartialInfo::default(); - for sig_input in sig.inputs.iter() { + for sig_input in func.sig().inputs.iter() { info = info.merge(self.parse_fn_arg(sig_input, &owner, &context)?)?; } - info = info.merge(self.parse_fn_output(sig, &context)?)?; + info = info.merge(self.parse_fn_output(func.sig(), &context)?)?; info = self.transform_fn_info(info); let codec_mode_pack = compute_codec_mode_pack(&attributes, force_codec_mode_pack); @@ -138,7 +137,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { owner, mode, stream_dart_await, - rust_async: sig.asyncness.is_some(), + rust_async: func.sig().asyncness.is_some(), initializer: attributes.init(), accessor: attributes.accessor(), arg_mode: if attributes.positional() { @@ -214,7 +213,7 @@ fn create_output_skip( reason: MirSkipReason, ) -> ParseFunctionOutput { ParseFunctionOutput::Skip(MirSkip { - name: NamespacedName::new(namespace_naive.to_owned(), func.sig().ident.to_string()), + name: NamespacedName::new(namespace_naive.to_owned(), func.name().to_string()), reason, }) } @@ -227,9 +226,9 @@ fn compute_func_mode(attributes: &FrbAttributes, info: &FunctionPartialInfo) -> }) } -fn parse_name(sig_ident: &Ident, owner: &MirFuncOwnerInfo) -> String { +fn parse_name(function_sig_ident_raw_name: &str, owner: &MirFuncOwnerInfo) -> String { match owner { - MirFuncOwnerInfo::Function => sig_ident.to_string(), + MirFuncOwnerInfo::Function => function_sig_ident_raw_name.to_string(), MirFuncOwnerInfo::Method(method) => parse_effective_function_name_of_method(method), } } From 3891d1f0cc8e29be7ac2598f5a4c79fc30706cb0 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:25:07 +0800 Subject: [PATCH 36/60] refactor: pub back --- frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs index f29250848e..2ff01a635e 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -32,7 +32,7 @@ impl HirFunction { } impl HirFunctionInner { - fn sig(&self) -> &Signature { + pub(crate) fn sig(&self) -> &Signature { match self { HirFunctionInner::Function { item_fn } => &item_fn.sig, HirFunctionInner::Method { impl_item_fn, .. } => &impl_item_fn.sig, From e0b9ce7927609f36a18be30fc2b0d9af519449bb Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:25:30 +0800 Subject: [PATCH 37/60] feat: ty --- .../hir/hierarchical/third_party_override_transformer.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index a61153a8bc..2884eab9cd 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -2,6 +2,8 @@ use crate::codegen::ir::hir::hierarchical::crates::HirCrate; use crate::codegen::ir::hir::hierarchical::function::HirFunction; use crate::codegen::ir::hir::hierarchical::module::HirModule; use crate::codegen::ir::hir::hierarchical::pack::HirPack; +use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnum; +use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; use crate::codegen::misc::THIRD_PARTY_DIR_NAME; use crate::utils::crate_name::CrateName; @@ -54,9 +56,9 @@ fn transform_module_content_functions( Ok(()) } -fn transform_module_content_struct_or_enums( +fn transform_module_content_struct_or_enums( target: &mut HirModule, - src_content_struct_or_enums: T, + src_content_struct_or_enums: Vec>, ) -> anyhow::Result<()> { todo!(); Ok(()) From e977c579268f2323db1b24ddc9b923b8f54baca0 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:41:14 +0800 Subject: [PATCH 38/60] feat: more --- .../third_party_override_transformer.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 2884eab9cd..420a4f2511 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -50,17 +50,23 @@ fn transform_module_content_functions( target: &mut HirModule, src_content_functions: Vec, ) -> anyhow::Result<()> { - for src_function in src_content_functions { - todo!(); - } - Ok(()) + transform_module_content_attrable(target, src_content_functions) } fn transform_module_content_struct_or_enums( target: &mut HirModule, src_content_struct_or_enums: Vec>, ) -> anyhow::Result<()> { - todo!(); + transform_module_content_attrable(target, src_content_struct_or_enums) +} + +fn transform_module_content_attrable( + target: &mut HirModule, + src_items: Vec, +) -> anyhow::Result<()> { + for src_item in src_items { + TODO; + } Ok(()) } From c28a4d7d4eabc3ef3e6afa8b7a8ee55b020b3771 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:42:08 +0800 Subject: [PATCH 39/60] feat: more --- .../hierarchical/third_party_override_transformer.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 420a4f2511..68070453fc 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -39,29 +39,29 @@ fn transform_crate(pack: &mut HirPack, src: HirModule) -> anyhow::Result<()> { } fn transform_module(target: &mut HirModule, src: HirModule) -> anyhow::Result<()> { - transform_module_content_functions(target, src.content.functions)?; - transform_module_content_struct_or_enums(target, src.content.structs)?; - transform_module_content_struct_or_enums(target, src.content.enums)?; + transform_module_content_functions(&mut target.content.functions, src.content.functions)?; + transform_module_content_struct_or_enums(&mut target.content.structs, src.content.structs)?; + transform_module_content_struct_or_enums(&mut target.content.enums, src.content.enums)?; transform_module_content_modules(target, src.content.modules)?; Ok(()) } fn transform_module_content_functions( - target: &mut HirModule, + target: &mut Vec, src_content_functions: Vec, ) -> anyhow::Result<()> { transform_module_content_attrable(target, src_content_functions) } fn transform_module_content_struct_or_enums( - target: &mut HirModule, + target: &mut Vec>, src_content_struct_or_enums: Vec>, ) -> anyhow::Result<()> { transform_module_content_attrable(target, src_content_struct_or_enums) } fn transform_module_content_attrable( - target: &mut HirModule, + target: &mut Vec, src_items: Vec, ) -> anyhow::Result<()> { for src_item in src_items { From 583ba8ca43fc344e225a34f4f1be484eea3fa25b Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:42:51 +0800 Subject: [PATCH 40/60] feat: more --- .../hir/hierarchical/third_party_override_transformer.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 68070453fc..ff4028b529 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -50,19 +50,20 @@ fn transform_module_content_functions( target: &mut Vec, src_content_functions: Vec, ) -> anyhow::Result<()> { - transform_module_content_attrable(target, src_content_functions) + transform_module_content_attrable(target, src_content_functions, |x| x.inner.name()) } fn transform_module_content_struct_or_enums( target: &mut Vec>, src_content_struct_or_enums: Vec>, ) -> anyhow::Result<()> { - transform_module_content_attrable(target, src_content_struct_or_enums) + transform_module_content_attrable(target, src_content_struct_or_enums, |x| x.ident.to_string()) } fn transform_module_content_attrable( target: &mut Vec, src_items: Vec, + key: impl Fn(&T) -> String, ) -> anyhow::Result<()> { for src_item in src_items { TODO; From f5100f55e1fd1cecaa498efb2d5331b73e685a15 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:45:15 +0800 Subject: [PATCH 41/60] feat: more --- .../third_party_override_transformer.rs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index ff4028b529..93569828ab 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -1,3 +1,4 @@ +use std::fmt::Debug; use crate::codegen::ir::hir::hierarchical::crates::HirCrate; use crate::codegen::ir::hir::hierarchical::function::HirFunction; use crate::codegen::ir::hir::hierarchical::module::HirModule; @@ -6,6 +7,7 @@ use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStructOrEnum; use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; use crate::codegen::misc::THIRD_PARTY_DIR_NAME; use crate::utils::crate_name::CrateName; +use itertools::Itertools; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { if let Some(module_third_party_root) = remove_module_third_party_root(&mut pack) { @@ -60,12 +62,27 @@ fn transform_module_content_struct_or_enums( transform_module_content_attrable(target, src_content_struct_or_enums, |x| x.ident.to_string()) } -fn transform_module_content_attrable( - target: &mut Vec, +fn transform_module_content_attrable( + target_items: &mut Vec, src_items: Vec, key: impl Fn(&T) -> String, ) -> anyhow::Result<()> { for src_item in src_items { + let src_key = key(src_item); + + let interest_target_items = target_items + .iter_mut() + .filter(|x| key(x) == src_key) + .collect_vec(); + if interest_target_items.len() != 1 { + log::warn!( + "transform_module_content_attrable skip src_key={src_key} src_item={src_item:?},\ + since the number of corresponding target items is not one (indeed is {}).", + interest_target_items.len(), + ); + continue; + } + TODO; } Ok(()) From fcefbd232fe8d39d732ebfbeff935101b1ad0e7f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:45:46 +0800 Subject: [PATCH 42/60] feat: more --- .../hir/hierarchical/third_party_override_transformer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 93569828ab..9b119c1dfc 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -1,4 +1,3 @@ -use std::fmt::Debug; use crate::codegen::ir::hir::hierarchical::crates::HirCrate; use crate::codegen::ir::hir::hierarchical::function::HirFunction; use crate::codegen::ir::hir::hierarchical::module::HirModule; @@ -8,6 +7,7 @@ use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStruc use crate::codegen::misc::THIRD_PARTY_DIR_NAME; use crate::utils::crate_name::CrateName; use itertools::Itertools; +use std::fmt::Debug; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { if let Some(module_third_party_root) = remove_module_third_party_root(&mut pack) { @@ -82,6 +82,7 @@ fn transform_module_content_attrable( ); continue; } + let interest_target_item = interest_target_items.into_iter().next().unwrap(); TODO; } From 15f23903a6a6d8eb72a6aae704dcadcbe2bc2088 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:46:36 +0800 Subject: [PATCH 43/60] feat: more --- .../third_party_override_transformer.rs | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 9b119c1dfc..ba6e42dd35 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -52,20 +52,37 @@ fn transform_module_content_functions( target: &mut Vec, src_content_functions: Vec, ) -> anyhow::Result<()> { - transform_module_content_attrable(target, src_content_functions, |x| x.inner.name()) + transform_module_content_general_vec( + target, + src_content_functions, + |x| x.inner.name(), + |target, src| { + TODO; + TODO; + }, + ) } fn transform_module_content_struct_or_enums( target: &mut Vec>, src_content_struct_or_enums: Vec>, ) -> anyhow::Result<()> { - transform_module_content_attrable(target, src_content_struct_or_enums, |x| x.ident.to_string()) + transform_module_content_general_vec( + target, + src_content_struct_or_enums, + |x| x.ident.to_string(), + |target, src| { + TODO; + TODO; + }, + ) } -fn transform_module_content_attrable( +fn transform_module_content_general_vec( target_items: &mut Vec, src_items: Vec, key: impl Fn(&T) -> String, + write: impl Fn(&mut T, T), ) -> anyhow::Result<()> { for src_item in src_items { let src_key = key(src_item); @@ -82,9 +99,9 @@ fn transform_module_content_attrable( ); continue; } - let interest_target_item = interest_target_items.into_iter().next().unwrap(); + let target_item = interest_target_items.into_iter().next().unwrap(); - TODO; + write(target_item, src_item); } Ok(()) } From d6a2e536e47ce9d69455930db35e505c88a49ddc Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:47:58 +0800 Subject: [PATCH 44/60] feat: more --- .../src/library/codegen/ir/hir/hierarchical/function.rs | 7 +++++++ .../ir/hir/hierarchical/syn_item_struct_or_enum.rs | 8 +++++--- .../hir/hierarchical/third_party_override_transformer.rs | 6 ++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs index 2ff01a635e..39f36063c4 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -50,6 +50,13 @@ impl HirFunctionInner { } } + pub(crate) fn attrs_mut(&self) -> &mut Vec { + match self { + HirFunctionInner::Function { item_fn } => &mut item_fn.attrs, + HirFunctionInner::Method { impl_item_fn, .. } => &mut impl_item_fn.attrs, + } + } + pub(crate) fn span(&self) -> Span { match self { HirFunctionInner::Function { item_fn } => item_fn.span(), diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs index f788403c85..c26084fbd7 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs @@ -2,14 +2,16 @@ use syn::*; pub(crate) trait SynItemStructOrEnum: Clone { fn attrs(&self) -> &[Attribute]; + + fn attrs_mut(&mut self) -> &mut [Attribute]; } macro_rules! impl_trait { ($name:ident) => { impl SynItemStructOrEnum for $name { - fn attrs(&self) -> &[syn::Attribute] { - &self.attrs - } + fn attrs(&self) -> &[syn::Attribute] { &self.attrs } + + fn attrs_mut(&mut self) -> &mut [syn::Attribute] { &mut self.attrs } } }; } diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index ba6e42dd35..8b028e3815 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -57,8 +57,7 @@ fn transform_module_content_functions( src_content_functions, |x| x.inner.name(), |target, src| { - TODO; - TODO; + target.inner.attrs_mut().extend(src.inner.attrs().to_owned()); }, ) } @@ -72,8 +71,7 @@ fn transform_module_content_struct_or_enums( src_content_struct_or_enums, |x| x.ident.to_string(), |target, src| { - TODO; - TODO; + target.src.attrs_mut().extend(src.src.attrs().to_owned()); }, ) } From 279e62b300560ca766e48c5e7558e2b0b29cd3ce Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:48:26 +0800 Subject: [PATCH 45/60] fix: err --- .../src/library/codegen/ir/hir/hierarchical/function.rs | 2 +- .../codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs | 4 ++-- .../hir/hierarchical/third_party_override_transformer.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs index 39f36063c4..31d4ef96f3 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -50,7 +50,7 @@ impl HirFunctionInner { } } - pub(crate) fn attrs_mut(&self) -> &mut Vec { + pub(crate) fn attrs_mut(&mut self) -> &mut Vec { match self { HirFunctionInner::Function { item_fn } => &mut item_fn.attrs, HirFunctionInner::Method { impl_item_fn, .. } => &mut impl_item_fn.attrs, diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs index c26084fbd7..ec2ad68237 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs @@ -3,7 +3,7 @@ use syn::*; pub(crate) trait SynItemStructOrEnum: Clone { fn attrs(&self) -> &[Attribute]; - fn attrs_mut(&mut self) -> &mut [Attribute]; + fn attrs_mut(&mut self) -> &mut Vec; } macro_rules! impl_trait { @@ -11,7 +11,7 @@ macro_rules! impl_trait { impl SynItemStructOrEnum for $name { fn attrs(&self) -> &[syn::Attribute] { &self.attrs } - fn attrs_mut(&mut self) -> &mut [syn::Attribute] { &mut self.attrs } + fn attrs_mut(&mut self) -> &mut Vec { &mut self.attrs } } }; } diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 8b028e3815..3ca8f92a6c 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -83,7 +83,7 @@ fn transform_module_content_general_vec( write: impl Fn(&mut T, T), ) -> anyhow::Result<()> { for src_item in src_items { - let src_key = key(src_item); + let src_key = key(&src_item); let interest_target_items = target_items .iter_mut() From 1de0a0437d0083588ae7f944c4c48ab6764e4c2f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:48:44 +0800 Subject: [PATCH 46/60] chore: lint --- .../hir/hierarchical/third_party_override_transformer.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 3ca8f92a6c..5fbe9d6b0c 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -1,4 +1,3 @@ -use crate::codegen::ir::hir::hierarchical::crates::HirCrate; use crate::codegen::ir::hir::hierarchical::function::HirFunction; use crate::codegen::ir::hir::hierarchical::module::HirModule; use crate::codegen::ir::hir::hierarchical::pack::HirPack; @@ -12,7 +11,7 @@ use std::fmt::Debug; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { if let Some(module_third_party_root) = remove_module_third_party_root(&mut pack) { for src in module_third_party_root.content.modules { - transform_crate(&mut pack, src); + transform_crate(&mut pack, src)?; } } Ok(pack) From 5b77359ff4cd27ed1bb19189431db772571d13e7 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 17:51:27 +0800 Subject: [PATCH 47/60] chore: cp #2008 --- .../library/codegen/generator/api_dart/spec_generator/info.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/info.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/info.rs index d5ed68042c..bb8330fb67 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/info.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/info.rs @@ -177,8 +177,8 @@ impl<'a> ApiDartGeneratorInfoTrait for PrimitiveListApiDartGenerator<'a> { MirTypePrimitive::I16 => "Int16List", MirTypePrimitive::U32 => "Uint32List", MirTypePrimitive::I32 => "Int32List", - MirTypePrimitive::U64 => "Uint64List", - MirTypePrimitive::I64 => "Int64List", + MirTypePrimitive::U64 | MirTypePrimitive::Usize => "Uint64List", + MirTypePrimitive::I64 | MirTypePrimitive::Isize => "Int64List", MirTypePrimitive::F32 => "Float32List", MirTypePrimitive::F64 => "Float64List", // frb-coverage:ignore-start From cf989b14cec9f03e00e1a31f499a5d088d217c42 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:01:08 +0800 Subject: [PATCH 48/60] chore: lint --- .../src/library/codegen/ir/hir/hierarchical/mod.rs | 2 +- .../library/codegen/ir/hir/hierarchical/struct_or_enum.rs | 2 +- .../ir/hir/hierarchical/syn_item_struct_or_enum.rs | 8 ++++++-- .../codegen/parser/hir/hierarchical/struct_or_enum.rs | 2 +- .../hir/hierarchical/third_party_override_transformer.rs | 5 ++++- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs index 8a6bd5a804..9e95feff48 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs @@ -3,5 +3,5 @@ pub(crate) mod function; pub(crate) mod module; pub(crate) mod pack; pub(crate) mod struct_or_enum; -pub(crate) mod type_alias; pub(crate) mod syn_item_struct_or_enum; +pub(crate) mod type_alias; diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs index 41b3e954c4..f677f9d0a9 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs @@ -1,11 +1,11 @@ use crate::codegen::ir::hir::hierarchical::module::HirVisibility; +use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; use crate::utils::namespace::{Namespace, NamespacedName}; use derivative::Derivative; use proc_macro2::Ident; use quote::ToTokens; use serde::{Serialize, Serializer}; use syn::{ItemEnum, ItemStruct}; -use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; // This struct is surely used many times, but coverage tool thinks it is never used // (possibly because of the macro?), so we manually exclude it from coverage report diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs index ec2ad68237..105569329e 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/syn_item_struct_or_enum.rs @@ -9,9 +9,13 @@ pub(crate) trait SynItemStructOrEnum: Clone { macro_rules! impl_trait { ($name:ident) => { impl SynItemStructOrEnum for $name { - fn attrs(&self) -> &[syn::Attribute] { &self.attrs } + fn attrs(&self) -> &[syn::Attribute] { + &self.attrs + } - fn attrs_mut(&mut self) -> &mut Vec { &mut self.attrs } + fn attrs_mut(&mut self) -> &mut Vec { + &mut self.attrs + } } }; } diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs index 2d75e37ccb..025193b804 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/struct_or_enum.rs @@ -1,4 +1,5 @@ use crate::codegen::ir::hir::hierarchical::struct_or_enum::{HirEnum, HirStruct, HirStructOrEnum}; +use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; use crate::codegen::parser::hir::hierarchical::mirror_ident::{ parse_mirror_ident, ParseMirrorIdentOutput, }; @@ -7,7 +8,6 @@ use itertools::Itertools; use log::debug; use proc_macro2::Ident; use syn::{Attribute, ItemEnum, ItemStruct}; -use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStructOrEnum; pub(crate) fn parse_syn_item_struct( item: &ItemStruct, diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 5fbe9d6b0c..5f340095c1 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -56,7 +56,10 @@ fn transform_module_content_functions( src_content_functions, |x| x.inner.name(), |target, src| { - target.inner.attrs_mut().extend(src.inner.attrs().to_owned()); + target + .inner + .attrs_mut() + .extend(src.inner.attrs().to_owned()); }, ) } From 12029cea0a611c9f37b7963bfcdfac0ccb0f97d8 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:16:05 +0800 Subject: [PATCH 49/60] feat: more --- frb_codegen/src/library/utils/crate_name.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/frb_codegen/src/library/utils/crate_name.rs b/frb_codegen/src/library/utils/crate_name.rs index cfece0dd65..e8740fbf0c 100644 --- a/frb_codegen/src/library/utils/crate_name.rs +++ b/frb_codegen/src/library/utils/crate_name.rs @@ -2,18 +2,10 @@ use crate::utils::namespace::Namespace; use serde::{Deserialize, Serialize}; /// e.g. `web-audio-api` (note the `-` instead of `_`) -#[derive(Debug, Clone, Serialize, Deserialize, Hash)] +#[derive(Debug, Clone, Serialize, Deserialize, Hash, PartialEq, Eq)] #[serde(transparent)] pub(crate) struct CrateName(String); -impl PartialEq for CrateName { - fn eq(&self, other: &Self) -> bool { - self.namespace() == other.namespace() - } -} - -impl Eq for CrateName {} - impl CrateName { pub(crate) const SELF_CRATE: &'static str = "crate"; From 086767e1c489a66f8ad7a60e864b2fc7eedd4d07 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:17:16 +0800 Subject: [PATCH 50/60] feat: more --- .../src/library/codegen/ir/hir/hierarchical/crates.rs | 2 ++ .../src/library/codegen/ir/hir/hierarchical/pack.rs | 2 +- frb_codegen/src/library/codegen/ir/hir/raw/crates.rs | 9 +++++++++ frb_codegen/src/library/codegen/ir/hir/raw/mod.rs | 7 ++++--- 4 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 frb_codegen/src/library/codegen/ir/hir/raw/crates.rs diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/crates.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/crates.rs index 69dd5ca275..edf8d78735 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/crates.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/crates.rs @@ -1,9 +1,11 @@ // This file is named `crates` not `crate`, because the latter is a Rust keyword use crate::codegen::ir::hir::hierarchical::module::HirModule; +use crate::utils::crate_name::CrateName; /// Represents a crate, including a map of its modules, imports, structs and enums. #[derive(Debug, Clone, serde::Serialize)] pub struct HirCrate { + pub(crate) name: CrateName, pub(crate) root_module: HirModule, } diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs index 57ebbc58af..eefde9843f 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs @@ -4,5 +4,5 @@ use std::collections::HashMap; #[derive(Debug, Clone, serde::Serialize)] pub struct HirPack { - pub(crate) crates: HashMap, + pub(crate) crates: Vec, } diff --git a/frb_codegen/src/library/codegen/ir/hir/raw/crates.rs b/frb_codegen/src/library/codegen/ir/hir/raw/crates.rs new file mode 100644 index 0000000000..0a7c186b98 --- /dev/null +++ b/frb_codegen/src/library/codegen/ir/hir/raw/crates.rs @@ -0,0 +1,9 @@ +// This file is named `crates` not `crate`, because the latter is a Rust keyword + +use crate::utils::crate_name::CrateName; + +#[derive(Debug, Clone, serde::Serialize)] +pub struct HirRawCrate { + pub(crate) name: CrateName, + pub(crate) syn_file: syn::File, +} diff --git a/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs b/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs index 1cc70244a6..2acd7ed6eb 100644 --- a/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs +++ b/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs @@ -1,6 +1,7 @@ -use crate::utils::crate_name::CrateName; -use std::collections::HashMap; +mod crates; + +use crate::codegen::ir::hir::raw::crates::HirRawCrate; pub(crate) struct HirRawPack { - pub crates: HashMap, + pub crates: Vec, } From e89dfdca3b4141bfa3aef6c1a3afc022bfc3b7ea Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:19:04 +0800 Subject: [PATCH 51/60] feat: more --- frb_codegen/src/library/codegen/ir/hir/raw/crates.rs | 2 +- frb_codegen/src/library/codegen/parser/hir/flat/mod.rs | 2 +- .../src/library/codegen/parser/hir/hierarchical/crates.rs | 5 ++++- .../src/library/codegen/parser/hir/hierarchical/mod.rs | 6 +++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/raw/crates.rs b/frb_codegen/src/library/codegen/ir/hir/raw/crates.rs index 0a7c186b98..581ec16ada 100644 --- a/frb_codegen/src/library/codegen/ir/hir/raw/crates.rs +++ b/frb_codegen/src/library/codegen/ir/hir/raw/crates.rs @@ -2,7 +2,7 @@ use crate::utils::crate_name::CrateName; -#[derive(Debug, Clone, serde::Serialize)] +#[derive(Debug, Clone)] pub struct HirRawCrate { pub(crate) name: CrateName, pub(crate) syn_file: syn::File, diff --git a/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs b/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs index 57f91a79c8..98f0378cdf 100644 --- a/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs @@ -117,7 +117,7 @@ fn is_interest_mod(module: &HirModule) -> bool { } fn visit_pack<'a, F: FnMut(&'a HirModule)>(hir_pack: &'a HirPack, f: &mut F) { - for hir_crate in hir_pack.crates.values() { + for hir_crate in &hir_pack.crates { visit_modules(&hir_crate.root_module, f); } } diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/crates.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/crates.rs index 445023bbca..9876ffbcf3 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/crates.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/crates.rs @@ -16,5 +16,8 @@ pub(crate) fn parse_crate( namespace: crate_name.namespace(), }; let root_module = parse_module(&file.items, info, config)?; - Ok(HirCrate { root_module }) + Ok(HirCrate { + crate_name: crate_name.to_owned(), + root_module, + }) } diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs index 0a1c913936..d974bfd119 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs @@ -26,10 +26,10 @@ fn parse_raw(config: &ParserHirInternalConfig, hir_raw: &HirRawPack) -> anyhow:: let crates = hir_raw .crates .iter() - .map(|(crate_name, syn_file)| { + .map(|c| { Ok(( - crate_name.to_owned(), - parse_crate(config, syn_file, crate_name)?, + c.name.to_owned(), + parse_crate(config, c.syn_file, crate_name)?, )) }) .collect::>>()? From bcdafbc94fdd51d2a325b1cb86b897159c1f271d Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:19:32 +0800 Subject: [PATCH 52/60] feat: more --- frb_codegen/src/library/codegen/ir/hir/raw/mod.rs | 2 +- frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs b/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs index 2acd7ed6eb..5eebc545a3 100644 --- a/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs +++ b/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs @@ -1,4 +1,4 @@ -mod crates; +pub(crate) mod crates; use crate::codegen::ir::hir::raw::crates::HirRawCrate; diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs index d974bfd119..0857d90f4f 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs @@ -29,7 +29,7 @@ fn parse_raw(config: &ParserHirInternalConfig, hir_raw: &HirRawPack) -> anyhow:: .map(|c| { Ok(( c.name.to_owned(), - parse_crate(config, c.syn_file, crate_name)?, + parse_crate(config, c.syn_file, c.name)?, )) }) .collect::>>()? From a479c5fafab4c65c47c7e4eefa5c723210be7abe Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:19:44 +0800 Subject: [PATCH 53/60] refactor: mv --- frb_codegen/src/library/codegen/ir/hir/raw/mod.rs | 6 +----- frb_codegen/src/library/codegen/ir/hir/raw/pack.rs | 5 +++++ .../src/library/codegen/parser/hir/hierarchical/mod.rs | 2 +- frb_codegen/src/library/codegen/parser/hir/raw/mod.rs | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 frb_codegen/src/library/codegen/ir/hir/raw/pack.rs diff --git a/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs b/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs index 5eebc545a3..e8e6198920 100644 --- a/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs +++ b/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs @@ -1,7 +1,3 @@ pub(crate) mod crates; +pub(crate) mod pack; -use crate::codegen::ir::hir::raw::crates::HirRawCrate; - -pub(crate) struct HirRawPack { - pub crates: Vec, -} diff --git a/frb_codegen/src/library/codegen/ir/hir/raw/pack.rs b/frb_codegen/src/library/codegen/ir/hir/raw/pack.rs new file mode 100644 index 0000000000..61b608dd8d --- /dev/null +++ b/frb_codegen/src/library/codegen/ir/hir/raw/pack.rs @@ -0,0 +1,5 @@ +use crate::codegen::ir::hir::raw::crates::HirRawCrate; + +pub(crate) struct HirRawPack { + pub crates: Vec, +} diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs index 0857d90f4f..1d3d2b9347 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs @@ -1,5 +1,5 @@ use crate::codegen::ir::hir::hierarchical::pack::HirPack; -use crate::codegen::ir::hir::raw::HirRawPack; +use crate::codegen::ir::hir::raw::pack::HirRawPack; use crate::codegen::parser::hir::hierarchical::crates::parse_crate; use crate::codegen::parser::hir::internal_config::ParserHirInternalConfig; diff --git a/frb_codegen/src/library/codegen/parser/hir/raw/mod.rs b/frb_codegen/src/library/codegen/parser/hir/raw/mod.rs index b6c888ea4f..ee58d08440 100644 --- a/frb_codegen/src/library/codegen/parser/hir/raw/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/raw/mod.rs @@ -1,5 +1,5 @@ use crate::codegen::dumper::Dumper; -use crate::codegen::ir::hir::raw::HirRawPack; +use crate::codegen::ir::hir::raw::pack::HirRawPack; use crate::codegen::parser::hir::internal_config::ParserHirInternalConfig; use crate::library::commands::cargo_expand::run_cargo_expand; use crate::utils::crate_name::CrateName; From 41ec3ffcc3d74b3a4a3b1449ecfa723e864157e4 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:21:17 +0800 Subject: [PATCH 54/60] feat: more --- .../library/codegen/parser/hir/hierarchical/crates.rs | 2 +- .../src/library/codegen/parser/hir/hierarchical/mod.rs | 8 ++------ frb_codegen/src/library/codegen/parser/hir/raw/mod.rs | 9 +++++---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/crates.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/crates.rs index 9876ffbcf3..d0674e31cc 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/crates.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/crates.rs @@ -17,7 +17,7 @@ pub(crate) fn parse_crate( }; let root_module = parse_module(&file.items, info, config)?; Ok(HirCrate { - crate_name: crate_name.to_owned(), + name: crate_name.to_owned(), root_module, }) } diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs index 1d3d2b9347..917429f296 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs @@ -1,3 +1,4 @@ +use crate::codegen::ir::hir::hierarchical::crates::HirCrate; use crate::codegen::ir::hir::hierarchical::pack::HirPack; use crate::codegen::ir::hir::raw::pack::HirRawPack; use crate::codegen::parser::hir::hierarchical::crates::parse_crate; @@ -26,12 +27,7 @@ fn parse_raw(config: &ParserHirInternalConfig, hir_raw: &HirRawPack) -> anyhow:: let crates = hir_raw .crates .iter() - .map(|c| { - Ok(( - c.name.to_owned(), - parse_crate(config, c.syn_file, c.name)?, - )) - }) + .map(|c| parse_crate(config, &c.syn_file, &c.name)) .collect::>>()? .into_iter() .collect(); diff --git a/frb_codegen/src/library/codegen/parser/hir/raw/mod.rs b/frb_codegen/src/library/codegen/parser/hir/raw/mod.rs index ee58d08440..f2afe1bc68 100644 --- a/frb_codegen/src/library/codegen/parser/hir/raw/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/raw/mod.rs @@ -1,4 +1,5 @@ use crate::codegen::dumper::Dumper; +use crate::codegen::ir::hir::raw::crates::HirRawCrate; use crate::codegen::ir::hir::raw::pack::HirRawPack; use crate::codegen::parser::hir::internal_config::ParserHirInternalConfig; use crate::library::commands::cargo_expand::run_cargo_expand; @@ -15,14 +16,14 @@ pub(crate) fn parse( ]) .iter() .map(|crate_name| { - Ok(( - crate_name.to_owned(), - run_cargo_expand( + Ok(HirRawCrate { + name: crate_name.to_owned(), + syn_file: run_cargo_expand( &config.rust_crate_dir, (*crate_name != CrateName::self_crate()).then_some(crate_name), dumper, )?, - )) + }) }) .collect::>>()? .into_iter() From 1974e658b6fa307121f62cbc2a116912606ee6e5 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:23:05 +0800 Subject: [PATCH 55/60] feat: more --- frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs index eefde9843f..49260a998f 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs @@ -6,3 +6,9 @@ use std::collections::HashMap; pub struct HirPack { pub(crate) crates: Vec, } + +impl HirPack { + pub(crate) fn get_mut_crate(&mut self, name: CrateName) -> Option<&mut HirCrate> { + (self.crates.iter_mut()).find(|x| x.name.namespace() == name.namespace()) + } +} From 27fb5a35b1da12e4071995ad921e1d7bf1dabe79 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:23:18 +0800 Subject: [PATCH 56/60] fix: err --- frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs | 2 +- .../hir/hierarchical/third_party_override_transformer.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs index 49260a998f..2c71306205 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs @@ -8,7 +8,7 @@ pub struct HirPack { } impl HirPack { - pub(crate) fn get_mut_crate(&mut self, name: CrateName) -> Option<&mut HirCrate> { + pub(crate) fn get_mut_crate(&mut self, name: &CrateName) -> Option<&mut HirCrate> { (self.crates.iter_mut()).find(|x| x.name.namespace() == name.namespace()) } } diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 5f340095c1..65aeec5608 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -18,7 +18,7 @@ pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { } fn remove_module_third_party_root(pack: &mut HirPack) -> Option { - let hir_crate = pack.crates.get_mut(&CrateName::self_crate()).unwrap(); + let hir_crate = pack.get_mut_crate(&CrateName::self_crate()).unwrap(); hir_crate .root_module .content @@ -27,7 +27,7 @@ fn remove_module_third_party_root(pack: &mut HirPack) -> Option { fn transform_crate(pack: &mut HirPack, src: HirModule) -> anyhow::Result<()> { let crate_name = CrateName::new((src.meta.namespace.path().last()).unwrap().to_string()); - if let Some(target_crate) = pack.crates.get_mut(&crate_name) { + if let Some(target_crate) = pack.get_mut_crate(&crate_name) { transform_module(&mut target_crate.root_module, src)?; } else { log::warn!( From 51166310598f14eb50794d2dfba4212875fcfe6b Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:23:54 +0800 Subject: [PATCH 57/60] chore: lint --- frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs | 1 - frb_codegen/src/library/codegen/ir/hir/raw/mod.rs | 1 - frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs index 2c71306205..ffaef5bcfa 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/pack.rs @@ -1,6 +1,5 @@ use crate::codegen::ir::hir::hierarchical::crates::HirCrate; use crate::utils::crate_name::CrateName; -use std::collections::HashMap; #[derive(Debug, Clone, serde::Serialize)] pub struct HirPack { diff --git a/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs b/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs index e8e6198920..36e6ed9511 100644 --- a/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs +++ b/frb_codegen/src/library/codegen/ir/hir/raw/mod.rs @@ -1,3 +1,2 @@ pub(crate) mod crates; pub(crate) mod pack; - diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs index 917429f296..86dcfd4310 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/mod.rs @@ -1,4 +1,3 @@ -use crate::codegen::ir::hir::hierarchical::crates::HirCrate; use crate::codegen::ir::hir::hierarchical::pack::HirPack; use crate::codegen::ir::hir::raw::pack::HirRawPack; use crate::codegen::parser::hir::hierarchical::crates::parse_crate; From 1e2fd5c5df4355360dd2bd51c3ef243c4a97f518 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:26:10 +0800 Subject: [PATCH 58/60] fix: lint --- .../parser/hir/hierarchical/third_party_override_transformer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 65aeec5608..4786c8c1fd 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -79,7 +79,7 @@ fn transform_module_content_struct_or_enums( } fn transform_module_content_general_vec( - target_items: &mut Vec, + target_items: &mut [T], src_items: Vec, key: impl Fn(&T) -> String, write: impl Fn(&mut T, T), From 069a7c28fb19bb0db63f72f695422480cff2ec5d Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:35:41 +0800 Subject: [PATCH 59/60] fix: lint --- .../hir/hierarchical/third_party_override_transformer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs index 4786c8c1fd..048d4df7be 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/third_party_override_transformer.rs @@ -48,7 +48,7 @@ fn transform_module(target: &mut HirModule, src: HirModule) -> anyhow::Result<() } fn transform_module_content_functions( - target: &mut Vec, + target: &mut [HirFunction], src_content_functions: Vec, ) -> anyhow::Result<()> { transform_module_content_general_vec( @@ -65,7 +65,7 @@ fn transform_module_content_functions( } fn transform_module_content_struct_or_enums( - target: &mut Vec>, + target: &mut [HirStructOrEnum], src_content_struct_or_enums: Vec>, ) -> anyhow::Result<()> { transform_module_content_general_vec( From 9cc246cf278c8a8a8fb8e8c0ef5596e97f582444 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 19:30:01 +0800 Subject: [PATCH 60/60] chore: goldens --- .../parser/mod/generics/expect_hir_hierarchical.json | 7 ++++--- .../parser/mod/methods/expect_hir_hierarchical.json | 7 ++++--- .../mod/multi_input_file/expect_hir_hierarchical.json | 7 ++++--- .../mod/non_qualified_names/expect_hir_hierarchical.json | 7 ++++--- .../mod/qualified_names/expect_hir_hierarchical.json | 7 ++++--- .../codegen/parser/mod/simple/expect_hir_hierarchical.json | 7 ++++--- .../mod/unused_struct_enum/expect_hir_hierarchical.json | 7 ++++--- .../use_type_in_another_file/expect_hir_hierarchical.json | 7 ++++--- 8 files changed, 32 insertions(+), 24 deletions(-) diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_hir_hierarchical.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_hir_hierarchical.json index 7e7822f03b..a5d402982b 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_hir_hierarchical.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_hir_hierarchical.json @@ -1,6 +1,7 @@ { - "crates": { - "crate": { + "crates": [ + { + "name": "crate", "root_module": { "content": { "enums": [], @@ -61,5 +62,5 @@ } } } - } + ] } \ No newline at end of file diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_hir_hierarchical.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_hir_hierarchical.json index fe7503f826..006e0db568 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_hir_hierarchical.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_hir_hierarchical.json @@ -1,6 +1,7 @@ { - "crates": { - "crate": { + "crates": [ + { + "name": "crate", "root_module": { "content": { "enums": [], @@ -58,5 +59,5 @@ } } } - } + ] } \ No newline at end of file diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/multi_input_file/expect_hir_hierarchical.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/multi_input_file/expect_hir_hierarchical.json index c70837a626..ee6b24d6e7 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/multi_input_file/expect_hir_hierarchical.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/multi_input_file/expect_hir_hierarchical.json @@ -1,6 +1,7 @@ { - "crates": { - "crate": { + "crates": [ + { + "name": "crate", "root_module": { "content": { "enums": [], @@ -53,5 +54,5 @@ } } } - } + ] } \ No newline at end of file diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/non_qualified_names/expect_hir_hierarchical.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/non_qualified_names/expect_hir_hierarchical.json index eb1b55bc59..0a3f39f1c1 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/non_qualified_names/expect_hir_hierarchical.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/non_qualified_names/expect_hir_hierarchical.json @@ -1,6 +1,7 @@ { - "crates": { - "crate": { + "crates": [ + { + "name": "crate", "root_module": { "content": { "enums": [], @@ -38,5 +39,5 @@ } } } - } + ] } \ No newline at end of file diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/qualified_names/expect_hir_hierarchical.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/qualified_names/expect_hir_hierarchical.json index 15aceea38d..64f4c80673 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/qualified_names/expect_hir_hierarchical.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/qualified_names/expect_hir_hierarchical.json @@ -1,6 +1,7 @@ { - "crates": { - "crate": { + "crates": [ + { + "name": "crate", "root_module": { "content": { "enums": [], @@ -44,5 +45,5 @@ } } } - } + ] } \ No newline at end of file diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/simple/expect_hir_hierarchical.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/simple/expect_hir_hierarchical.json index 24911b6be9..738156294f 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/simple/expect_hir_hierarchical.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/simple/expect_hir_hierarchical.json @@ -1,6 +1,7 @@ { - "crates": { - "crate": { + "crates": [ + { + "name": "crate", "root_module": { "content": { "enums": [], @@ -35,5 +36,5 @@ } } } - } + ] } \ No newline at end of file diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/unused_struct_enum/expect_hir_hierarchical.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/unused_struct_enum/expect_hir_hierarchical.json index 58e2fb2c8d..7bec7f834d 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/unused_struct_enum/expect_hir_hierarchical.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/unused_struct_enum/expect_hir_hierarchical.json @@ -1,6 +1,7 @@ { - "crates": { - "crate": { + "crates": [ + { + "name": "crate", "root_module": { "content": { "enums": [], @@ -45,5 +46,5 @@ } } } - } + ] } \ No newline at end of file diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_hir_hierarchical.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_hir_hierarchical.json index d8eb2381f9..0977d1b094 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_hir_hierarchical.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_hir_hierarchical.json @@ -1,6 +1,7 @@ { - "crates": { - "crate": { + "crates": [ + { + "name": "crate", "root_module": { "content": { "enums": [], @@ -63,5 +64,5 @@ } } } - } + ] } \ No newline at end of file