Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sh permission #1842

Merged
merged 29 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

* Fix class is not generated when having only static methods #1851
* Fix passing non-existent variable to getter causing compilation error #1851
* Fix missing code generation when using enum and methods #1851

## 2.0.0-dev.29

* Please refer to https://fzyzcjy.github.io/flutter_rust_bridge/guides/miscellaneous/whats-new for what's changed in V2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ A new Flutter FFI plugin project.
'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386',
'OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/libREPLACE_ME_RUST_CRATE_NAME.a',
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ A new Flutter FFI plugin project.
'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386',
'OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/libREPLACE_ME_RUST_CRATE_NAME.a',
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn generate_api_method(func: &IrFunc, context: ApiDartGeneratorContext) -> Strin
let comments = generate_comments(func, default_constructor_mode);
let signature =
generate_signature(func, context, method_info, params, default_constructor_mode);
let arg_names = generate_arg_names(func, is_static_method, skip_count).concat();
let arg_names = generate_arg_names(func, skip_count).concat();
let implementation = generate_implementation(func, context, is_static_method, arg_names);

format!("{comments}{signature}=>{implementation};\n\n")
Expand Down Expand Up @@ -141,15 +141,15 @@ fn generate_signature(
format!("{maybe_static} {return_type} {maybe_getter} {method_name}{func_params}")
}

fn generate_arg_names(func: &IrFunc, is_static_method: bool, skip_count: usize) -> Vec<String> {
fn generate_arg_names(func: &IrFunc, skip_count: usize) -> Vec<String> {
let mut ans = func
.inputs
.iter()
.skip(skip_count)
.map(|input| format!("{}:{},", input.name.dart_style(), input.name.dart_style()))
.collect_vec();
if is_static_method {
ans.push("hint: hint".to_string());
if !func.getter {
ans.push("hint: hint,".to_string());
}
ans
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::codegen::generator::api_dart::spec_generator::class::field::{
generate_field_default, generate_field_required_modifier,
};
use crate::codegen::generator::api_dart::spec_generator::class::method::generate_api_methods;
use crate::codegen::generator::api_dart::spec_generator::class::ApiDartGeneratedClass;
use crate::codegen::generator::api_dart::spec_generator::misc::{
generate_dart_comments, generate_dart_maybe_implements_exception,
Expand Down Expand Up @@ -31,12 +32,18 @@ impl<'a> EnumRefApiDartGenerator<'a> {
let maybe_implements_exception =
generate_dart_maybe_implements_exception(self.ir.is_exception);

let methods_str = generate_api_methods(&src.name, self.context).join("\n");

Some(ApiDartGeneratedClass {
namespace: src.name.namespace.clone(),
code: format!(
"@freezed
{sealed} class {name} with _${name} {maybe_implements_exception} {{
const {name}._();

{variants}

{methods_str}
}}",
),
needs_freezed: true,
Expand Down
11 changes: 10 additions & 1 deletion frb_codegen/src/library/codegen/ir/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ pub enum IrFuncOwnerInfo {
}

pub struct IrFuncOwnerInfoMethod {
pub(crate) enum_or_struct_name: NamespacedName,
pub(crate) enum_or_struct_ty: IrType,
pub(crate) enum_or_struct_name: NamespacedName, // TODO use info in `enum_or_struct_ty`
pub(crate) actual_method_name: String,
pub(crate) mode: IrFuncOwnerInfoMethodMode,
}
Expand Down Expand Up @@ -73,6 +74,14 @@ impl IrFunc {
let error_output = (self.error_output.as_ref().cloned())
.unwrap_or(IrType::Primitive(IrTypePrimitive::Unit));
error_output.visit_types(f, ir_context);

// extra (#1838)
if let IrFuncOwnerInfo::Method(IrFuncOwnerInfoMethod {
enum_or_struct_ty, ..
}) = &self.owner
{
enum_or_struct_ty.visit_types(f, ir_context);
}
}

pub(crate) fn default_constructor_mode(&self) -> Option<IrFuncDefaultConstructorMode> {
Expand Down
7 changes: 4 additions & 3 deletions frb_codegen/src/library/codegen/parser/function_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> {
IrFuncOwnerInfoMethodMode::Static
};

let enum_or_struct_name =
let (enum_or_struct_ty, enum_or_struct_name) =
if let Some(x) = self.parse_enum_or_struct_name(item_impl, context)? {
x
} else {
Expand All @@ -149,6 +149,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> {
let actual_method_name = impl_item_fn.sig.ident.to_string();

IrFuncOwnerInfo::Method(IrFuncOwnerInfoMethod {
enum_or_struct_ty,
enum_or_struct_name,
actual_method_name,
mode,
Expand All @@ -161,7 +162,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> {
&mut self,
item_impl: &ItemImpl,
context: &TypeParserParsingContext,
) -> anyhow::Result<Option<NamespacedName>> {
) -> anyhow::Result<Option<(IrType, NamespacedName)>> {
let self_ty_path = if let Type::Path(self_ty_path) = item_impl.self_ty.as_ref() {
self_ty_path
} else {
Expand All @@ -173,7 +174,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> {
let ty = self.type_parser.parse_type(&syn_ty, context)?;

let namespace: Option<Namespace> = ty.self_namespace();
Ok(namespace.map(|namespace| NamespacedName::new(namespace, enum_or_struct_name)))
Ok(namespace.map(|namespace| (ty, NamespacedName::new(namespace, enum_or_struct_name))))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@
"Method": {
"actual_method_name": "example_instance_method",
"enum_or_struct_name": "crate::api/MyEnum",
"enum_or_struct_ty": {
"data": {
"PrimitiveEnum": {
"ir": {
"ident": "crate::api/MyEnum",
"is_exception": false
},
"repr": "I32"
}
},
"safe_ident": "my_enum",
"type": "Delegate"
},
"mode": "Instance"
}
},
Expand Down Expand Up @@ -94,6 +107,19 @@
"Method": {
"actual_method_name": "example_static_method",
"enum_or_struct_name": "crate::api/MyEnum",
"enum_or_struct_ty": {
"data": {
"PrimitiveEnum": {
"ir": {
"ident": "crate::api/MyEnum",
"is_exception": false
},
"repr": "I32"
}
},
"safe_ident": "my_enum",
"type": "Delegate"
},
"mode": "Static"
}
},
Expand Down Expand Up @@ -146,6 +172,14 @@
"Method": {
"actual_method_name": "example_instance_method",
"enum_or_struct_name": "crate::api/MyStruct",
"enum_or_struct_ty": {
"data": {
"ident": "crate::api/MyStruct",
"is_exception": false
},
"safe_ident": "my_struct",
"type": "StructRef"
},
"mode": "Instance"
}
},
Expand Down Expand Up @@ -173,6 +207,14 @@
"Method": {
"actual_method_name": "example_static_method",
"enum_or_struct_name": "crate::api/MyStruct",
"enum_or_struct_ty": {
"data": {
"ident": "crate::api/MyStruct",
"is_exception": false
},
"safe_ident": "my_struct",
"type": "StructRef"
},
"mode": "Static"
}
},
Expand Down
Loading
Loading