Skip to content

Commit

Permalink
rename codegen methods consistently, make some public methods private
Browse files Browse the repository at this point in the history
  • Loading branch information
Tehforsch committed Jan 12, 2024
1 parent 85b9ded commit 60d0c0b
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 54 deletions.
2 changes: 1 addition & 1 deletion crates/diman_unit_system/src/codegen/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Defs {
quote! { [ #units ] }
}

pub fn debug_trait(&self) -> TokenStream {
pub fn gen_debug_trait_impl(&self) -> TokenStream {
let Defs {
quantity_type,
dimension_type,
Expand Down
4 changes: 2 additions & 2 deletions crates/diman_unit_system/src/codegen/dimension_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use quote::quote;
use crate::types::Defs;

impl Defs {
pub(crate) fn dimension_impl(&self) -> TokenStream {
pub(crate) fn gen_dimension(&self) -> TokenStream {
let name = &self.dimension_type;

let dim_type = self.base_dimension_type();
Expand All @@ -29,7 +29,7 @@ impl Defs {
}
}

pub(crate) fn dimension_methods_impl(&self) -> TokenStream {
fn dimension_methods_impl(&self) -> TokenStream {
let type_name = &self.dimension_type;
let none_gen: proc_macro2::TokenStream = self
.base_dimensions()
Expand Down
2 changes: 1 addition & 1 deletion crates/diman_unit_system/src/codegen/float_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Defs {
])
}

pub fn float_methods(&self) -> TokenStream {
pub fn gen_float_methods(&self) -> TokenStream {
join([
self.ensure_float_traits(),
#[cfg(any(feature = "std", feature = "num-traits-libm"))]
Expand Down
12 changes: 6 additions & 6 deletions crates/diman_unit_system/src/codegen/generic_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ use syn::Type;
use crate::types::Defs;

impl Defs {
pub fn gen_generic_methods(&self) -> TokenStream {
self.storage_type_names()
.map(|name| self.impl_method_for_generic_storage_type(&name, &quote! { abs }))
.collect()
}

fn impl_method_for_generic_storage_type(
&self,
storage_type: &Type,
Expand All @@ -23,10 +29,4 @@ impl Defs {
}
}
}

pub fn generic_methods(&self) -> TokenStream {
self.storage_type_names()
.map(|name| self.impl_method_for_generic_storage_type(&name, &quote! { abs }))
.collect()
}
}
10 changes: 5 additions & 5 deletions crates/diman_unit_system/src/codegen/hdf5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ use crate::{
use super::join;

impl Defs {
pub fn hdf5_impl(&self) -> TokenStream {
pub fn gen_hdf5_impl(&self) -> TokenStream {
join([self.hdf5_floats_impl(), self.hdf5_vectors_impl()])
}

pub fn hdf5_floats_impl(&self) -> TokenStream {
fn hdf5_floats_impl(&self) -> TokenStream {
self.float_types()
.iter()
.map(|float_type| self.hdf5_float_impl(float_type))
.collect()
}

pub fn hdf5_float_impl(&self, float_type: &FloatType) -> TokenStream {
fn hdf5_float_impl(&self, float_type: &FloatType) -> TokenStream {
let float_type_name = &float_type.name;
let hdf5_type = &float_type.hdf5_type;
let Defs {
Expand All @@ -37,14 +37,14 @@ impl Defs {
}
}

pub fn hdf5_vectors_impl(&self) -> TokenStream {
fn hdf5_vectors_impl(&self) -> TokenStream {
self.vector_types()
.iter()
.map(|vector_type| self.hdf5_vector_impl(vector_type))
.collect()
}

pub fn hdf5_vector_impl(&self, vector_type: &VectorType) -> TokenStream {
fn hdf5_vector_impl(&self, vector_type: &VectorType) -> TokenStream {
let vector_type_name = &vector_type.name;
let hdf5_type = &vector_type.float_type.hdf5_type;
let num_dims = vector_type.num_dims;
Expand Down
27 changes: 13 additions & 14 deletions crates/diman_unit_system/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,23 @@ fn join<const D: usize>(streams: [TokenStream; D]) -> TokenStream {
impl Defs {
pub fn code_gen(&self) -> TokenStream {
join([
self.dimension_impl(),
self.quantity_definition(),
self.quantity_functions(),
self.definitions_for_storage_types(),
self.unit_constructors(),
self.impl_numeric_traits(),
self.debug_trait(),
self.float_methods(),
self.vector_methods(),
self.generic_methods(),
self.gen_dimension(),
self.gen_quantity(),
self.gen_definitions_for_storage_types(),
self.gen_unit_constructors(),
self.gen_numeric_trait_impls(),
self.gen_debug_trait_impl(),
self.gen_float_methods(),
self.gen_vector_methods(),
self.gen_generic_methods(),
#[cfg(feature = "serde")]
self.serde_impl(),
self.gen_serde_impl(),
#[cfg(feature = "hdf5")]
self.hdf5_impl(),
self.gen_hdf5_impl(),
#[cfg(feature = "mpi")]
self.mpi_impl(),
self.gen_mpi_impl(),
#[cfg(feature = "rand")]
self.rand_impl(),
self.gen_rand_impl(),
])
}
}
10 changes: 5 additions & 5 deletions crates/diman_unit_system/src/codegen/mpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ use crate::{
use super::join;

impl Defs {
pub fn mpi_impl(&self) -> TokenStream {
pub fn gen_mpi_impl(&self) -> TokenStream {
join([self.mpi_floats_impl(), self.mpi_vectors_impl()])
}

pub fn mpi_floats_impl(&self) -> TokenStream {
fn mpi_floats_impl(&self) -> TokenStream {
self.float_types()
.iter()
.map(|float_type| self.mpi_float_impl(float_type))
.collect()
}

pub fn mpi_float_impl(&self, float_type: &FloatType) -> TokenStream {
fn mpi_float_impl(&self, float_type: &FloatType) -> TokenStream {
let float_type_name = &float_type.name;
let mpi_type = &float_type.mpi_type;
let Defs {
Expand All @@ -41,14 +41,14 @@ impl Defs {
}
}

pub fn mpi_vectors_impl(&self) -> TokenStream {
fn mpi_vectors_impl(&self) -> TokenStream {
self.vector_types()
.iter()
.map(|vector_type| self.mpi_vector_impl(vector_type))
.collect()
}

pub fn mpi_vector_impl(&self, vector_type: &VectorType) -> TokenStream {
fn mpi_vector_impl(&self, vector_type: &VectorType) -> TokenStream {
let vector_type_name = &vector_type.name;
let float_type = &vector_type.float_type.name;
let num_dims = vector_type.num_dims as i32;
Expand Down
2 changes: 1 addition & 1 deletion crates/diman_unit_system/src/codegen/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use proc_macro2::TokenStream;
use crate::{storage_types::FloatType, types::Defs};

impl Defs {
pub fn rand_impl(&self) -> TokenStream {
pub fn gen_rand_impl(&self) -> TokenStream {
let float_impls: TokenStream = self
.float_types()
.iter()
Expand Down
12 changes: 6 additions & 6 deletions crates/diman_unit_system/src/codegen/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use crate::{
use super::join;

impl Defs {
pub fn serde_impl(&self) -> TokenStream {
pub fn gen_serde_impl(&self) -> TokenStream {
join([
self.serde_helpers_impl(),
self.serde_floats_impl(),
self.serde_vectors_impl(),
])
}

pub fn serde_helpers_impl(&self) -> TokenStream {
fn serde_helpers_impl(&self) -> TokenStream {
let Defs {
dimension_type,
quantity_type,
Expand Down Expand Up @@ -92,14 +92,14 @@ impl Defs {
}
}

pub fn serde_floats_impl(&self) -> TokenStream {
fn serde_floats_impl(&self) -> TokenStream {
self.float_types()
.iter()
.map(|float_type| self.serde_float_impl(float_type))
.collect()
}

pub fn serde_float_impl(&self, float_type: &FloatType) -> TokenStream {
fn serde_float_impl(&self, float_type: &FloatType) -> TokenStream {
let Defs {
dimension_type,
quantity_type,
Expand Down Expand Up @@ -215,14 +215,14 @@ impl Defs {
}
}

pub fn serde_vectors_impl(&self) -> TokenStream {
fn serde_vectors_impl(&self) -> TokenStream {
self.vector_types()
.iter()
.map(|vector_type| self.serde_vector_impl(vector_type))
.collect()
}

pub fn serde_vector_impl(&self, vector_type: &VectorType) -> TokenStream {
fn serde_vector_impl(&self, vector_type: &VectorType) -> TokenStream {
let float_type = &vector_type.float_type.name;
let num_dims = vector_type.num_dims;
let vector_type = &vector_type.name;
Expand Down
2 changes: 1 addition & 1 deletion crates/diman_unit_system/src/codegen/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ impl Defs {
}
}

pub fn impl_numeric_traits(&self) -> TokenStream {
pub fn gen_numeric_trait_impls(&self) -> TokenStream {
let ops: TokenStream = self
.iter_numeric_traits()
.map(|num_trait| self.generic_numeric_trait_impl(num_trait))
Expand Down
20 changes: 11 additions & 9 deletions crates/diman_unit_system/src/codegen/type_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ use proc_macro2::TokenStream;
use quote::{quote, quote_spanned};

impl Defs {
pub(crate) fn quantity_definition(&self) -> TokenStream {
pub(crate) fn gen_quantity(&self) -> TokenStream {
let Self {
quantity_type,
dimension_type,
..
} = &self;
let span = quantity_type.span();
let functions = self.quantity_functions();
quote_spanned! {span =>
#[derive(Clone, Copy, Eq, Default)]
#[repr(transparent)]
pub struct #quantity_type<S, const D: #dimension_type>(pub(crate) S);
#[derive(Clone, Copy, Eq, Default)]
#[repr(transparent)]
pub struct #quantity_type<S, const D: #dimension_type>(pub(crate) S);
#functions
}
}

pub(crate) fn quantity_functions(&self) -> TokenStream {
fn quantity_functions(&self) -> TokenStream {
let Self {
quantity_type,
dimension_type,
Expand Down Expand Up @@ -83,7 +85,7 @@ impl Defs {
}
}

pub fn definitions_for_storage_types(&self) -> TokenStream {
pub(crate) fn gen_definitions_for_storage_types(&self) -> TokenStream {
self.storage_types()
.map(|type_| {
self.definitions_for_storage_type(
Expand All @@ -105,7 +107,7 @@ impl Defs {
quote! {}
}

pub fn definitions_for_storage_type(
fn definitions_for_storage_type(
&self,
type_: &dyn StorageType,
module_name: &TokenStream,
Expand Down Expand Up @@ -134,7 +136,7 @@ impl Defs {
}
}

pub fn quantity_definitions_for_storage_type(&self, type_: &dyn StorageType) -> TokenStream {
fn quantity_definitions_for_storage_type(&self, type_: &dyn StorageType) -> TokenStream {
self.dimensions
.iter()
.map(|quantity| {
Expand All @@ -150,7 +152,7 @@ impl Defs {
.collect()
}

pub fn constant_definitions_for_storage_type(&self, type_: &dyn StorageType) -> TokenStream {
fn constant_definitions_for_storage_type(&self, type_: &dyn StorageType) -> TokenStream {
self
.constants
.iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/diman_unit_system/src/codegen/unit_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};

impl Defs {
pub fn unit_constructors(&self) -> TokenStream {
pub fn gen_unit_constructors(&self) -> TokenStream {
self.units
.iter()
.map(|unit| {
Expand Down
4 changes: 2 additions & 2 deletions crates/diman_unit_system/src/codegen/vector_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use quote::quote;
use crate::{storage_types::VectorType, types::Defs};

impl Defs {
pub fn vector_methods(&self) -> TokenStream {
pub fn gen_vector_methods(&self) -> TokenStream {
self.vector_types()
.iter()
.map(|vector_type| self.impl_vector_methods(vector_type))
.collect()
}

pub fn impl_vector_methods(&self, vector_type: &VectorType) -> TokenStream {
fn impl_vector_methods(&self, vector_type: &VectorType) -> TokenStream {
let Defs {
dimension_type,
quantity_type,
Expand Down

0 comments on commit 60d0c0b

Please sign in to comment.