1+ //! Module to parse hexadecimal-represented number constants
2+
13#![ allow( clippy:: arbitrary_source_item_ordering) ]
24
35use super :: super :: macros:: parse_int_from_radix;
@@ -7,13 +9,14 @@ use super::super::types::arch_types::*;
79use super :: super :: types:: { ERR_PREFIX , Number , NumberType } ;
810use crate :: errors:: api:: { CompileError , Location } ;
911
12+ /// Implements the [`FloatingPoint`] for the floating-point types.
1013macro_rules! impl_floating_point {
11- ( $x: expr, $( $ftype : ident) * ) => {
14+ ( $x: expr, $( $type : ident) * ) => {
1215 $( #[ expect( clippy:: as_conversions, clippy:: cast_precision_loss) ]
13- impl FloatingPoint <concat_idents!( $ftype , IntPart ) > for $ftype {
16+ impl FloatingPoint <concat_idents!( $type , IntPart ) > for $type {
1417 const MANTISSA_SIZE : u32 = $x;
1518
16- type Unsigned = concat_idents!( $ftype , IntPart ) ;
19+ type Unsigned = concat_idents!( $type , IntPart ) ;
1720
1821
1922 fn from_unsigned(
@@ -39,6 +42,7 @@ macro_rules! impl_floating_point {
3942 } ;
4043}
4144
45+ /// Parses the stringified version of a number into a [`HexFloatData`].
4246macro_rules! parse_hexadecimal_float {
4347 ( $overflow: expr, $nb_type: ident, $float_parse: ident, $( $t: ident) * ) => { {
4448 match $nb_type {
@@ -71,9 +75,17 @@ impl_floating_point!(23, Double Float LongDouble);
7175///
7276/// ``overflow`` is set to true if the value doesn't fix in the mantissa.
7377trait FloatingPoint < T > {
78+ /// Size of the mantissa
79+ ///
80+ /// In the binary representation of the floating-point
81+ /// values, there is one part for the exponent, and one point for the
82+ /// digits, the latter is called 'mantissa'.
7483 const MANTISSA_SIZE : u32 ;
84+ /// The biggest unsigned integer type that can contain the mantissa.
7585 type Unsigned ;
86+ /// Convert the integer-parsed value into the current floating-point type.
7687 fn from_unsigned ( val : T , overflow : & mut bool ) -> Self ;
88+ /// Convert the usize-parsed value into the current floating-point type.
7789 fn from_usize ( val : usize , overflow : & mut bool ) -> Self ;
7890}
7991
@@ -100,6 +112,7 @@ struct HexFloatData {
100112}
101113
102114impl HexFloatData {
115+ /// Pushes a character to the current state.
103116 fn push ( & mut self , ch : char ) {
104117 match self . state {
105118 HexFloatParseState :: Int => self . int_part . push ( ch) ,
@@ -108,6 +121,7 @@ impl HexFloatData {
108121 }
109122 }
110123
124+ /// Returns the exponent of the number constant.
111125 fn get_exp ( & self ) -> u32 {
112126 if self . exponent . is_empty ( ) {
113127 0
@@ -125,8 +139,18 @@ impl HexFloatData {
125139/// and a exponent part after an exponent character ('p').
126140#[ derive( Default , PartialEq , Eq , Debug ) ]
127141enum HexFloatParseState {
142+ /// Decimal part
143+ ///
144+ /// The part between the full stop and the exponent character 'p' (if they
145+ /// exist).
128146 Decimal ,
147+ /// Exponent part
148+ ///
149+ /// Last part of the string, after the 'p' character.
129150 Exponent ,
151+ /// Integer part
152+ ///
153+ /// First part of the string, before the full stop and the 'p' character.
130154 #[ default]
131155 Int ,
132156}
0 commit comments