From 59fa7e7e1374eedd5219e9e247de8c40ccbce248 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:29:50 +0800 Subject: [PATCH 01/33] refactor: extract --- .../parser/mir/function_parser/argument.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs index cbf2810115..184a7c125b 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs @@ -48,13 +48,11 @@ impl<'a, 'b> FunctionParser<'a, 'b> { ownership_mode_split, )?; - if let MirType::StructRef(s) = &ty { - if s.get(self.type_parser).ignore { - return Ok(FunctionPartialInfo { - ignore_func: true, - ..Default::default() - }); - } + if should_ignore_function_by_type(ty, self.type_parser) { + return Ok(FunctionPartialInfo { + ignore_func: true, + ..Default::default() + }); } let attrs = parse_attrs_from_fn_arg(sig_input); @@ -78,6 +76,12 @@ impl<'a, 'b> FunctionParser<'a, 'b> { } } +fn should_ignore_function_by_type(ty: &MirType, type_parser: &mut TypeParser) -> bool { + match ty { + MirType::StructRef(s) => s.get(type_parser).ignore, + } +} + pub(crate) fn merge_ownership_into_ty( type_parser: &mut TypeParser, context: &TypeParserParsingContext, From 00ffa6def93be8a6fe521639f94859f1286d847a Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:30:24 +0800 Subject: [PATCH 02/33] chore: hint --- .../src/library/codegen/parser/mir/function_parser/argument.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs index 184a7c125b..9683378900 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs @@ -78,7 +78,8 @@ impl<'a, 'b> FunctionParser<'a, 'b> { fn should_ignore_function_by_type(ty: &MirType, type_parser: &mut TypeParser) -> bool { match ty { - MirType::StructRef(s) => s.get(type_parser).ignore, + MirType::StructRef(ty) => ty.get(type_parser).ignore, + // TODO handle enum } } From 3bfd108e5dac0463cccde9bfd6216c66eafe3995 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:33:38 +0800 Subject: [PATCH 03/33] chore: more --- .../src/library/codegen/parser/mir/type_parser/structure.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 4c241070a3..697ad6b9c1 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 @@ -51,13 +51,15 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let attributes = FrbAttributes::parse(&src_struct.src.attrs)?; let dart_metadata = attributes.dart_metadata(); + let ignore = attributes.ignore() || TODO; + Ok(MirStruct { name, wrapper_name, fields, is_fields_named, dart_metadata, - ignore: attributes.ignore(), + ignore, generate_hash: attributes.generate_hash(), generate_eq: attributes.generate_eq(), comments, From 52adbd24da83a19f2348a45df6dc874bbb930c82 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:34:44 +0800 Subject: [PATCH 04/33] feat: more --- .../src/library/codegen/parser/mir/type_parser/structure.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 697ad6b9c1..f658b0193b 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 @@ -1,3 +1,4 @@ +use crate::codegen::ir::hir::hierarchical::module::HirVisibility; use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStruct; use crate::codegen::ir::mir::field::{MirField, MirFieldSettings}; use crate::codegen::ir::mir::ident::MirIdent; @@ -51,7 +52,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let attributes = FrbAttributes::parse(&src_struct.src.attrs)?; let dart_metadata = attributes.dart_metadata(); - let ignore = attributes.ignore() || TODO; + let ignore = attributes.ignore() || (src_struct.visibility != HirVisibility::Public); Ok(MirStruct { name, From cf0233bb9931717aced91c9045deab0392ca105f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:35:19 +0800 Subject: [PATCH 05/33] fix: err --- .../src/library/codegen/parser/mir/function_parser/argument.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs index 9683378900..a2ac2a0497 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs @@ -48,7 +48,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { ownership_mode_split, )?; - if should_ignore_function_by_type(ty, self.type_parser) { + if should_ignore_function_by_type(&ty, self.type_parser) { return Ok(FunctionPartialInfo { ignore_func: true, ..Default::default() From b7a2b41cb610b7e6852d8e70a519e96bd77a5edf Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 18:36:54 +0800 Subject: [PATCH 06/33] fix: err --- .../src/library/codegen/parser/mir/function_parser/argument.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs index a2ac2a0497..42c8acf71d 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs @@ -79,6 +79,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { fn should_ignore_function_by_type(ty: &MirType, type_parser: &mut TypeParser) -> bool { match ty { MirType::StructRef(ty) => ty.get(type_parser).ignore, + _ => false, // TODO handle enum } } From b6e344fca4c8c92cbb899458e2d53faf4bcb3737 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 19:56:07 +0800 Subject: [PATCH 07/33] feat: field --- frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs | 1 + .../src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs b/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs index 43081aa73c..23847e244d 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs @@ -22,6 +22,7 @@ pub struct MirEnum { pub comments: Vec, pub variants: Vec, pub mode: MirEnumMode, + pub ignore: bool, } #[derive(Copy)] diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs b/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs index 1b7fa9f64d..1a4bb281c0 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs @@ -10,6 +10,7 @@ pub struct MirTypeRustAutoOpaqueImplicit { pub ownership_mode: OwnershipMode, pub inner: MirTypeRustOpaque, pub raw: MirRustAutoOpaqueRaw, + pub ignore: bool, } /// Original type without any transformation From d900d19bfdd3180dfaf383e25f0c23cd1743f87f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 19:57:25 +0800 Subject: [PATCH 08/33] feat: more --- frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs | 4 ++++ frb_codegen/src/library/codegen/ir/mir/ty/mod.rs | 4 ++++ .../library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs | 4 ++++ frb_codegen/src/library/codegen/ir/mir/ty/structure.rs | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs b/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs index 23847e244d..c30fd20c33 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs @@ -78,6 +78,10 @@ impl MirTypeTrait for MirTypeEnumRef { fn self_namespace(&self) -> Option { Some(self.ident.0.namespace.clone()) } + + fn ignore(&self, mir_context: &impl MirContext) -> bool { + self.get(mir_context).ignore + } } impl MirEnum { diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs b/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs index ebc15b19b0..5490d802d4 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs @@ -100,6 +100,10 @@ pub trait MirTypeTrait { None } + fn ignore(&self, mir_context: &impl MirContext) -> bool { + false + } + // TODO move fn cloned_getter_semantics_reasonable(&self) -> bool { false diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs b/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs index 1a4bb281c0..cba33f23f1 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs @@ -48,6 +48,10 @@ impl MirTypeTrait for MirTypeRustAutoOpaqueImplicit { fn as_primitive(&self) -> Option<&MirTypePrimitive> { Some(&RUST_OPAQUE_AS_PRIMITIVE) } + + fn ignore(&self, mir_context: &impl MirContext) -> bool { + self.get(mir_context).ignore + } } impl MirTypeRustAutoOpaqueImplicit { diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/structure.rs b/frb_codegen/src/library/codegen/ir/mir/ty/structure.rs index 40206acb70..6946b6261f 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/structure.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/structure.rs @@ -59,6 +59,10 @@ impl MirTypeTrait for MirTypeStructRef { fn self_namespace(&self) -> Option { Some(self.ident.0.namespace.clone()) } + + fn ignore(&self, mir_context: &impl MirContext) -> bool { + self.get(mir_context).ignore + } } impl MirStruct { From 875a6a4874976ce9cdd071ee903f23499d0a81e3 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 19:57:49 +0800 Subject: [PATCH 09/33] feat: usage --- .../codegen/parser/mir/function_parser/argument.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs index 42c8acf71d..77f61a084a 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs @@ -48,7 +48,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { ownership_mode_split, )?; - if should_ignore_function_by_type(&ty, self.type_parser) { + if ty.ignore(self.type_parser) { return Ok(FunctionPartialInfo { ignore_func: true, ..Default::default() @@ -76,14 +76,6 @@ impl<'a, 'b> FunctionParser<'a, 'b> { } } -fn should_ignore_function_by_type(ty: &MirType, type_parser: &mut TypeParser) -> bool { - match ty { - MirType::StructRef(ty) => ty.get(type_parser).ignore, - _ => false, - // TODO handle enum - } -} - pub(crate) fn merge_ownership_into_ty( type_parser: &mut TypeParser, context: &TypeParserParsingContext, From 5a936ded15f11abf39ed6ef9f07190ece84176e7 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 19:58:15 +0800 Subject: [PATCH 10/33] refactor: rename --- frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs | 2 +- frb_codegen/src/library/codegen/ir/mir/ty/mod.rs | 2 +- .../src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs | 2 +- frb_codegen/src/library/codegen/ir/mir/ty/structure.rs | 2 +- .../src/library/codegen/parser/mir/function_parser/argument.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs b/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs index c30fd20c33..52e0f239f9 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/enumeration.rs @@ -79,7 +79,7 @@ impl MirTypeTrait for MirTypeEnumRef { Some(self.ident.0.namespace.clone()) } - fn ignore(&self, mir_context: &impl MirContext) -> bool { + fn should_ignore(&self, mir_context: &impl MirContext) -> bool { self.get(mir_context).ignore } } diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs b/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs index 5490d802d4..5f505aea78 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs @@ -100,7 +100,7 @@ pub trait MirTypeTrait { None } - fn ignore(&self, mir_context: &impl MirContext) -> bool { + fn should_ignore(&self, mir_context: &impl MirContext) -> bool { false } diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs b/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs index cba33f23f1..556353ef6c 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs @@ -49,7 +49,7 @@ impl MirTypeTrait for MirTypeRustAutoOpaqueImplicit { Some(&RUST_OPAQUE_AS_PRIMITIVE) } - fn ignore(&self, mir_context: &impl MirContext) -> bool { + fn should_ignore(&self, mir_context: &impl MirContext) -> bool { self.get(mir_context).ignore } } diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/structure.rs b/frb_codegen/src/library/codegen/ir/mir/ty/structure.rs index 6946b6261f..7846a3e62e 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/structure.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/structure.rs @@ -60,7 +60,7 @@ impl MirTypeTrait for MirTypeStructRef { Some(self.ident.0.namespace.clone()) } - fn ignore(&self, mir_context: &impl MirContext) -> bool { + fn should_ignore(&self, mir_context: &impl MirContext) -> bool { self.get(mir_context).ignore } } diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs index 77f61a084a..f1670bc1dd 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs @@ -48,7 +48,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { ownership_mode_split, )?; - if ty.ignore(self.type_parser) { + if ty.should_ignore(self.type_parser) { return Ok(FunctionPartialInfo { ignore_func: true, ..Default::default() From 0baae76b8ed8af5300cbe8d781a77918794b84f1 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 19:58:40 +0800 Subject: [PATCH 11/33] fix: err --- .../src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs | 2 +- .../src/library/codegen/parser/mir/function_parser/argument.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs b/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs index 556353ef6c..621c5ea2d4 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs @@ -50,7 +50,7 @@ impl MirTypeTrait for MirTypeRustAutoOpaqueImplicit { } fn should_ignore(&self, mir_context: &impl MirContext) -> bool { - self.get(mir_context).ignore + self.ignore } } diff --git a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs index f1670bc1dd..e5c9d9cc32 100644 --- a/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs +++ b/frb_codegen/src/library/codegen/parser/mir/function_parser/argument.rs @@ -11,6 +11,7 @@ use crate::codegen::parser::mir::type_parser::misc::parse_comments; use crate::codegen::parser::mir::type_parser::rust_auto_opaque_implicit::split_ownership_from_ty; use crate::codegen::parser::mir::type_parser::{TypeParser, TypeParserParsingContext}; use crate::if_then_some; +use crate::library::codegen::ir::mir::ty::MirTypeTrait; use anyhow::Context; use syn::*; From f17fbb02877586361e0fa10064e176698a0076b2 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 19:59:34 +0800 Subject: [PATCH 12/33] feat: more --- .../src/library/codegen/parser/mir/type_parser/enumeration.rs | 3 +++ 1 file changed, 3 insertions(+) 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 3c2ad40fb9..f33e3c6699 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,6 +37,8 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { name: NamespacedName, wrapper_name: Option, ) -> anyhow::Result { + let attributes = FrbAttributes::parse(&src_enum.src.attrs)?; + let comments = parse_comments(&src_enum.src.attrs); let raw_variants = src_enum .src @@ -54,6 +56,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { comments, variants, mode, + ignore: attributes.ignore(), }) } From bde0ae07071ed767245170e86f929bc4879b4944 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:01:15 +0800 Subject: [PATCH 13/33] refactor: extract --- .../src/library/codegen/parser/mir/type_parser/misc.rs | 6 ++++++ .../src/library/codegen/parser/mir/type_parser/structure.rs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index 127ce35c34..5cc8bcfacb 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -1,4 +1,6 @@ +use crate::codegen::ir::hir::hierarchical::module::HirVisibility; use crate::codegen::ir::mir::comment::MirComment; +use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use itertools::Itertools; use syn::*; @@ -45,3 +47,7 @@ fn parse_comment(input: &str) -> MirComment { format!("///{input}") }) } + +pub(crate) fn parse_simple_type_should_ignore(attrs: &FrbAttributes, vis: HirVisibility) -> bool { + attributes.ignore() || (vis != HirVisibility::Public) +} 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 f658b0193b..245a959954 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 @@ -9,7 +9,7 @@ use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::enum_or_struct::{ EnumOrStructParser, EnumOrStructParserInfo, }; -use crate::codegen::parser::mir::type_parser::misc::parse_comments; +use crate::codegen::parser::mir::type_parser::misc::{parse_comments, parse_simple_type_should_ignore}; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::codegen::parser::mir::type_parser::TypeParserWithContext; use crate::utils::namespace::{Namespace, NamespacedName}; @@ -52,7 +52,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let attributes = FrbAttributes::parse(&src_struct.src.attrs)?; let dart_metadata = attributes.dart_metadata(); - let ignore = attributes.ignore() || (src_struct.visibility != HirVisibility::Public); + let ignore = parse_simple_type_should_ignore(&attributes, src_struct.visibility); Ok(MirStruct { name, From 2cac78d0fb3b032f1bad6671c6023baf5856b6a6 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:01:39 +0800 Subject: [PATCH 14/33] feat: more --- .../src/library/codegen/parser/mir/type_parser/enumeration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 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 f33e3c6699..9f13ec528f 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 @@ -14,7 +14,7 @@ use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::enum_or_struct::{ EnumOrStructParser, EnumOrStructParserInfo, }; -use crate::codegen::parser::mir::type_parser::misc::parse_comments; +use crate::codegen::parser::mir::type_parser::misc::{parse_comments, parse_simple_type_should_ignore}; use crate::codegen::parser::mir::type_parser::structure::structure_compute_default_opaque; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::codegen::parser::mir::type_parser::TypeParserWithContext; @@ -56,7 +56,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { comments, variants, mode, - ignore: attributes.ignore(), + ignore: parse_simple_type_should_ignore(&attributes, src_enum.visibility), }) } From 1a85a9fd312e17248313c7ef3f53e80745668cc0 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:01:47 +0800 Subject: [PATCH 15/33] fix: err --- frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index 5cc8bcfacb..c2c76b889e 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -49,5 +49,5 @@ fn parse_comment(input: &str) -> MirComment { } pub(crate) fn parse_simple_type_should_ignore(attrs: &FrbAttributes, vis: HirVisibility) -> bool { - attributes.ignore() || (vis != HirVisibility::Public) + attrs.ignore() || (vis != HirVisibility::Public) } From 6821ebcf63edfe8900419c7825709fbb6704260f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:03:10 +0800 Subject: [PATCH 16/33] feat: more --- .../library/codegen/parser/mir/type_parser/enum_or_struct.rs | 2 ++ .../src/library/codegen/parser/mir/type_parser/enumeration.rs | 3 ++- .../src/library/codegen/parser/mir/type_parser/path.rs | 2 +- .../parser/mir/type_parser/rust_auto_opaque_implicit.rs | 4 ++++ .../src/library/codegen/parser/mir/type_parser/structure.rs | 3 ++- frb_codegen/src/library/codegen/parser/mir/type_parser/ty.rs | 2 +- 6 files changed, 12 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 5833e69f26..ad5bcefd55 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 @@ -95,6 +95,7 @@ where self.parse_type_rust_auto_opaque_implicit( Some(namespaced_name.namespace.clone()), &syn::parse_str(&namespaced_name.name)?, + Some(TODO), ) } @@ -117,6 +118,7 @@ where &mut self, namespace: Option, ty: &Type, + override_ignore: Option, ) -> anyhow::Result; fn compute_default_opaque(obj: &Obj) -> bool; 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 9f13ec528f..a679b8c420 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 @@ -180,8 +180,9 @@ impl EnumOrStructParser &mut self, namespace: Option, ty: &Type, + override_ignore: Option, ) -> anyhow::Result { - self.0.parse_type_rust_auto_opaque_implicit(namespace, ty) + self.0.parse_type_rust_auto_opaque_implicit(namespace, ty, override_ignore) } fn compute_default_opaque(obj: &MirEnum) -> bool { diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/path.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/path.rs index e88e80637c..8fe8febea0 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/path.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/path.rs @@ -62,6 +62,6 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { } // frb-coverage:ignore-end - self.parse_type_rust_auto_opaque_implicit(None, &syn::Type::Path(type_path.to_owned())) + self.parse_type_rust_auto_opaque_implicit(None, &syn::Type::Path(type_path.to_owned()), None) } } diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/rust_auto_opaque_implicit.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/rust_auto_opaque_implicit.rs index bf3ff7aa06..eb5d74dcb9 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/rust_auto_opaque_implicit.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/rust_auto_opaque_implicit.rs @@ -17,12 +17,14 @@ use anyhow::Result; use quote::ToTokens; use syn::Type; use MirType::RustAutoOpaqueImplicit; +use crate::codegen::parser::mir::type_parser::misc::parse_simple_type_should_ignore; impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { pub(crate) fn parse_type_rust_auto_opaque_implicit( &mut self, namespace: Option, ty: &Type, + override_ignore: Option, ) -> Result { let (inner, ownership_mode) = split_ownership_from_ty(ty); let (ans_raw, ans_inner) = @@ -31,6 +33,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { ownership_mode, raw: ans_raw, inner: ans_inner, + ignore: override_ignore.unwrap_or(false), })) } @@ -93,6 +96,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { self.parse_type_rust_auto_opaque_implicit( ty_raw.self_namespace(), &syn::parse_str(&transform(&ty_raw.raw.string))?, + None, ) } } 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 245a959954..b2a03a4873 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 @@ -123,8 +123,9 @@ impl EnumOrStructParser &mut self, namespace: Option, ty: &Type, + override_ignore: Option, ) -> anyhow::Result { - self.0.parse_type_rust_auto_opaque_implicit(namespace, ty) + self.0.parse_type_rust_auto_opaque_implicit(namespace, ty, override_ignore) } fn compute_default_opaque(obj: &MirStruct) -> bool { diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/ty.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/ty.rs index fed5317a65..150f3ce983 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/ty.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/ty.rs @@ -15,7 +15,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { Type::ImplTrait(type_impl_trait) => self .parse_type_impl_trait_dart_fn(&type_impl_trait) .context("when trying to parse DartFn")?, - _ => self.parse_type_rust_auto_opaque_implicit(None, &resolve_ty)?, + _ => self.parse_type_rust_auto_opaque_implicit(None, &resolve_ty, None)?, }) } From 3695fb809df9d7dc4369baa3d19145163e8d598e Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:04:40 +0800 Subject: [PATCH 17/33] feat: more --- .../library/codegen/parser/mir/type_parser/enum_or_struct.rs | 3 ++- 1 file changed, 2 insertions(+), 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 ad5bcefd55..17d163e17c 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 @@ -11,6 +11,7 @@ use std::collections::{HashMap, HashSet}; use std::fmt::Debug; use std::hash::Hash; use syn::{Ident, Type}; +use crate::codegen::parser::mir::type_parser::misc::parse_simple_type_should_ignore; pub(super) trait EnumOrStructParser where @@ -95,7 +96,7 @@ where self.parse_type_rust_auto_opaque_implicit( Some(namespaced_name.namespace.clone()), &syn::parse_str(&namespaced_name.name)?, - Some(TODO), + Some(parse_simple_type_should_ignore(&attributes, src_enum.visibility)), ) } From bc3af20620980b33d150444397cc9d02faed0c52 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:05:55 +0800 Subject: [PATCH 18/33] feat: more --- .../parser/mir/type_parser/enum_or_struct.rs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 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 17d163e17c..a62bf852f3 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,8 +1,10 @@ +use crate::codegen::ir::hir::hierarchical::module::HirVisibility; 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; +use crate::codegen::parser::mir::type_parser::misc::parse_simple_type_should_ignore; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::library::codegen::ir::mir::ty::MirTypeTrait; use crate::utils::namespace::{Namespace, NamespacedName}; @@ -11,7 +13,6 @@ use std::collections::{HashMap, HashSet}; use std::fmt::Debug; use std::hash::Hash; use syn::{Ident, Type}; -use crate::codegen::parser::mir::type_parser::misc::parse_simple_type_should_ignore; pub(super) trait EnumOrStructParser where @@ -37,6 +38,7 @@ where if let Some(src_object) = self.src_objects().get(&name) { let src_object = (*src_object).clone(); + let vis = src_object.visibility; let namespace = &src_object.namespaced_name.namespace; let namespaced_name = NamespacedName::new(namespace.clone(), name.clone()); @@ -45,7 +47,10 @@ where let attrs_opaque = override_opaque.or(attrs.opaque()); if attrs_opaque == Some(true) { debug!("Treat {name} as opaque since attribute says so"); - return Ok(Some((self.parse_opaque(&namespaced_name)?, attrs))); + return Ok(Some(( + self.parse_opaque(&namespaced_name, attrs, vis)?, + attrs, + ))); } let ident: Id = namespaced_name.clone().into(); @@ -65,7 +70,10 @@ where .map_or(false, |obj| Self::compute_default_opaque(obj)) { debug!("Treat {name} as opaque by compute_default_opaque"); - return Ok(Some((self.parse_opaque(&namespaced_name)?, attrs))); + return Ok(Some(( + self.parse_opaque(&namespaced_name, attrs, vis)?, + attrs, + ))); } return Ok(Some((self.construct_output(ident)?, attrs))); @@ -92,11 +100,16 @@ where } } - fn parse_opaque(&mut self, namespaced_name: &NamespacedName) -> anyhow::Result { + fn parse_opaque( + &mut self, + namespaced_name: &NamespacedName, + attrs: &FrbAttributes, + vis: HirVisibility, + ) -> anyhow::Result { self.parse_type_rust_auto_opaque_implicit( Some(namespaced_name.namespace.clone()), &syn::parse_str(&namespaced_name.name)?, - Some(parse_simple_type_should_ignore(&attributes, src_enum.visibility)), + Some(parse_simple_type_should_ignore(attrs, vis)), ) } From 17b35d88ae3ae01425cfcf08534a304673e5948f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:06:12 +0800 Subject: [PATCH 19/33] fix: err --- .../library/codegen/parser/mir/type_parser/enum_or_struct.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 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 a62bf852f3..08ea6cbf54 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 @@ -48,7 +48,7 @@ where if attrs_opaque == Some(true) { debug!("Treat {name} as opaque since attribute says so"); return Ok(Some(( - self.parse_opaque(&namespaced_name, attrs, vis)?, + self.parse_opaque(&namespaced_name, &attrs, vis)?, attrs, ))); } @@ -71,7 +71,7 @@ where { debug!("Treat {name} as opaque by compute_default_opaque"); return Ok(Some(( - self.parse_opaque(&namespaced_name, attrs, vis)?, + self.parse_opaque(&namespaced_name, &attrs, vis)?, attrs, ))); } From c46d02bc16d28e0a1ecc177a18aa85159342f1eb Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:06:28 +0800 Subject: [PATCH 20/33] chore: lint --- frb_codegen/src/library/codegen/ir/mir/ty/mod.rs | 2 +- .../src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs b/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs index 5f505aea78..f9167db2e1 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/mod.rs @@ -100,7 +100,7 @@ pub trait MirTypeTrait { None } - fn should_ignore(&self, mir_context: &impl MirContext) -> bool { + fn should_ignore(&self, _mir_context: &impl MirContext) -> bool { false } diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs b/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs index 621c5ea2d4..0833469cbe 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/rust_auto_opaque_implicit.rs @@ -49,7 +49,7 @@ impl MirTypeTrait for MirTypeRustAutoOpaqueImplicit { Some(&RUST_OPAQUE_AS_PRIMITIVE) } - fn should_ignore(&self, mir_context: &impl MirContext) -> bool { + fn should_ignore(&self, _mir_context: &impl MirContext) -> bool { self.ignore } } From 5919b2069eea728f0d85674ceff5f58143f7eb73 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:06:36 +0800 Subject: [PATCH 21/33] chore: lint --- .../codegen/parser/mir/type_parser/rust_auto_opaque_implicit.rs | 1 - .../src/library/codegen/parser/mir/type_parser/structure.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/rust_auto_opaque_implicit.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/rust_auto_opaque_implicit.rs index eb5d74dcb9..23583ee953 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/rust_auto_opaque_implicit.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/rust_auto_opaque_implicit.rs @@ -17,7 +17,6 @@ use anyhow::Result; use quote::ToTokens; use syn::Type; use MirType::RustAutoOpaqueImplicit; -use crate::codegen::parser::mir::type_parser::misc::parse_simple_type_should_ignore; impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { pub(crate) fn parse_type_rust_auto_opaque_implicit( 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 b2a03a4873..19d15f22e0 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 @@ -1,4 +1,3 @@ -use crate::codegen::ir::hir::hierarchical::module::HirVisibility; use crate::codegen::ir::hir::hierarchical::struct_or_enum::HirStruct; use crate::codegen::ir::mir::field::{MirField, MirFieldSettings}; use crate::codegen::ir::mir::ident::MirIdent; From c927bf012ca7fad73e4f65af06a4872f470f5663 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:07:50 +0800 Subject: [PATCH 22/33] feat: more --- .../src/library/codegen/parser/mir/function_parser/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) 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 85c44aab75..9aeaa44c59 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 @@ -176,6 +176,10 @@ impl<'a, 'b> FunctionParser<'a, 'b> { return Ok(None); }; + if owner_ty.should_ignore(context) { + return Ok(None); + } + let actual_method_name = impl_item_fn.sig.ident.to_string(); MirFuncOwnerInfo::Method(MirFuncOwnerInfoMethod { From 15f057c281293a165835efa2de0d67c754b5eb4f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:08:41 +0800 Subject: [PATCH 23/33] fix: err --- .../src/library/codegen/parser/mir/function_parser/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9aeaa44c59..030ab8c110 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 @@ -176,7 +176,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { return Ok(None); }; - if owner_ty.should_ignore(context) { + if owner_ty.should_ignore(self.type_parser) { return Ok(None); } From 78e4167e940e5df6710f73e78e94c55bee3384f0 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:15:20 +0800 Subject: [PATCH 24/33] chore: lint --- .../library/codegen/parser/mir/type_parser/enumeration.rs | 7 +++++-- .../src/library/codegen/parser/mir/type_parser/path.rs | 6 +++++- .../library/codegen/parser/mir/type_parser/structure.rs | 7 +++++-- 3 files changed, 15 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 a679b8c420..f25964a581 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 @@ -14,7 +14,9 @@ use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::enum_or_struct::{ EnumOrStructParser, EnumOrStructParserInfo, }; -use crate::codegen::parser::mir::type_parser::misc::{parse_comments, parse_simple_type_should_ignore}; +use crate::codegen::parser::mir::type_parser::misc::{ + parse_comments, parse_simple_type_should_ignore, +}; use crate::codegen::parser::mir::type_parser::structure::structure_compute_default_opaque; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::codegen::parser::mir::type_parser::TypeParserWithContext; @@ -182,7 +184,8 @@ impl EnumOrStructParser ty: &Type, override_ignore: Option, ) -> anyhow::Result { - self.0.parse_type_rust_auto_opaque_implicit(namespace, ty, override_ignore) + self.0 + .parse_type_rust_auto_opaque_implicit(namespace, ty, override_ignore) } fn compute_default_opaque(obj: &MirEnum) -> bool { diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/path.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/path.rs index 8fe8febea0..b70814b6ef 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/path.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/path.rs @@ -62,6 +62,10 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { } // frb-coverage:ignore-end - self.parse_type_rust_auto_opaque_implicit(None, &syn::Type::Path(type_path.to_owned()), None) + self.parse_type_rust_auto_opaque_implicit( + None, + &syn::Type::Path(type_path.to_owned()), + None, + ) } } 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 19d15f22e0..5ffb25b2bc 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 @@ -8,7 +8,9 @@ use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::enum_or_struct::{ EnumOrStructParser, EnumOrStructParserInfo, }; -use crate::codegen::parser::mir::type_parser::misc::{parse_comments, parse_simple_type_should_ignore}; +use crate::codegen::parser::mir::type_parser::misc::{ + parse_comments, parse_simple_type_should_ignore, +}; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::codegen::parser::mir::type_parser::TypeParserWithContext; use crate::utils::namespace::{Namespace, NamespacedName}; @@ -124,7 +126,8 @@ impl EnumOrStructParser ty: &Type, override_ignore: Option, ) -> anyhow::Result { - self.0.parse_type_rust_auto_opaque_implicit(namespace, ty, override_ignore) + self.0 + .parse_type_rust_auto_opaque_implicit(namespace, ty, override_ignore) } fn compute_default_opaque(obj: &MirStruct) -> bool { From 40d0fbbee21188601060c5019c0ca7840fd8368d Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:16:11 +0800 Subject: [PATCH 25/33] refactor: rename --- .../library/codegen/parser/mir/type_parser/enum_or_struct.rs | 4 ++-- .../src/library/codegen/parser/mir/type_parser/enumeration.rs | 4 ++-- .../src/library/codegen/parser/mir/type_parser/misc.rs | 2 +- .../src/library/codegen/parser/mir/type_parser/structure.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 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 08ea6cbf54..4d649f4be7 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 @@ -4,7 +4,7 @@ use crate::codegen::ir::hir::hierarchical::syn_item_struct_or_enum::SynItemStruc use crate::codegen::ir::mir::ty::MirType; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use crate::codegen::parser::mir::type_parser::external_impl; -use crate::codegen::parser::mir::type_parser::misc::parse_simple_type_should_ignore; +use crate::codegen::parser::mir::type_parser::misc::parse_type_should_ignore_simple; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::library::codegen::ir::mir::ty::MirTypeTrait; use crate::utils::namespace::{Namespace, NamespacedName}; @@ -109,7 +109,7 @@ where self.parse_type_rust_auto_opaque_implicit( Some(namespaced_name.namespace.clone()), &syn::parse_str(&namespaced_name.name)?, - Some(parse_simple_type_should_ignore(attrs, vis)), + Some(parse_type_should_ignore_simple(attrs, vis)), ) } 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 f25964a581..982d83bcdf 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 @@ -15,7 +15,7 @@ use crate::codegen::parser::mir::type_parser::enum_or_struct::{ EnumOrStructParser, EnumOrStructParserInfo, }; use crate::codegen::parser::mir::type_parser::misc::{ - parse_comments, parse_simple_type_should_ignore, + parse_comments, parse_type_should_ignore_simple, }; use crate::codegen::parser::mir::type_parser::structure::structure_compute_default_opaque; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; @@ -58,7 +58,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { comments, variants, mode, - ignore: parse_simple_type_should_ignore(&attributes, src_enum.visibility), + ignore: parse_type_should_ignore_simple(&attributes, src_enum.visibility), }) } diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index c2c76b889e..d5c72075cd 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -48,6 +48,6 @@ fn parse_comment(input: &str) -> MirComment { }) } -pub(crate) fn parse_simple_type_should_ignore(attrs: &FrbAttributes, vis: HirVisibility) -> bool { +pub(crate) fn parse_type_should_ignore_simple(attrs: &FrbAttributes, vis: HirVisibility) -> bool { attrs.ignore() || (vis != HirVisibility::Public) } 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 5ffb25b2bc..399b7fdef4 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 @@ -9,7 +9,7 @@ use crate::codegen::parser::mir::type_parser::enum_or_struct::{ EnumOrStructParser, EnumOrStructParserInfo, }; use crate::codegen::parser::mir::type_parser::misc::{ - parse_comments, parse_simple_type_should_ignore, + parse_comments, parse_type_should_ignore_simple, }; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::codegen::parser::mir::type_parser::TypeParserWithContext; @@ -53,7 +53,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let attributes = FrbAttributes::parse(&src_struct.src.attrs)?; let dart_metadata = attributes.dart_metadata(); - let ignore = parse_simple_type_should_ignore(&attributes, src_struct.visibility); + let ignore = parse_type_should_ignore_simple(&attributes, src_struct.visibility); Ok(MirStruct { name, From 4fb77a5883ce8a962d3ff149912ebdc95b764165 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:17:01 +0800 Subject: [PATCH 26/33] feat: more --- .../src/library/codegen/parser/mir/type_parser/misc.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index d5c72075cd..1e8890fdc1 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -3,6 +3,7 @@ use crate::codegen::ir::mir::comment::MirComment; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; use itertools::Itertools; use syn::*; +use crate::utils::crate_name::CrateName; pub(crate) fn convert_ident_str(ty: &Type) -> Option { if let Type::Path(TypePath { qself: _, path }) = ty { @@ -48,6 +49,6 @@ fn parse_comment(input: &str) -> MirComment { }) } -pub(crate) fn parse_type_should_ignore_simple(attrs: &FrbAttributes, vis: HirVisibility) -> bool { - attrs.ignore() || (vis != HirVisibility::Public) +pub(crate) fn parse_type_should_ignore_simple(attrs: &FrbAttributes, vis: HirVisibility, crate_name: &CrateName) -> bool { + attrs.ignore() || (crate_name != CrateName::self_crate() && vis != HirVisibility::Public) } From 78f040784e7c198cbc71b59289ab1142c1bc8137 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:18:33 +0800 Subject: [PATCH 27/33] feat: arg --- .../codegen/parser/mir/type_parser/enum_or_struct.rs | 12 ++++++++---- .../codegen/parser/mir/type_parser/enumeration.rs | 2 +- .../library/codegen/parser/mir/type_parser/mod.rs | 2 ++ .../codegen/parser/mir/type_parser/structure.rs | 2 +- 4 files changed, 12 insertions(+), 6 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 4d649f4be7..78adafaf26 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 @@ -7,6 +7,7 @@ use crate::codegen::parser::mir::type_parser::external_impl; use crate::codegen::parser::mir::type_parser::misc::parse_type_should_ignore_simple; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::library::codegen::ir::mir::ty::MirTypeTrait; +use crate::utils::crate_name::CrateName; use crate::utils::namespace::{Namespace, NamespacedName}; use log::debug; use std::collections::{HashMap, HashSet}; @@ -21,9 +22,10 @@ where fn parse( &mut self, last_segment: &SplayedSegment, + crate_name: &CrateName, override_opaque: Option, ) -> anyhow::Result> { - let output = self.parse_impl(last_segment, override_opaque)?; + let output = self.parse_impl(last_segment , crate_name, override_opaque)?; self.handle_dart_code(&output); Ok(output.map(|(ty, _)| ty)) } @@ -31,6 +33,7 @@ where fn parse_impl( &mut self, last_segment: &SplayedSegment, + crate_name: &CrateName, override_opaque: Option, ) -> anyhow::Result> { let (name, _) = last_segment; @@ -48,7 +51,7 @@ where if attrs_opaque == Some(true) { debug!("Treat {name} as opaque since attribute says so"); return Ok(Some(( - self.parse_opaque(&namespaced_name, &attrs, vis)?, + self.parse_opaque(&namespaced_name, crate_name, &attrs, vis)?, attrs, ))); } @@ -71,7 +74,7 @@ where { debug!("Treat {name} as opaque by compute_default_opaque"); return Ok(Some(( - self.parse_opaque(&namespaced_name, &attrs, vis)?, + self.parse_opaque(&namespaced_name, crate_name, &attrs, vis)?, attrs, ))); } @@ -103,13 +106,14 @@ where fn parse_opaque( &mut self, namespaced_name: &NamespacedName, + crate_name: &CrateName, attrs: &FrbAttributes, vis: HirVisibility, ) -> anyhow::Result { self.parse_type_rust_auto_opaque_implicit( Some(namespaced_name.namespace.clone()), &syn::parse_str(&namespaced_name.name)?, - Some(parse_type_should_ignore_simple(attrs, vis)), + Some(parse_type_should_ignore_simple(attrs, vis, crate_name)), ) } 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 982d83bcdf..e970e9df79 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 @@ -58,7 +58,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { comments, variants, mode, - ignore: parse_type_should_ignore_simple(&attributes, src_enum.visibility), + ignore: parse_type_should_ignore_simple(&attributes, src_enum.visibility, &self.context.crate_name), }) } diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/mod.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/mod.rs index 5bba78035a..618a24b880 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/mod.rs @@ -16,6 +16,7 @@ use crate::codegen::parser::mir::type_parser::rust_opaque::RustOpaqueParserInfo; use crate::utils::namespace::Namespace; use std::collections::HashMap; use syn::Type; +use crate::utils::crate_name::CrateName; pub(crate) mod array; pub(crate) mod concrete; @@ -111,6 +112,7 @@ pub(crate) struct TypeParserParsingContext { pub(crate) default_stream_sink_codec: CodecMode, pub(crate) default_rust_opaque_codec: RustOpaqueCodecMode, pub(crate) owner: Option, + pub(crate) crate_name: CrateName, } impl MirContext for TypeParser<'_> { 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 399b7fdef4..8af3b457a7 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 @@ -53,7 +53,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let attributes = FrbAttributes::parse(&src_struct.src.attrs)?; let dart_metadata = attributes.dart_metadata(); - let ignore = parse_type_should_ignore_simple(&attributes, src_struct.visibility); + let ignore = parse_type_should_ignore_simple(&attributes, src_struct.visibility, &self.context.crate_name); Ok(MirStruct { name, From 4058059b8e49595ace126c7f08e2cfe4e6e5c208 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:19:08 +0800 Subject: [PATCH 28/33] Revert "feat: arg" This reverts commit 78f040784e7c198cbc71b59289ab1142c1bc8137. --- .../codegen/parser/mir/type_parser/enum_or_struct.rs | 12 ++++-------- .../codegen/parser/mir/type_parser/enumeration.rs | 2 +- .../library/codegen/parser/mir/type_parser/mod.rs | 2 -- .../codegen/parser/mir/type_parser/structure.rs | 2 +- 4 files changed, 6 insertions(+), 12 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 78adafaf26..4d649f4be7 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 @@ -7,7 +7,6 @@ use crate::codegen::parser::mir::type_parser::external_impl; use crate::codegen::parser::mir::type_parser::misc::parse_type_should_ignore_simple; use crate::codegen::parser::mir::type_parser::unencodable::SplayedSegment; use crate::library::codegen::ir::mir::ty::MirTypeTrait; -use crate::utils::crate_name::CrateName; use crate::utils::namespace::{Namespace, NamespacedName}; use log::debug; use std::collections::{HashMap, HashSet}; @@ -22,10 +21,9 @@ where fn parse( &mut self, last_segment: &SplayedSegment, - crate_name: &CrateName, override_opaque: Option, ) -> anyhow::Result> { - let output = self.parse_impl(last_segment , crate_name, override_opaque)?; + let output = self.parse_impl(last_segment, override_opaque)?; self.handle_dart_code(&output); Ok(output.map(|(ty, _)| ty)) } @@ -33,7 +31,6 @@ where fn parse_impl( &mut self, last_segment: &SplayedSegment, - crate_name: &CrateName, override_opaque: Option, ) -> anyhow::Result> { let (name, _) = last_segment; @@ -51,7 +48,7 @@ where if attrs_opaque == Some(true) { debug!("Treat {name} as opaque since attribute says so"); return Ok(Some(( - self.parse_opaque(&namespaced_name, crate_name, &attrs, vis)?, + self.parse_opaque(&namespaced_name, &attrs, vis)?, attrs, ))); } @@ -74,7 +71,7 @@ where { debug!("Treat {name} as opaque by compute_default_opaque"); return Ok(Some(( - self.parse_opaque(&namespaced_name, crate_name, &attrs, vis)?, + self.parse_opaque(&namespaced_name, &attrs, vis)?, attrs, ))); } @@ -106,14 +103,13 @@ where fn parse_opaque( &mut self, namespaced_name: &NamespacedName, - crate_name: &CrateName, attrs: &FrbAttributes, vis: HirVisibility, ) -> anyhow::Result { self.parse_type_rust_auto_opaque_implicit( Some(namespaced_name.namespace.clone()), &syn::parse_str(&namespaced_name.name)?, - Some(parse_type_should_ignore_simple(attrs, vis, crate_name)), + Some(parse_type_should_ignore_simple(attrs, vis)), ) } 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 e970e9df79..982d83bcdf 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 @@ -58,7 +58,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { comments, variants, mode, - ignore: parse_type_should_ignore_simple(&attributes, src_enum.visibility, &self.context.crate_name), + ignore: parse_type_should_ignore_simple(&attributes, src_enum.visibility), }) } diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/mod.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/mod.rs index 618a24b880..5bba78035a 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/mod.rs @@ -16,7 +16,6 @@ use crate::codegen::parser::mir::type_parser::rust_opaque::RustOpaqueParserInfo; use crate::utils::namespace::Namespace; use std::collections::HashMap; use syn::Type; -use crate::utils::crate_name::CrateName; pub(crate) mod array; pub(crate) mod concrete; @@ -112,7 +111,6 @@ pub(crate) struct TypeParserParsingContext { pub(crate) default_stream_sink_codec: CodecMode, pub(crate) default_rust_opaque_codec: RustOpaqueCodecMode, pub(crate) owner: Option, - pub(crate) crate_name: CrateName, } impl MirContext for TypeParser<'_> { 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 8af3b457a7..399b7fdef4 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 @@ -53,7 +53,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let attributes = FrbAttributes::parse(&src_struct.src.attrs)?; let dart_metadata = attributes.dart_metadata(); - let ignore = parse_type_should_ignore_simple(&attributes, src_struct.visibility, &self.context.crate_name); + let ignore = parse_type_should_ignore_simple(&attributes, src_struct.visibility); Ok(MirStruct { name, From 79bd31202b3c6c14dcc491cec40bb9c1b2357dad Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:19:29 +0800 Subject: [PATCH 29/33] fix: err --- frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index 1e8890fdc1..ef7b8bb4df 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -50,5 +50,5 @@ fn parse_comment(input: &str) -> MirComment { } pub(crate) fn parse_type_should_ignore_simple(attrs: &FrbAttributes, vis: HirVisibility, crate_name: &CrateName) -> bool { - attrs.ignore() || (crate_name != CrateName::self_crate() && vis != HirVisibility::Public) + attrs.ignore() || (crate_name != &CrateName::self_crate() && vis != HirVisibility::Public) } From e05e1454bb66e0bc1a16b036dffea46cde081949 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:20:42 +0800 Subject: [PATCH 30/33] feat: more --- .../codegen/parser/mir/type_parser/enum_or_struct.rs | 6 +++++- .../library/codegen/parser/mir/type_parser/enumeration.rs | 3 ++- .../src/library/codegen/parser/mir/type_parser/structure.rs | 6 +++++- frb_codegen/src/library/utils/namespace.rs | 4 ++++ 4 files changed, 16 insertions(+), 3 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 4d649f4be7..d25200058b 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 @@ -109,7 +109,11 @@ where self.parse_type_rust_auto_opaque_implicit( Some(namespaced_name.namespace.clone()), &syn::parse_str(&namespaced_name.name)?, - Some(parse_type_should_ignore_simple(attrs, vis)), + Some(parse_type_should_ignore_simple( + attrs, + vis, + &namespaced_name.namespace.crate_name(), + )), ) } 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 982d83bcdf..ef1b8f14e6 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 @@ -51,6 +51,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let mode = compute_enum_mode(&raw_variants); let variants = maybe_field_wrap_box(raw_variants, mode); + let ignore = parse_type_should_ignore_simple(&attributes, src_enum.visibility, &name.namespace.crate_name()); Ok(MirEnum { name, @@ -58,7 +59,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { comments, variants, mode, - ignore: parse_type_should_ignore_simple(&attributes, src_enum.visibility), + ignore, }) } 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 399b7fdef4..1a64ab2fcf 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 @@ -53,7 +53,11 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let attributes = FrbAttributes::parse(&src_struct.src.attrs)?; let dart_metadata = attributes.dart_metadata(); - let ignore = parse_type_should_ignore_simple(&attributes, src_struct.visibility); + let ignore = parse_type_should_ignore_simple( + &attributes, + src_struct.visibility, + &name.namespace.crate_name(), + ); Ok(MirStruct { name, diff --git a/frb_codegen/src/library/utils/namespace.rs b/frb_codegen/src/library/utils/namespace.rs index 9bf2248453..2ab2876258 100644 --- a/frb_codegen/src/library/utils/namespace.rs +++ b/frb_codegen/src/library/utils/namespace.rs @@ -50,6 +50,10 @@ impl Namespace { // Ok(Self::new_self_crate(p)) // } + pub fn crate_name(&self) -> CrateName { + CrateName::new(self.path()[0].to_owned()) + } + pub fn path(&self) -> Vec<&str> { self.joined_path.split(Self::SEP).collect() } From 5c2b30508f1fad7746a00b9c2c7f457365b3e4a7 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:22:58 +0800 Subject: [PATCH 31/33] chore: comments --- .../library/codegen/parser/mir/type_parser/misc.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs index ef7b8bb4df..0ce76f9339 100644 --- a/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs +++ b/frb_codegen/src/library/codegen/parser/mir/type_parser/misc.rs @@ -1,9 +1,9 @@ use crate::codegen::ir::hir::hierarchical::module::HirVisibility; use crate::codegen::ir::mir::comment::MirComment; use crate::codegen::parser::mir::attribute_parser::FrbAttributes; +use crate::utils::crate_name::CrateName; use itertools::Itertools; use syn::*; -use crate::utils::crate_name::CrateName; pub(crate) fn convert_ident_str(ty: &Type) -> Option { if let Type::Path(TypePath { qself: _, path }) = ty { @@ -49,6 +49,13 @@ fn parse_comment(input: &str) -> MirComment { }) } -pub(crate) fn parse_type_should_ignore_simple(attrs: &FrbAttributes, vis: HirVisibility, crate_name: &CrateName) -> bool { - attrs.ignore() || (crate_name != &CrateName::self_crate() && vis != HirVisibility::Public) +pub(crate) fn parse_type_should_ignore_simple( + attrs: &FrbAttributes, + vis: HirVisibility, + crate_name: &CrateName, +) -> bool { + attrs.ignore() + // For third party crates, if a struct is not public, then it is impossible to utilize it, + // thus we ignore it. + || (crate_name != &CrateName::self_crate() && vis != HirVisibility::Public) } From 3bb400aa91666a0d6345bba26f57838db81a1e05 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:23:13 +0800 Subject: [PATCH 32/33] chore: fmt --- .../library/codegen/parser/mir/type_parser/enumeration.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 ef1b8f14e6..17d3f006e0 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 @@ -51,7 +51,11 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { let mode = compute_enum_mode(&raw_variants); let variants = maybe_field_wrap_box(raw_variants, mode); - let ignore = parse_type_should_ignore_simple(&attributes, src_enum.visibility, &name.namespace.crate_name()); + let ignore = parse_type_should_ignore_simple( + &attributes, + src_enum.visibility, + &name.namespace.crate_name(), + ); Ok(MirEnum { name, From 977a7e1b1fce44e43760c7096b44944c2b983adf Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 2 Jun 2024 20:51:22 +0800 Subject: [PATCH 33/33] chore: goldens --- .../codegen/parser/mod/generics/expect_mir.json | 10 ++++++++++ .../library/codegen/parser/mod/methods/expect_mir.json | 1 + .../mod/use_type_in_another_file/expect_mir.json | 1 + 3 files changed, 12 insertions(+) diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_mir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_mir.json index 39d25d773c..072f87fe47 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_mir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_mir.json @@ -3,6 +3,7 @@ "enum_pool": { "crate::api/MyGenericEnum": { "comments": [], + "ignore": false, "mode": "Complex", "name": "crate::api/MyGenericEnum", "variants": [ @@ -24,6 +25,7 @@ }, "ty": { "data": { + "ignore": false, "inner": { "brief_name": true, "codec": "Nom", @@ -75,6 +77,7 @@ }, "ty": { "data": { + "ignore": false, "inner": { "brief_name": true, "codec": "Nom", @@ -138,6 +141,7 @@ }, "ty": { "data": { + "ignore": false, "inner": { "brief_name": true, "codec": "Nom", @@ -201,6 +205,7 @@ }, "ty": { "data": { + "ignore": false, "inner": { "brief_name": true, "codec": "Nom", @@ -264,6 +269,7 @@ }, "ty": { "data": { + "ignore": false, "inner": { "brief_name": true, "codec": "Nom", @@ -327,6 +333,7 @@ }, "ty": { "data": { + "ignore": false, "inner": { "brief_name": true, "codec": "Nom", @@ -390,6 +397,7 @@ }, "ty": { "data": { + "ignore": false, "inner": { "brief_name": true, "codec": "Nom", @@ -447,6 +455,7 @@ }, "ty": { "data": { + "ignore": false, "inner": { "brief_name": true, "codec": "Nom", @@ -479,6 +488,7 @@ }, "ty": { "data": { + "ignore": false, "inner": { "brief_name": true, "codec": "Nom", diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_mir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_mir.json index 655a626439..26ac16d30c 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_mir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_mir.json @@ -3,6 +3,7 @@ "enum_pool": { "crate::api/MyEnum": { "comments": [], + "ignore": false, "mode": "Simple", "name": "crate::api/MyEnum", "variants": [ diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_mir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_mir.json index 283bf017d1..656e3348ce 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_mir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_mir.json @@ -3,6 +3,7 @@ "enum_pool": { "crate::another_file/EnumInAnotherFile": { "comments": [], + "ignore": false, "mode": "Simple", "name": "crate::another_file/EnumInAnotherFile", "variants": [