Skip to content

Commit 7792d63

Browse files
committed
codegen: Minor nits for dynamic function generation.
1 parent c2b5c46 commit 7792d63

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

src/codegen/dyngen.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::ir::function::Abi;
22
use proc_macro2::Ident;
33

44
/// Used to build the output tokens for dynamic bindings.
5+
#[derive(Default)]
56
pub struct DynamicItems {
67
/// Tracks the tokens that will appears inside the library struct -- e.g.:
78
/// ```ignore
@@ -74,18 +75,6 @@ pub struct DynamicItems {
7475
init_fields: Vec<proc_macro2::TokenStream>,
7576
}
7677

77-
impl Default for DynamicItems {
78-
fn default() -> Self {
79-
DynamicItems {
80-
struct_members: vec![],
81-
struct_implementation: vec![],
82-
runtime_checks: vec![],
83-
constructor_inits: vec![],
84-
init_fields: vec![],
85-
}
86-
}
87-
}
88-
8978
impl DynamicItems {
9079
pub fn new() -> Self {
9180
Self::default()
@@ -141,7 +130,7 @@ impl DynamicItems {
141130
}
142131
}
143132

144-
pub fn add_function(
133+
pub fn push(
145134
&mut self,
146135
ident: Ident,
147136
abi: Abi,

src/codegen/mod.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3805,7 +3805,7 @@ impl CodeGenerator for Function {
38053805
TypeKind::Void => quote! {()},
38063806
_ => return_item.to_rust_ty_or_opaque(ctx, &()),
38073807
};
3808-
result.dynamic_items().add_function(
3808+
result.dynamic_items().push(
38093809
ident,
38103810
abi,
38113811
args,
@@ -4105,17 +4105,10 @@ pub(crate) fn codegen(
41054105
&(),
41064106
);
41074107

4108-
if context.options().dynamic_library_name.is_some() {
4109-
let lib_ident = context.rust_ident(
4110-
context.options().dynamic_library_name.as_ref().unwrap(),
4111-
);
4112-
let check_struct_ident = context.rust_ident(
4113-
[
4114-
"Check",
4115-
context.options().dynamic_library_name.as_ref().unwrap(),
4116-
]
4117-
.join(""),
4118-
);
4108+
if let Some(ref lib_name) = context.options().dynamic_library_name {
4109+
let lib_ident = context.rust_ident(lib_name);
4110+
let check_struct_ident =
4111+
context.rust_ident(format!("Check{}", lib_name));
41194112
let dynamic_items_tokens = result
41204113
.dynamic_items()
41214114
.get_tokens(lib_ident, check_struct_ident);

0 commit comments

Comments
 (0)