From 9becc74d9e04cc3dd1df201430f92a967065f156 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 09:59:16 +0800 Subject: [PATCH 01/34] chore: more --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 8e70b1ea69..b5e9aa02b6 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -30,6 +30,11 @@ fn parse_pub_use_from_item(item: &syn::Item) -> Option { None } +struct PubUseInfo { + namespace: Namespace, + name_filters: Option>, +} + fn transform_module_by_pub_use_single( module: &mut HirModule, pub_use_name: &Namespace, From 8ea13c302411e07062e82f4e5e5ab7d72578e5a7 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 09:59:19 +0800 Subject: [PATCH 02/34] Revert "chore: more" This reverts commit 9becc74d9e04cc3dd1df201430f92a967065f156. --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index b5e9aa02b6..8e70b1ea69 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -30,11 +30,6 @@ fn parse_pub_use_from_item(item: &syn::Item) -> Option { None } -struct PubUseInfo { - namespace: Namespace, - name_filters: Option>, -} - fn transform_module_by_pub_use_single( module: &mut HirModule, pub_use_name: &Namespace, From 75e2942f0f17d19c73e65e28f9ff7a7acc806350 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:00:09 +0800 Subject: [PATCH 03/34] feat: trait --- .../src/library/codegen/ir/hir/hierarchical/traits.rs | 9 +++++++++ .../hir/hierarchical/module/pub_use_transformer.rs | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs index 451ce6e98c..dc548b4ba4 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs @@ -15,3 +15,12 @@ pub(crate) struct HirTraitImpl { #[serde(skip_serializing)] pub(crate) item_impl: ItemImpl, } + +impl HirTrait { + pub(crate) fn with_namespace(&self, namespace: Namespace) -> Self { + Self { + namespace, + ..self.to_owned() + } + } +} diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 8e70b1ea69..3d9852c9b1 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -46,10 +46,14 @@ fn transform_module_by_pub_use_single( let src_enums = (src_mod.content.enums.iter()) .map(|x| x.with_namespace(self_namespace.clone())) .collect_vec(); + let src_traits = (src_mod.content.traits.iter()) + .map(|x| x.with_namespace(self_namespace.clone())) + .collect_vec(); module.content.functions.extend(src_functions); module.content.structs.extend(src_structs); module.content.enums.extend(src_enums); + module.content.traits.extend(src_traits); } else { log::debug!( "transform_module_by_pub_use_single skip `{pub_use_name}` since cannot find mod" From 968fea30bead374b44394828fdc6540ff46c2032 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:05:53 +0800 Subject: [PATCH 04/34] feat: more --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 3d9852c9b1..d4aeb52951 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -3,6 +3,11 @@ use crate::utils::namespace::Namespace; use itertools::Itertools; pub(crate) fn transform(mut module: HirModule, items: &[syn::Item]) -> anyhow::Result { + // Only apply to third party crate currently, since in self crate usually no need to care about this + if module.meta.namespace.crate_name().is_self_crate() { + return Ok(module); + } + let pub_use_names = parse_pub_use_from_items(items); for pub_use_name in pub_use_names { transform_module_by_pub_use_single(&mut module, &pub_use_name)?; From 121667122556b136a7b196acdaffa3475e25fe9f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:07:14 +0800 Subject: [PATCH 05/34] feat: more --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index d4aeb52951..44b7d51690 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -40,6 +40,11 @@ fn transform_module_by_pub_use_single( pub_use_name: &Namespace, ) -> anyhow::Result<()> { if let Some(src_mod) = module.content.get_module_nested(&pub_use_name.path()) { + if src_mod.meta.is_public() { + log::debug!("transform_module_by_pub_use_single skip `{pub_use_name}` since src mod already public"); + return Ok(()); + } + let self_namespace = &module.meta.namespace; let src_functions = (src_mod.content.functions.iter()) From a20d4f2b7b6a930987938861ee34e9636080ae6c Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:07:38 +0800 Subject: [PATCH 06/34] Revert "Revert "chore: more"" This reverts commit 8ea13c302411e07062e82f4e5e5ab7d72578e5a7. --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 44b7d51690..ce49aaf434 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -35,6 +35,11 @@ fn parse_pub_use_from_item(item: &syn::Item) -> Option { None } +struct PubUseInfo { + namespace: Namespace, + name_filters: Option>, +} + fn transform_module_by_pub_use_single( module: &mut HirModule, pub_use_name: &Namespace, From 9e0e0db9e66b59604c807a3dae192dfeecdb8286 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:08:21 +0800 Subject: [PATCH 07/34] feat: usage --- .../module/pub_use_transformer.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index ce49aaf434..132c8120de 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -8,21 +8,21 @@ pub(crate) fn transform(mut module: HirModule, items: &[syn::Item]) -> anyhow::R return Ok(module); } - let pub_use_names = parse_pub_use_from_items(items); - for pub_use_name in pub_use_names { - transform_module_by_pub_use_single(&mut module, &pub_use_name)?; + let pub_use_infos = parse_pub_use_from_items(items); + for pub_use_info in pub_use_infos { + transform_module_by_pub_use_single(&mut module, &pub_use_info)?; } Ok(module) } -fn parse_pub_use_from_items(items: &[syn::Item]) -> Vec { +fn parse_pub_use_from_items(items: &[syn::Item]) -> Vec { items .iter() .filter_map(parse_pub_use_from_item) .collect_vec() } -fn parse_pub_use_from_item(item: &syn::Item) -> Option { +fn parse_pub_use_from_item(item: &syn::Item) -> Option { if let syn::Item::Use(item_use) = item { if matches!(item_use.vis, syn::Visibility::Public(_)) { let tree = &item_use.tree; @@ -35,6 +35,7 @@ fn parse_pub_use_from_item(item: &syn::Item) -> Option { None } +#[derive(Debug, Clone)] struct PubUseInfo { namespace: Namespace, name_filters: Option>, @@ -42,11 +43,11 @@ struct PubUseInfo { fn transform_module_by_pub_use_single( module: &mut HirModule, - pub_use_name: &Namespace, + pub_use_info: &PubUseInfo, ) -> anyhow::Result<()> { - if let Some(src_mod) = module.content.get_module_nested(&pub_use_name.path()) { + if let Some(src_mod) = module.content.get_module_nested(&pub_use_info.path()) { if src_mod.meta.is_public() { - log::debug!("transform_module_by_pub_use_single skip `{pub_use_name}` since src mod already public"); + log::debug!("transform_module_by_pub_use_single skip `{pub_use_info}` since src mod already public"); return Ok(()); } @@ -71,7 +72,7 @@ fn transform_module_by_pub_use_single( module.content.traits.extend(src_traits); } else { log::debug!( - "transform_module_by_pub_use_single skip `{pub_use_name}` since cannot find mod" + "transform_module_by_pub_use_single skip `{pub_use_info}` since cannot find mod" ); } From f8de2cb7c56345a5de6a0e40d85ca9b3445ece99 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:08:49 +0800 Subject: [PATCH 08/34] feat: more --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 132c8120de..e40b171ba2 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -45,7 +45,7 @@ fn transform_module_by_pub_use_single( module: &mut HirModule, pub_use_info: &PubUseInfo, ) -> anyhow::Result<()> { - if let Some(src_mod) = module.content.get_module_nested(&pub_use_info.path()) { + if let Some(src_mod) = (module.content).get_module_nested(&pub_use_info.namespace.path()) { if src_mod.meta.is_public() { log::debug!("transform_module_by_pub_use_single skip `{pub_use_info}` since src mod already public"); return Ok(()); From bb08b3ad0683b5fc7ea19128082a9ed20d4fe022 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:09:16 +0800 Subject: [PATCH 09/34] chore: empty --- frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs | 5 +++++ frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs | 1 + 2 files changed, 6 insertions(+) create mode 100644 frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs new file mode 100644 index 0000000000..3255822954 --- /dev/null +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs @@ -0,0 +1,5 @@ +use crate::utils::namespace::Namespace; + +pub(crate) trait WithNamespace { + fn with_namespace(&self, namespace: Namespace) -> Self; +} 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 a596df54ad..c1d7c113f9 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs @@ -6,3 +6,4 @@ pub(crate) mod struct_or_enum; pub(crate) mod syn_item_struct_or_enum; pub(crate) mod traits; pub(crate) mod type_alias; +pub(crate) mod misc; From 9daf478609b51745bc6ada99f6aa811b02e4573a Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:09:51 +0800 Subject: [PATCH 10/34] feat: triat --- .../src/library/codegen/ir/hir/hierarchical/function.rs | 7 +++++-- .../library/codegen/ir/hir/hierarchical/struct_or_enum.rs | 5 +++-- .../src/library/codegen/ir/hir/hierarchical/traits.rs | 5 +++-- 3 files changed, 11 insertions(+), 6 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 bb21ef4c76..f1c9f795e9 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -1,3 +1,4 @@ +use crate::codegen::ir::hir::hierarchical::misc::WithNamespace; use crate::utils::namespace::{Namespace, NamespacedName}; use proc_macro2::Span; use serde::Serialize; @@ -13,14 +14,16 @@ pub(crate) struct HirFunction { pub(crate) item_fn: GeneralizedItemFn, } -impl HirFunction { - pub(crate) fn with_namespace(&self, namespace: Namespace) -> Self { +impl WithNamespace for HirFunction { + fn with_namespace(&self, namespace: Namespace) -> Self { Self { namespace, ..self.clone() } } +} +impl HirFunction { pub(crate) fn owner_and_name(&self) -> SimpleOwnerAndName { (self.owner.simple_name(), self.item_fn.name()) } 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 f677f9d0a9..f6a341d3d4 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,3 +1,4 @@ +use crate::codegen::ir::hir::hierarchical::misc::WithNamespace; 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}; @@ -27,8 +28,8 @@ pub struct HirStructOrEnum { pub type HirStruct = HirStructOrEnum; pub type HirEnum = HirStructOrEnum; -impl HirStructOrEnum { - pub(crate) fn with_namespace(&self, namespace: Namespace) -> Self { +impl WithNamespace for HirStructOrEnum { + 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/ir/hir/hierarchical/traits.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs index dc548b4ba4..5490502f8c 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs @@ -1,3 +1,4 @@ +use crate::codegen::ir::hir::hierarchical::misc::WithNamespace; use crate::utils::namespace::Namespace; use serde::Serialize; use syn::{ItemImpl, ItemTrait}; @@ -16,8 +17,8 @@ pub(crate) struct HirTraitImpl { pub(crate) item_impl: ItemImpl, } -impl HirTrait { - pub(crate) fn with_namespace(&self, namespace: Namespace) -> Self { +impl WithNamespace for HirTrait { + fn with_namespace(&self, namespace: Namespace) -> Self { Self { namespace, ..self.to_owned() From daf2f6726d1f79f47ba7409b98aae6db885b3a85 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:11:01 +0800 Subject: [PATCH 11/34] feat: more --- .../module/pub_use_transformer.rs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index e40b171ba2..662948a016 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -1,3 +1,4 @@ +use crate::codegen::ir::hir::hierarchical::misc::WithNamespace; use crate::codegen::ir::hir::hierarchical::module::HirModule; use crate::utils::namespace::Namespace; use itertools::Itertools; @@ -53,18 +54,10 @@ fn transform_module_by_pub_use_single( let self_namespace = &module.meta.namespace; - let src_functions = (src_mod.content.functions.iter()) - .map(|x| x.with_namespace(self_namespace.clone())) - .collect_vec(); - let src_structs = (src_mod.content.structs.iter()) - .map(|x| x.with_namespace(self_namespace.clone())) - .collect_vec(); - let src_enums = (src_mod.content.enums.iter()) - .map(|x| x.with_namespace(self_namespace.clone())) - .collect_vec(); - let src_traits = (src_mod.content.traits.iter()) - .map(|x| x.with_namespace(self_namespace.clone())) - .collect_vec(); + let src_functions = transform_items(src_mod.content.functions, self_namespace); + let src_structs = transform_items(src_mod.content.structs, self_namespace); + let src_enums = transform_items(src_mod.content.enums, self_namespace); + let src_traits = transform_items(src_mod.content.traits, self_namespace); module.content.functions.extend(src_functions); module.content.structs.extend(src_structs); @@ -78,3 +71,9 @@ fn transform_module_by_pub_use_single( Ok(()) } + +fn transform_items(items: &[T], self_namespace: &Namespace) -> Vec { + (items.iter()) + .map(|x| x.with_namespace(self_namespace.clone())) + .collect_vec() +} From e706589cffefbef41786889b19bb62c54de8c722 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:11:26 +0800 Subject: [PATCH 12/34] fix: err --- .../hir/hierarchical/module/pub_use_transformer.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 662948a016..2bd6ee3ba3 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -48,16 +48,16 @@ fn transform_module_by_pub_use_single( ) -> anyhow::Result<()> { if let Some(src_mod) = (module.content).get_module_nested(&pub_use_info.namespace.path()) { if src_mod.meta.is_public() { - log::debug!("transform_module_by_pub_use_single skip `{pub_use_info}` since src mod already public"); + log::debug!("transform_module_by_pub_use_single skip `{pub_use_info:?}` since src mod already public"); return Ok(()); } let self_namespace = &module.meta.namespace; - let src_functions = transform_items(src_mod.content.functions, self_namespace); - let src_structs = transform_items(src_mod.content.structs, self_namespace); - let src_enums = transform_items(src_mod.content.enums, self_namespace); - let src_traits = transform_items(src_mod.content.traits, self_namespace); + let src_functions = transform_items(&src_mod.content.functions, self_namespace); + let src_structs = transform_items(&src_mod.content.structs, self_namespace); + let src_enums = transform_items(&src_mod.content.enums, self_namespace); + let src_traits = transform_items(&src_mod.content.traits, self_namespace); module.content.functions.extend(src_functions); module.content.structs.extend(src_structs); @@ -65,7 +65,7 @@ fn transform_module_by_pub_use_single( module.content.traits.extend(src_traits); } else { log::debug!( - "transform_module_by_pub_use_single skip `{pub_use_info}` since cannot find mod" + "transform_module_by_pub_use_single skip `{pub_use_info:?}` since cannot find mod" ); } From 47e23e60ca7e028b570f9bba84133cb07ed830c1 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:13:51 +0800 Subject: [PATCH 13/34] feat: more --- .../module/pub_use_transformer.rs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 2bd6ee3ba3..950aedb204 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -42,6 +42,16 @@ struct PubUseInfo { name_filters: Option>, } +impl PubUseInfo { + fn is_interest_name(&self, name: &str) -> bool { + if let Some(name_filters) = &self.name_filters { + name_filters.contains(name) + } else { + true + } + } +} + fn transform_module_by_pub_use_single( module: &mut HirModule, pub_use_info: &PubUseInfo, @@ -54,10 +64,11 @@ fn transform_module_by_pub_use_single( let self_namespace = &module.meta.namespace; - let src_functions = transform_items(&src_mod.content.functions, self_namespace); - let src_structs = transform_items(&src_mod.content.structs, self_namespace); - let src_enums = transform_items(&src_mod.content.enums, self_namespace); - let src_traits = transform_items(&src_mod.content.traits, self_namespace); + let src_functions = + transform_items(&src_mod.content.functions, self_namespace, pub_use_info); + let src_structs = transform_items(&src_mod.content.structs, self_namespace, pub_use_info); + let src_enums = transform_items(&src_mod.content.enums, self_namespace, pub_use_info); + let src_traits = transform_items(&src_mod.content.traits, self_namespace, pub_use_info); module.content.functions.extend(src_functions); module.content.structs.extend(src_structs); @@ -72,8 +83,13 @@ fn transform_module_by_pub_use_single( Ok(()) } -fn transform_items(items: &[T], self_namespace: &Namespace) -> Vec { +fn transform_items( + items: &[T], + self_namespace: &Namespace, + pub_use_info: &PubUseInfo, +) -> Vec { (items.iter()) + .filter(|x| pub_use_info.is_interest_name(TODO)) .map(|x| x.with_namespace(self_namespace.clone())) .collect_vec() } From ac31edb562e7c933d93170fc5e2cc026b595d768 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:14:21 +0800 Subject: [PATCH 14/34] chore: rename --- .../src/library/codegen/ir/hir/hierarchical/function.rs | 4 ++-- frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs | 2 +- .../src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs | 4 ++-- frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs | 4 ++-- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 4 ++-- 5 files changed, 9 insertions(+), 9 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 f1c9f795e9..be23c52e93 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -1,4 +1,4 @@ -use crate::codegen::ir::hir::hierarchical::misc::WithNamespace; +use crate::codegen::ir::hir::hierarchical::misc::HirCommon; use crate::utils::namespace::{Namespace, NamespacedName}; use proc_macro2::Span; use serde::Serialize; @@ -14,7 +14,7 @@ pub(crate) struct HirFunction { pub(crate) item_fn: GeneralizedItemFn, } -impl WithNamespace for HirFunction { +impl HirCommon for HirFunction { fn with_namespace(&self, namespace: Namespace) -> Self { Self { namespace, diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs index 3255822954..8bafead19c 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs @@ -1,5 +1,5 @@ use crate::utils::namespace::Namespace; -pub(crate) trait WithNamespace { +pub(crate) trait HirCommon { fn with_namespace(&self, namespace: Namespace) -> Self; } 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 f6a341d3d4..73bf0807c8 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,4 +1,4 @@ -use crate::codegen::ir::hir::hierarchical::misc::WithNamespace; +use crate::codegen::ir::hir::hierarchical::misc::HirCommon; 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}; @@ -28,7 +28,7 @@ pub struct HirStructOrEnum { pub type HirStruct = HirStructOrEnum; pub type HirEnum = HirStructOrEnum; -impl WithNamespace for HirStructOrEnum { +impl HirCommon for HirStructOrEnum { 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/traits.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs index 5490502f8c..cc48d34f71 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs @@ -1,4 +1,4 @@ -use crate::codegen::ir::hir::hierarchical::misc::WithNamespace; +use crate::codegen::ir::hir::hierarchical::misc::HirCommon; use crate::utils::namespace::Namespace; use serde::Serialize; use syn::{ItemImpl, ItemTrait}; @@ -17,7 +17,7 @@ pub(crate) struct HirTraitImpl { pub(crate) item_impl: ItemImpl, } -impl WithNamespace for HirTrait { +impl HirCommon for HirTrait { fn with_namespace(&self, namespace: Namespace) -> Self { Self { namespace, diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 950aedb204..367d549a5a 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -1,4 +1,4 @@ -use crate::codegen::ir::hir::hierarchical::misc::WithNamespace; +use crate::codegen::ir::hir::hierarchical::misc::HirCommon; use crate::codegen::ir::hir::hierarchical::module::HirModule; use crate::utils::namespace::Namespace; use itertools::Itertools; @@ -83,7 +83,7 @@ fn transform_module_by_pub_use_single( Ok(()) } -fn transform_items( +fn transform_items( items: &[T], self_namespace: &Namespace, pub_use_info: &PubUseInfo, From 0a8f602102302337d7ac30075dfa239625deb452 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:15:19 +0800 Subject: [PATCH 15/34] feat: more --- .../src/library/codegen/ir/hir/hierarchical/function.rs | 4 ++++ frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs | 2 ++ .../src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs | 4 ++++ frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs | 4 ++++ .../parser/hir/hierarchical/module/pub_use_transformer.rs | 2 +- 5 files changed, 15 insertions(+), 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 be23c52e93..a46d8f39de 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -21,6 +21,10 @@ impl HirCommon for HirFunction { ..self.clone() } } + + fn name(&self) -> String { + self.item_fn.name() + } } impl HirFunction { diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs index 8bafead19c..cdd6386f7e 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs @@ -2,4 +2,6 @@ use crate::utils::namespace::Namespace; pub(crate) trait HirCommon { fn with_namespace(&self, namespace: Namespace) -> Self; + + fn name(&self) -> String; } 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 73bf0807c8..94acdf2dbf 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 @@ -35,6 +35,10 @@ impl HirCommon for HirStructOrEnum { ..self.to_owned() } } + + fn name(&self) -> String { + self.ident.to_string() + } } pub(super) fn serialize_syn( diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs index cc48d34f71..f7d7db1532 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs @@ -24,4 +24,8 @@ impl HirCommon for HirTrait { ..self.to_owned() } } + + fn name(&self) -> String { + self.item_trait.ident.to_string() + } } diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 367d549a5a..a769416e36 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -89,7 +89,7 @@ fn transform_items( pub_use_info: &PubUseInfo, ) -> Vec { (items.iter()) - .filter(|x| pub_use_info.is_interest_name(TODO)) + .filter(|x| pub_use_info.is_interest_name(x.name())) .map(|x| x.with_namespace(self_namespace.clone())) .collect_vec() } From ac30f7dbced9d5e97b0ed6f7f86ba2da4af0b8ce Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:15:35 +0800 Subject: [PATCH 16/34] refactor: rename --- frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs | 2 +- frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs | 2 +- .../src/library/codegen/ir/hir/hierarchical/struct_or_enum.rs | 2 +- frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs | 2 +- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 2 +- 5 files changed, 5 insertions(+), 5 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 a46d8f39de..5eb0f3d5ca 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -22,7 +22,7 @@ impl HirCommon for HirFunction { } } - fn name(&self) -> String { + fn ident(&self) -> String { self.item_fn.name() } } diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs index cdd6386f7e..498e2c6779 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs @@ -3,5 +3,5 @@ use crate::utils::namespace::Namespace; pub(crate) trait HirCommon { fn with_namespace(&self, namespace: Namespace) -> Self; - fn name(&self) -> String; + fn ident(&self) -> String; } 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 94acdf2dbf..f80fa1a94e 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 @@ -36,7 +36,7 @@ impl HirCommon for HirStructOrEnum { } } - fn name(&self) -> String { + fn ident(&self) -> String { self.ident.to_string() } } diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs index f7d7db1532..7ea0f78b3e 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs @@ -25,7 +25,7 @@ impl HirCommon for HirTrait { } } - fn name(&self) -> String { + fn ident(&self) -> String { self.item_trait.ident.to_string() } } diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index a769416e36..4cce7ed62a 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -89,7 +89,7 @@ fn transform_items( pub_use_info: &PubUseInfo, ) -> Vec { (items.iter()) - .filter(|x| pub_use_info.is_interest_name(x.name())) + .filter(|x| pub_use_info.is_interest_name(x.ident())) .map(|x| x.with_namespace(self_namespace.clone())) .collect_vec() } From ba2d4766f63a9bc0f29c72af3cd97c39e91be003 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:16:24 +0800 Subject: [PATCH 17/34] feat: more --- .../src/library/codegen/ir/hir/hierarchical/function.rs | 6 +++--- frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs | 3 ++- .../library/codegen/ir/hir/hierarchical/struct_or_enum.rs | 4 ++-- .../src/library/codegen/ir/hir/hierarchical/traits.rs | 5 +++-- 4 files changed, 10 insertions(+), 8 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 5eb0f3d5ca..1f03133148 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -1,6 +1,6 @@ use crate::codegen::ir::hir::hierarchical::misc::HirCommon; use crate::utils::namespace::{Namespace, NamespacedName}; -use proc_macro2::Span; +use proc_macro2::{Ident, Span}; use serde::Serialize; use syn::spanned::Spanned; use syn::{Attribute, ImplItemFn, ItemFn, ItemImpl, Signature, TraitItemFn, Visibility}; @@ -22,8 +22,8 @@ impl HirCommon for HirFunction { } } - fn ident(&self) -> String { - self.item_fn.name() + fn ident(&self) -> Ident { + self.item_fn.sig().ident.clone() } } diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs index 498e2c6779..cfb7b88da1 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/misc.rs @@ -1,7 +1,8 @@ use crate::utils::namespace::Namespace; +use proc_macro2::Ident; pub(crate) trait HirCommon { fn with_namespace(&self, namespace: Namespace) -> Self; - fn ident(&self) -> String; + fn ident(&self) -> Ident; } 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 f80fa1a94e..3c56d3a314 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 @@ -36,8 +36,8 @@ impl HirCommon for HirStructOrEnum { } } - fn ident(&self) -> String { - self.ident.to_string() + fn ident(&self) -> Ident { + self.ident.clone() } } diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs index 7ea0f78b3e..dc33463b26 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs @@ -1,3 +1,4 @@ +use proc_macro2::Ident; use crate::codegen::ir::hir::hierarchical::misc::HirCommon; use crate::utils::namespace::Namespace; use serde::Serialize; @@ -25,7 +26,7 @@ impl HirCommon for HirTrait { } } - fn ident(&self) -> String { - self.item_trait.ident.to_string() + fn ident(&self) -> Ident { + self.item_trait.ident.clone() } } From 87f8ac639d03d09775b0494d649a330488664c86 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:16:31 +0800 Subject: [PATCH 18/34] fix: err --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 4cce7ed62a..f973914905 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -89,7 +89,7 @@ fn transform_items( pub_use_info: &PubUseInfo, ) -> Vec { (items.iter()) - .filter(|x| pub_use_info.is_interest_name(x.ident())) + .filter(|x| pub_use_info.is_interest_name(x.ident().to_string())) .map(|x| x.with_namespace(self_namespace.clone())) .collect_vec() } From 1ba878b588438d3b134d56d27580b8df4bd7c152 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:17:57 +0800 Subject: [PATCH 19/34] fix: err --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index f973914905..4b4f882e2b 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -45,7 +45,7 @@ struct PubUseInfo { impl PubUseInfo { fn is_interest_name(&self, name: &str) -> bool { if let Some(name_filters) = &self.name_filters { - name_filters.contains(name) + name_filters.contains(&name.to_owned()) } else { true } @@ -89,7 +89,7 @@ fn transform_items( pub_use_info: &PubUseInfo, ) -> Vec { (items.iter()) - .filter(|x| pub_use_info.is_interest_name(x.ident().to_string())) + .filter(|x| pub_use_info.is_interest_name(&x.ident().to_string())) .map(|x| x.with_namespace(self_namespace.clone())) .collect_vec() } From 58e426ec358dbc8eac55f9ead17477af953b5da1 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:18:24 +0800 Subject: [PATCH 20/34] feat: more --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 4b4f882e2b..84b326543e 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -29,7 +29,10 @@ fn parse_pub_use_from_item(item: &syn::Item) -> Option { let tree = &item_use.tree; let tree_string = quote::quote!(#tree).to_string().replace(' ', ""); if let Some(interest_use_part) = tree_string.strip_suffix("::*") { - return Some(Namespace::new_raw(interest_use_part.to_owned())); + return Some(PubUseInfo { + namespace: Namespace::new_raw(interest_use_part.to_owned()), + name_filters: TODO, + }); } } } From 9d6035a0260f8bf2080fe2191935118f900c6938 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:20:32 +0800 Subject: [PATCH 21/34] feat: more --- .../hierarchical/module/pub_use_transformer.rs | 17 +++++++++++------ frb_codegen/src/library/utils/namespace.rs | 10 +++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 84b326543e..86c9e48295 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -2,6 +2,7 @@ use crate::codegen::ir::hir::hierarchical::misc::HirCommon; use crate::codegen::ir::hir::hierarchical::module::HirModule; use crate::utils::namespace::Namespace; use itertools::Itertools; +use quote::ToTokens; pub(crate) fn transform(mut module: HirModule, items: &[syn::Item]) -> anyhow::Result { // Only apply to third party crate currently, since in self crate usually no need to care about this @@ -28,12 +29,16 @@ fn parse_pub_use_from_item(item: &syn::Item) -> Option { if matches!(item_use.vis, syn::Visibility::Public(_)) { let tree = &item_use.tree; let tree_string = quote::quote!(#tree).to_string().replace(' ', ""); - if let Some(interest_use_part) = tree_string.strip_suffix("::*") { - return Some(PubUseInfo { - namespace: Namespace::new_raw(interest_use_part.to_owned()), - name_filters: TODO, - }); - } + let tree_parts = tree_string.split(Namespace::SEP).collect_vec(); + let name_filters = match tree_parts.last() { + "*" => None, + x => Some(x.to_string()), + }; + + return Some(PubUseInfo { + namespace: Namespace::new_raw(tree_parts[..tree_parts.len() - 1]), + name_filters, + }); } } None diff --git a/frb_codegen/src/library/utils/namespace.rs b/frb_codegen/src/library/utils/namespace.rs index 10ef0ba24b..1982c29a9a 100644 --- a/frb_codegen/src/library/utils/namespace.rs +++ b/frb_codegen/src/library/utils/namespace.rs @@ -14,12 +14,12 @@ pub struct Namespace { } impl Namespace { - const SEP: &'static str = "::"; + pub(crate) const SEP: &'static str = "::"; - // pub fn new(path: Vec) -> Self { - // assert!((path.iter()).all(|item| !item.contains(Self::SEP))); - // Self::new_raw(path.join(Self::SEP)) - // } + pub fn new(path: Vec) -> Self { + assert!((path.iter()).all(|item| !item.contains(Self::SEP))); + Self::new_raw(path.join(Self::SEP)) + } pub fn new_raw(joined_path: String) -> Self { // This will stop the whole generator and tell the users, so we do not care about testing it From ad08eaf495b10960581281df5ed2de28dea97038 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:21:41 +0800 Subject: [PATCH 22/34] fix: err --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 86c9e48295..f68fc88437 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -30,7 +30,7 @@ fn parse_pub_use_from_item(item: &syn::Item) -> Option { let tree = &item_use.tree; let tree_string = quote::quote!(#tree).to_string().replace(' ', ""); let tree_parts = tree_string.split(Namespace::SEP).collect_vec(); - let name_filters = match tree_parts.last() { + let name_filters = match tree_parts.last().unwrap() { "*" => None, x => Some(x.to_string()), }; From af8a6f5c236b2c9ac1c449cf9f5e61292eb134a0 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:23:05 +0800 Subject: [PATCH 23/34] fix: more --- .../hir/hierarchical/module/pub_use_transformer.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index f68fc88437..ef429c22f5 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -30,13 +30,17 @@ fn parse_pub_use_from_item(item: &syn::Item) -> Option { let tree = &item_use.tree; let tree_string = quote::quote!(#tree).to_string().replace(' ', ""); let tree_parts = tree_string.split(Namespace::SEP).collect_vec(); - let name_filters = match tree_parts.last().unwrap() { + let name_filters = match *tree_parts.last().unwrap() { "*" => None, - x => Some(x.to_string()), + x => Some(vec![x.to_string()]), }; return Some(PubUseInfo { - namespace: Namespace::new_raw(tree_parts[..tree_parts.len() - 1]), + namespace: Namespace::new( + (tree_parts[..tree_parts.len() - 1].iter()) + .map(ToString::to_string) + .collect_vec(), + ), name_filters, }); } From 33edb5ae4840c78440b38a0965a4760db5ab35cc Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:23:14 +0800 Subject: [PATCH 24/34] chore: lint --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index ef429c22f5..2b151ab4e8 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -2,7 +2,6 @@ use crate::codegen::ir::hir::hierarchical::misc::HirCommon; use crate::codegen::ir::hir::hierarchical::module::HirModule; use crate::utils::namespace::Namespace; use itertools::Itertools; -use quote::ToTokens; pub(crate) fn transform(mut module: HirModule, items: &[syn::Item]) -> anyhow::Result { // Only apply to third party crate currently, since in self crate usually no need to care about this From efe2330f1b6402a8d3f1b33b3d50818652e13815 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:29:00 +0800 Subject: [PATCH 25/34] feat: more --- .../library/codegen/ir/hir/hierarchical/function.rs | 2 -- .../src/library/codegen/ir/hir/hierarchical/traits.rs | 11 +++++++---- 2 files changed, 7 insertions(+), 6 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 1f03133148..943615332b 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -8,9 +8,7 @@ use syn::{Attribute, ImplItemFn, ItemFn, ItemImpl, Signature, TraitItemFn, Visib #[derive(Debug, Clone, Serialize)] pub(crate) struct HirFunction { pub(crate) namespace: Namespace, - #[serde(skip_serializing)] pub(crate) owner: HirFunctionOwner, - #[serde(skip_serializing)] pub(crate) item_fn: GeneralizedItemFn, } diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs index dc33463b26..59f490030f 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs @@ -1,20 +1,19 @@ -use proc_macro2::Ident; use crate::codegen::ir::hir::hierarchical::misc::HirCommon; use crate::utils::namespace::Namespace; -use serde::Serialize; +use proc_macro2::Ident; +use serde::{Serialize, Serializer}; use syn::{ItemImpl, ItemTrait}; #[derive(Debug, Clone, Serialize)] pub(crate) struct HirTrait { pub(crate) namespace: Namespace, - #[serde(skip_serializing)] + #[serde(serialize_with = "serialize_item_trait")] pub(crate) item_trait: ItemTrait, } #[derive(Debug, Clone, Serialize)] pub(crate) struct HirTraitImpl { pub(crate) namespace: Namespace, - #[serde(skip_serializing)] pub(crate) item_impl: ItemImpl, } @@ -30,3 +29,7 @@ impl HirCommon for HirTrait { self.item_trait.ident.clone() } } + +fn serialize_item_trait(x: &ItemTrait, s: S) -> Result { + s.serialize_str(&format!("ident={}", x.ident.to_string())) +} From e6ce83858ce53682f8104d19456e96b96e07575b Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:30:49 +0800 Subject: [PATCH 26/34] feat: more --- .../src/library/codegen/ir/hir/hierarchical/function.rs | 4 +++- .../src/library/codegen/ir/hir/hierarchical/traits.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 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 943615332b..613da0b888 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/function.rs @@ -9,6 +9,7 @@ use syn::{Attribute, ImplItemFn, ItemFn, ItemImpl, Signature, TraitItemFn, Visib pub(crate) struct HirFunction { pub(crate) namespace: Namespace, pub(crate) owner: HirFunctionOwner, + #[serde(skip_serializing)] pub(crate) item_fn: GeneralizedItemFn, } @@ -45,10 +46,11 @@ impl HirFunction { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize)] pub(crate) enum HirFunctionOwner { Function, Method { + #[serde(skip_serializing)] item_impl: ItemImpl, trait_def_name: Option, }, diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs index 59f490030f..e2af79c637 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs @@ -14,6 +14,7 @@ pub(crate) struct HirTrait { #[derive(Debug, Clone, Serialize)] pub(crate) struct HirTraitImpl { pub(crate) namespace: Namespace, + #[serde(serialize_with = "serialize_item_impl")] pub(crate) item_impl: ItemImpl, } @@ -33,3 +34,11 @@ impl HirCommon for HirTrait { fn serialize_item_trait(x: &ItemTrait, s: S) -> Result { s.serialize_str(&format!("ident={}", x.ident.to_string())) } + +fn serialize_item_impl(x: &ItemImpl, s: S) -> Result { + s.serialize_str(&format!("self_ty={}", ty_to_string(&x.self_ty))) +} + +fn ty_to_string(ty: &syn::Type) -> String { + quote::quote!(#ty).to_string() +} From f51cf91353462d213f9f2509d2e82baa0e83cd6a Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:33:43 +0800 Subject: [PATCH 27/34] chore: log --- .../hir/hierarchical/module/pub_use_transformer.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 2b151ab4e8..30f5b50896 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -68,8 +68,13 @@ fn transform_module_by_pub_use_single( pub_use_info: &PubUseInfo, ) -> anyhow::Result<()> { if let Some(src_mod) = (module.content).get_module_nested(&pub_use_info.namespace.path()) { + log::info!( + "transform_module_by_pub_use_single pub_use_info={:?}", + pub_use_info + ); + if src_mod.meta.is_public() { - log::debug!("transform_module_by_pub_use_single skip `{pub_use_info:?}` since src mod already public"); + log::info!("transform_module_by_pub_use_single skip `{pub_use_info:?}` since src mod already public"); return Ok(()); } @@ -86,7 +91,7 @@ fn transform_module_by_pub_use_single( module.content.enums.extend(src_enums); module.content.traits.extend(src_traits); } else { - log::debug!( + log::info!( "transform_module_by_pub_use_single skip `{pub_use_info:?}` since cannot find mod" ); } From c71df489725f05328ae26514dff2f624943636f7 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:34:40 +0800 Subject: [PATCH 28/34] feat: more --- .../parser/hir/hierarchical/module/pub_use_transformer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs index 30f5b50896..11a7c30e87 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/module/pub_use_transformer.rs @@ -68,13 +68,13 @@ fn transform_module_by_pub_use_single( pub_use_info: &PubUseInfo, ) -> anyhow::Result<()> { if let Some(src_mod) = (module.content).get_module_nested(&pub_use_info.namespace.path()) { - log::info!( + log::debug!( "transform_module_by_pub_use_single pub_use_info={:?}", pub_use_info ); if src_mod.meta.is_public() { - log::info!("transform_module_by_pub_use_single skip `{pub_use_info:?}` since src mod already public"); + log::debug!("transform_module_by_pub_use_single skip `{pub_use_info:?}` since src mod already public"); return Ok(()); } @@ -91,7 +91,7 @@ fn transform_module_by_pub_use_single( module.content.enums.extend(src_enums); module.content.traits.extend(src_traits); } else { - log::info!( + log::debug!( "transform_module_by_pub_use_single skip `{pub_use_info:?}` since cannot find mod" ); } From d149bb8cc3b470e47b5801d7a97cd5e99b23676d Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:35:47 +0800 Subject: [PATCH 29/34] fix: err --- frb_codegen/src/library/codegen/parser/hir/flat/mod.rs | 10 ++++++++++ .../hir/hierarchical/pack/trait_impl_transformer.rs | 10 +--------- 2 files changed, 11 insertions(+), 9 deletions(-) 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 35f46d984b..876311c704 100644 --- a/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs @@ -11,6 +11,7 @@ use log::debug; use std::collections::HashMap; use std::fmt::Debug; use syn::Type; +use crate::codegen::ir::hir::hierarchical::traits::HirTrait; mod type_alias_resolver; @@ -60,6 +61,15 @@ fn collect_enums(hir_pack: &HirPack) -> HashMap { ) } +// TODO move +pub(crate) fn collect_traits(hir_pack: &HirPack) -> HashMap { + collect_objects_map( + hir_pack, + |module| &module.content.traits, + |x| (x.item_trait.ident.to_string(), x), + ) +} + fn collect_types(hir_pack: &HirPack) -> HashMap { collect_objects_map( hir_pack, diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs index 7675af26be..65f22124c2 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs @@ -4,6 +4,7 @@ use crate::codegen::ir::hir::hierarchical::function::{ use crate::codegen::ir::hir::hierarchical::module::HirModule; use crate::codegen::ir::hir::hierarchical::pack::HirPack; use crate::codegen::ir::hir::hierarchical::traits::HirTrait; +use crate::codegen::parser::hir::flat::collect_traits; use crate::codegen::parser::hir::hierarchical::function::parse_syn_item_impl; use crate::if_then_some; use crate::utils::namespace::{Namespace, NamespacedName}; @@ -19,15 +20,6 @@ pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { Ok(pack) } -fn collect_traits(pack: &HirPack) -> HashMap { - let mut traits = vec![]; - pack.visit(&mut |module| traits.extend(module.content.traits.clone())); - traits - .into_iter() - .map(|t| (t.item_trait.ident.to_string(), t)) - .collect() -} - fn compute_methods(module: &HirModule, trait_map: &HashMap) -> Vec { (module.content.trait_impls.iter()) .flat_map(|trait_impl| { From 54dae48e9c3a9a361fcf3a97d1ef79d737aff03b Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:36:01 +0800 Subject: [PATCH 30/34] fix: err --- .../parser/hir/hierarchical/pack/trait_impl_transformer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs index 65f22124c2..ccf86c56c7 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs @@ -20,7 +20,7 @@ pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { Ok(pack) } -fn compute_methods(module: &HirModule, trait_map: &HashMap) -> Vec { +fn compute_methods(module: &HirModule, trait_map: &HashMap) -> Vec { (module.content.trait_impls.iter()) .flat_map(|trait_impl| { let namespace = &trait_impl.namespace; From 16a462d47253e2d1e1e356d65b08534dbb4ff015 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:36:33 +0800 Subject: [PATCH 31/34] fix: more --- .../hir/hierarchical/pack/trait_impl_transformer.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs index ccf86c56c7..8dadceb1ce 100644 --- a/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/hierarchical/pack/trait_impl_transformer.rs @@ -13,14 +13,18 @@ use std::collections::HashMap; use syn::{ItemImpl, TraitItem}; pub(super) fn transform(mut pack: HirPack) -> anyhow::Result { - let trait_map = collect_traits(&pack); + let trait_map = (collect_traits(&pack).into_iter()) + .map(|(k, v)| (k, v.to_owned())) + .collect::>(); + pack.visit_mut(&mut |module| { (module.content.functions).extend(compute_methods(module, &trait_map)); }); + Ok(pack) } -fn compute_methods(module: &HirModule, trait_map: &HashMap) -> Vec { +fn compute_methods(module: &HirModule, trait_map: &HashMap) -> Vec { (module.content.trait_impls.iter()) .flat_map(|trait_impl| { let namespace = &trait_impl.namespace; From effd2839c0410bf8327ea1f0da41346207a517ef Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 10:40:57 +0800 Subject: [PATCH 32/34] chore: lint --- frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs | 2 +- frb_codegen/src/library/codegen/parser/hir/flat/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 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 c1d7c113f9..2156ecb543 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/mod.rs @@ -1,9 +1,9 @@ pub(crate) mod crates; pub(crate) mod function; +pub(crate) mod misc; pub(crate) mod module; pub(crate) mod pack; pub(crate) mod struct_or_enum; pub(crate) mod syn_item_struct_or_enum; pub(crate) mod traits; pub(crate) mod type_alias; -pub(crate) mod misc; 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 876311c704..9e1c0b473d 100644 --- a/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs @@ -4,6 +4,7 @@ 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::HirEnum; use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStruct; +use crate::codegen::ir::hir::hierarchical::traits::HirTrait; use crate::codegen::parser::hir::flat::type_alias_resolver::resolve_type_aliases; use crate::codegen::parser::hir::internal_config::ParserHirInternalConfig; use crate::utils::crate_name::CrateName; @@ -11,7 +12,6 @@ use log::debug; use std::collections::HashMap; use std::fmt::Debug; use syn::Type; -use crate::codegen::ir::hir::hierarchical::traits::HirTrait; mod type_alias_resolver; From 8ec6536f5a4dad95d88a3a04876a34f52a9b5380 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 11:00:20 +0800 Subject: [PATCH 33/34] fix: lint --- frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs index e2af79c637..764031c3ee 100644 --- a/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs +++ b/frb_codegen/src/library/codegen/ir/hir/hierarchical/traits.rs @@ -32,7 +32,7 @@ impl HirCommon for HirTrait { } fn serialize_item_trait(x: &ItemTrait, s: S) -> Result { - s.serialize_str(&format!("ident={}", x.ident.to_string())) + s.serialize_str(&format!("ident={}", x.ident)) } fn serialize_item_impl(x: &ItemImpl, s: S) -> Result { From 6821c19d362717729ba9fb0b150cf66a74e59ac4 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 4 Jun 2024 11:29:31 +0800 Subject: [PATCH 34/34] chore: goldens --- .../mod/generics/expect_hir_hierarchical.json | 15 ++++++---- .../mod/methods/expect_hir_hierarchical.json | 28 ++++++++++++++++--- .../expect_hir_hierarchical.json | 6 ++-- .../expect_hir_hierarchical.json | 6 ++-- .../expect_hir_hierarchical.json | 12 +++++--- .../mod/simple/expect_hir_hierarchical.json | 3 +- .../expect_hir_hierarchical.json | 3 +- 7 files changed, 54 insertions(+), 19 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 cc8e0f9850..85c94ddb7c 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 @@ -19,19 +19,24 @@ ], "functions": [ { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" } ], "modules": [], 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 fa2ec3d260..2ed0a802e7 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 @@ -19,16 +19,36 @@ ], "functions": [ { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": { + "Method": { + "trait_def_name": null + } + } }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": { + "Method": { + "trait_def_name": null + } + } }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": { + "Method": { + "trait_def_name": null + } + } }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": { + "Method": { + "trait_def_name": null + } + } } ], "modules": [], 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 29735bfbb2..5f6769526c 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 @@ -12,7 +12,8 @@ "enums": [], "functions": [ { - "namespace": "crate::api_one" + "namespace": "crate::api_one", + "owner": "Function" } ], "modules": [], @@ -32,7 +33,8 @@ "enums": [], "functions": [ { - "namespace": "crate::api_two" + "namespace": "crate::api_two", + "owner": "Function" } ], "modules": [], 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 7c72530672..f2e2ca833d 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 @@ -12,10 +12,12 @@ "enums": [], "functions": [ { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" } ], "modules": [], 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 0833090f70..a4a6469acc 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 @@ -12,16 +12,20 @@ "enums": [], "functions": [ { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" }, { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" } ], "modules": [], 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 776f2e485e..1aee36ea99 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 @@ -12,7 +12,8 @@ "enums": [], "functions": [ { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" } ], "modules": [], 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 cc7bd2a0ee..a5cebe1bac 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 @@ -42,7 +42,8 @@ "enums": [], "functions": [ { - "namespace": "crate::api" + "namespace": "crate::api", + "owner": "Function" } ], "modules": [],