Skip to content

Commit

Permalink
codegen: Minor nits for dynamic function generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Nov 25, 2020
1 parent c2b5c46 commit 7792d63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
15 changes: 2 additions & 13 deletions src/codegen/dyngen.rs
Expand Up @@ -2,6 +2,7 @@ use crate::ir::function::Abi;
use proc_macro2::Ident;

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

impl Default for DynamicItems {
fn default() -> Self {
DynamicItems {
struct_members: vec![],
struct_implementation: vec![],
runtime_checks: vec![],
constructor_inits: vec![],
init_fields: vec![],
}
}
}

impl DynamicItems {
pub fn new() -> Self {
Self::default()
Expand Down Expand Up @@ -141,7 +130,7 @@ impl DynamicItems {
}
}

pub fn add_function(
pub fn push(
&mut self,
ident: Ident,
abi: Abi,
Expand Down
17 changes: 5 additions & 12 deletions src/codegen/mod.rs
Expand Up @@ -3805,7 +3805,7 @@ impl CodeGenerator for Function {
TypeKind::Void => quote! {()},
_ => return_item.to_rust_ty_or_opaque(ctx, &()),
};
result.dynamic_items().add_function(
result.dynamic_items().push(
ident,
abi,
args,
Expand Down Expand Up @@ -4105,17 +4105,10 @@ pub(crate) fn codegen(
&(),
);

if context.options().dynamic_library_name.is_some() {
let lib_ident = context.rust_ident(
context.options().dynamic_library_name.as_ref().unwrap(),
);
let check_struct_ident = context.rust_ident(
[
"Check",
context.options().dynamic_library_name.as_ref().unwrap(),
]
.join(""),
);
if let Some(ref lib_name) = context.options().dynamic_library_name {
let lib_ident = context.rust_ident(lib_name);
let check_struct_ident =
context.rust_ident(format!("Check{}", lib_name));
let dynamic_items_tokens = result
.dynamic_items()
.get_tokens(lib_ident, check_struct_ident);
Expand Down

0 comments on commit 7792d63

Please sign in to comment.