Skip to content

Commit

Permalink
Doc
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Delmas <[email protected]>
  • Loading branch information
tdelmas committed Nov 3, 2023
1 parent 34cfdb7 commit e1d1fae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion typed_floats_macros/src/add_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) fn generate_main_description(floats: &[FloatDefinition]) -> proc_macr
output
}

fn comment_line(str: &str) -> proc_macro2::TokenStream {
pub(crate) fn comment_line(str: &str) -> proc_macro2::TokenStream {
let comment: String = "/// ".to_owned() + str + "\n";
comment.parse().unwrap()
}
Expand Down
25 changes: 20 additions & 5 deletions typed_floats_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ pub fn generate_tests_self_rhs(_input: proc_macro::TokenStream) -> proc_macro::T
output.into()
}

fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
fn get_specifications() -> Vec<(&'static str,&'static str, FloatSpecifications)> {
vec![
(
"NonNaN",
"A non-NaN floating point number",
FloatSpecifications {
accept_inf: true,
accept_zero: true,
Expand All @@ -57,6 +58,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"NonZeroNonNaN",
"A non-NaN floating point number different from zero",
FloatSpecifications {
accept_inf: true,
accept_zero: false,
Expand All @@ -66,6 +68,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"NonNaNFinite",
"A non-NaN finite floating point number",
FloatSpecifications {
accept_inf: false,
accept_zero: true,
Expand All @@ -75,6 +78,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"NonZeroNonNaNFinite",
"A non-NaN finite floating point number different from zero",
FloatSpecifications {
accept_inf: false,
accept_zero: false,
Expand All @@ -84,6 +88,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"Positive",
"A non-NaN positive floating point number",
FloatSpecifications {
accept_inf: true,
accept_zero: true,
Expand All @@ -93,6 +98,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"Negative",
"A non-NaN negative floating point number",
FloatSpecifications {
accept_inf: true,
accept_zero: true,
Expand All @@ -102,6 +108,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"PositiveFinite",
"A non-NaN positive finite floating point number",
FloatSpecifications {
accept_inf: false,
accept_zero: true,
Expand All @@ -111,6 +118,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"NegativeFinite",
"A non-NaN negative finite floating point number",
FloatSpecifications {
accept_inf: false,
accept_zero: true,
Expand All @@ -120,6 +128,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"StrictlyPositive",
"A non-NaN strictly positive floating point number",
FloatSpecifications {
accept_inf: true,
accept_zero: false,
Expand All @@ -129,6 +138,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"StrictlyNegative",
"A non-NaN strictly negative floating point number",
FloatSpecifications {
accept_inf: true,
accept_zero: false,
Expand All @@ -138,6 +148,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"StrictlyPositiveFinite",
"A non-NaN strictly positive finite floating point number",
FloatSpecifications {
accept_inf: false,
accept_zero: false,
Expand All @@ -147,6 +158,7 @@ fn get_specifications() -> Vec<(&'static str, FloatSpecifications)> {
),
(
"StrictlyNegativeFinite",
"A non-NaN strictly negative finite floating point number",
FloatSpecifications {
accept_inf: false,
accept_zero: false,
Expand All @@ -165,7 +177,7 @@ fn get_definitions(float_type: &'static str) -> Vec<FloatDefinition> {
.map(|specification| FloatDefinition {
name: specification.0,
float_type,
s: specification.1.clone(),
s: specification.2.clone(),
})
.collect::<Vec<_>>()
}
Expand Down Expand Up @@ -199,15 +211,16 @@ pub fn generate_floats(_input: proc_macro::TokenStream) -> proc_macro::TokenStre
}

fn do_generate_generic_floats(
specifications: &[(&'static str, FloatSpecifications)],
specifications: &[(&'static str,&'static str, FloatSpecifications)],
default_float_type: &str,
) -> proc_macro2::TokenStream {
let mut output = proc_macro2::TokenStream::new();

let default_float_type = syn::Ident::new(default_float_type, proc_macro2::Span::call_site());

for (name, s) in specifications {
for (name, description, s) in specifications {
let name = syn::Ident::new(name, proc_macro2::Span::call_site());
let description = add_doc::comment_line(description);

let mut constraints = quote! {
/// - It is not NaN.
Expand Down Expand Up @@ -238,7 +251,9 @@ fn do_generate_generic_floats(
}

output.extend(quote! {
/// A floating point number that satisfies the following constraints:
#description
///
/// It satisfies the following constraints:
#constraints
#[derive(Debug, Copy, Clone)]
#[repr(transparent)]
Expand Down

0 comments on commit e1d1fae

Please sign in to comment.