@@ -29,7 +29,7 @@ use crate::utils::{
2929
3030#[ derive( Clone , Debug ) ]
3131enum ControlOperator {
32- Range ( ( Option < isize > , Option < isize > ) ) ,
32+ Range ( ( Option < i128 > , Option < i128 > ) ) ,
3333 CBOR ( RustType ) ,
3434}
3535
@@ -131,40 +131,40 @@ fn parse_control_operator(types: &mut IntermediateTypes, parent: &Type2AndParent
131131 Type2 :: IntValue { value, ..} => value,
132132 _ => unimplemented ! ( "unsupported type in range control operator: {:?}" , operator) ,
133133 } ;
134- ControlOperator :: Range ( ( Some ( range_start) , Some ( if is_inclusive { range_end } else { range_end + 1 } ) ) )
134+ ControlOperator :: Range ( ( Some ( range_start as i128 ) , Some ( if is_inclusive { range_end as i128 } else { ( range_end + 1 ) as i128 } ) ) )
135135 } ,
136136 RangeCtlOp :: CtlOp { ctrl, .. } => match ctrl {
137137 ".default" |
138138 ".cborseq" |
139139 ".within" |
140140 ".and" => todo ! ( "control operator {} not supported" , ctrl) ,
141141 ".cbor" => ControlOperator :: CBOR ( rust_type_from_type2 ( types, & Type2AndParent { type2 : & operator. type2 , parent : parent. parent , } ) ) ,
142- ".eq" => ControlOperator :: Range ( ( Some ( type2_to_number_literal ( & operator. type2 ) ) , Some ( type2_to_number_literal ( & operator. type2 ) ) ) ) ,
142+ ".eq" => ControlOperator :: Range ( ( Some ( type2_to_number_literal ( & operator. type2 ) as i128 ) , Some ( type2_to_number_literal ( & operator. type2 ) as i128 ) ) ) ,
143143 // TODO: this would be MUCH nicer (for error displaying, etc) to handle this in its own dedicated way
144144 // which might be necessary once we support other control operators anyway
145- ".ne" => ControlOperator :: Range ( ( Some ( type2_to_number_literal ( & operator. type2 ) + 1 ) , Some ( type2_to_number_literal ( & operator. type2 ) - 1 ) ) ) ,
146- ".le" => ControlOperator :: Range ( ( lower_bound, Some ( type2_to_number_literal ( & operator. type2 ) ) ) ) ,
147- ".lt" => ControlOperator :: Range ( ( lower_bound, Some ( type2_to_number_literal ( & operator. type2 ) - 1 ) ) ) ,
148- ".ge" => ControlOperator :: Range ( ( Some ( type2_to_number_literal ( & operator. type2 ) ) , None ) ) ,
149- ".gt" => ControlOperator :: Range ( ( Some ( type2_to_number_literal ( & operator. type2 ) + 1 ) , None ) ) ,
145+ ".ne" => ControlOperator :: Range ( ( Some ( ( type2_to_number_literal ( & operator. type2 ) + 1 ) as i128 ) , Some ( ( type2_to_number_literal ( & operator. type2 ) - 1 ) as i128 ) ) ) ,
146+ ".le" => ControlOperator :: Range ( ( lower_bound, Some ( type2_to_number_literal ( & operator. type2 ) as i128 ) ) ) ,
147+ ".lt" => ControlOperator :: Range ( ( lower_bound, Some ( ( type2_to_number_literal ( & operator. type2 ) - 1 ) as i128 ) ) ) ,
148+ ".ge" => ControlOperator :: Range ( ( Some ( type2_to_number_literal ( & operator. type2 ) as i128 ) , None ) ) ,
149+ ".gt" => ControlOperator :: Range ( ( Some ( ( type2_to_number_literal ( & operator. type2 ) + 1 ) as i128 ) , None ) ) ,
150150 ".size" => {
151151 let base_range = match & operator. type2 {
152- Type2 :: UintValue { value, .. } => ControlOperator :: Range ( ( None , Some ( * value as isize ) ) ) ,
153- Type2 :: IntValue { value, .. } => ControlOperator :: Range ( ( None , Some ( * value) ) ) ,
152+ Type2 :: UintValue { value, .. } => ControlOperator :: Range ( ( None , Some ( * value as i128 ) ) ) ,
153+ Type2 :: IntValue { value, .. } => ControlOperator :: Range ( ( None , Some ( * value as i128 ) ) ) ,
154154 Type2 :: ParenthesizedType { pt, .. } => {
155155 assert_eq ! ( pt. type_choices. len( ) , 1 ) ;
156156 let inner_type = & pt. type_choices . first ( ) . unwrap ( ) . type1 ;
157157 let min = match inner_type. type2 {
158- Type2 :: UintValue { value, .. } => Some ( value as isize ) ,
159- Type2 :: IntValue { value, .. } => Some ( value) ,
158+ Type2 :: UintValue { value, .. } => Some ( value as i128 ) ,
159+ Type2 :: IntValue { value, .. } => Some ( value as i128 ) ,
160160 _ => unimplemented ! ( "unsupported type in range control operator: {:?}" , operator) ,
161161 } ;
162162 let max = match & inner_type. operator {
163163 Some ( op) => match op. operator {
164164 RangeCtlOp :: RangeOp { is_inclusive, ..} => {
165165 let value = match op. type2 {
166- Type2 :: UintValue { value, .. } => value as isize ,
167- Type2 :: IntValue { value, ..} => value,
166+ Type2 :: UintValue { value, .. } => value as i128 ,
167+ Type2 :: IntValue { value, ..} => value as i128 ,
168168 _ => unimplemented ! ( "unsupported type in range control operator: {:?}" , operator) ,
169169 } ;
170170 Some ( if is_inclusive { value } else { value + 1 } )
@@ -181,16 +181,16 @@ fn parse_control_operator(types: &mut IntermediateTypes, parent: &Type2AndParent
181181 Type2 :: Typename { ident, .. } if ident. to_string ( ) == "uint" => {
182182 // .size 3 means 24 bits
183183 match & base_range {
184- ControlOperator :: Range ( ( Some ( l) , Some ( h) ) ) => ControlOperator :: Range ( ( Some ( isize :: pow ( 2 , 8 * * l as u32 ) ) , Some ( isize :: pow ( 2 , 8 * * h as u32 ) - 1 ) ) ) ,
185- ControlOperator :: Range ( ( None , Some ( h) ) ) => ControlOperator :: Range ( ( Some ( 0 ) , Some ( isize :: pow ( 2 , 8 * * h as u32 ) - 1 ) ) ) ,
184+ ControlOperator :: Range ( ( Some ( l) , Some ( h) ) ) => ControlOperator :: Range ( ( Some ( i128 :: pow ( 2 , 8 * * l as u32 ) ) , Some ( i128 :: pow ( 2 , 8 * * h as u32 ) - 1 ) ) ) ,
185+ ControlOperator :: Range ( ( None , Some ( h) ) ) => ControlOperator :: Range ( ( Some ( 0 ) , Some ( i128 :: pow ( 2 , 8 * * h as u32 ) - 1 ) ) ) ,
186186 _ => panic ! ( "unexpected partial range in size control operator: {:?}" , operator)
187187 }
188188 } ,
189189 Type2 :: Typename { ident, .. } if ident. to_string ( ) == "int" => {
190190 match & base_range {
191191 // this is complex to support since it requires two disjoint ranges of possible values
192192 ControlOperator :: Range ( ( Some ( _) , Some ( _) ) ) => panic ! ( ".size range unsupported for signed int type: {:?}" , operator) ,
193- ControlOperator :: Range ( ( None , Some ( h) ) ) => ControlOperator :: Range ( ( Some ( -isize :: pow ( 2 , 8 * ( * h - 1 ) as u32 ) ) , Some ( isize :: pow ( 2 , ( 8 * ( * h - 1 ) ) as u32 ) - 1 ) ) ) ,
193+ ControlOperator :: Range ( ( None , Some ( h) ) ) => ControlOperator :: Range ( ( Some ( -i128 :: pow ( 2 , ( ( 8 * * h ) - 1 ) as u32 ) ) , Some ( i128 :: pow ( 2 , ( ( 8 * * h ) - 1 ) as u32 ) - 1 ) ) ) ,
194194 _ => panic ! ( "unexpected partial range in size control operator: {:?}" , operator)
195195 }
196196 }
@@ -208,16 +208,16 @@ fn parse_control_operator(types: &mut IntermediateTypes, parent: &Type2AndParent
208208 }
209209}
210210
211- fn range_to_primitive ( low : Option < isize > , high : Option < isize > ) -> Option < RustType > {
211+ fn range_to_primitive ( low : Option < i128 > , high : Option < i128 > ) -> Option < RustType > {
212212 match ( low, high) {
213- ( Some ( l) , Some ( h) ) if l == u8:: MIN as isize && h == u8:: MAX as isize => Some ( RustType :: Primitive ( Primitive :: U8 ) ) ,
214- ( Some ( l) , Some ( h) ) if l == i8:: MIN as isize && h == i8:: MAX as isize => Some ( RustType :: Primitive ( Primitive :: I8 ) ) ,
215- ( Some ( l) , Some ( h) ) if l == u16:: MIN as isize && h == u16:: MAX as isize => Some ( RustType :: Primitive ( Primitive :: U16 ) ) ,
216- ( Some ( l) , Some ( h) ) if l == i16:: MIN as isize && h == i16:: MAX as isize => Some ( RustType :: Primitive ( Primitive :: I16 ) ) ,
217- ( Some ( l) , Some ( h) ) if l == u32:: MIN as isize && h == u32:: MAX as isize => Some ( RustType :: Primitive ( Primitive :: U32 ) ) ,
218- ( Some ( l) , Some ( h) ) if l == i32:: MIN as isize && h == i32:: MAX as isize => Some ( RustType :: Primitive ( Primitive :: I32 ) ) ,
219- ( Some ( l) , Some ( h) ) if l == u64:: MIN as isize && h == u64:: MAX as isize => Some ( RustType :: Primitive ( Primitive :: U64 ) ) ,
220- ( Some ( l) , Some ( h) ) if l == i64:: MIN as isize && h == i64:: MAX as isize => Some ( RustType :: Primitive ( Primitive :: I64 ) ) ,
213+ ( Some ( l) , Some ( h) ) if l == u8:: MIN as i128 && h == u8:: MAX as i128 => Some ( RustType :: Primitive ( Primitive :: U8 ) ) ,
214+ ( Some ( l) , Some ( h) ) if l == i8:: MIN as i128 && h == i8:: MAX as i128 => Some ( RustType :: Primitive ( Primitive :: I8 ) ) ,
215+ ( Some ( l) , Some ( h) ) if l == u16:: MIN as i128 && h == u16:: MAX as i128 => Some ( RustType :: Primitive ( Primitive :: U16 ) ) ,
216+ ( Some ( l) , Some ( h) ) if l == i16:: MIN as i128 && h == i16:: MAX as i128 => Some ( RustType :: Primitive ( Primitive :: I16 ) ) ,
217+ ( Some ( l) , Some ( h) ) if l == u32:: MIN as i128 && h == u32:: MAX as i128 => Some ( RustType :: Primitive ( Primitive :: U32 ) ) ,
218+ ( Some ( l) , Some ( h) ) if l == i32:: MIN as i128 && h == i32:: MAX as i128 => Some ( RustType :: Primitive ( Primitive :: I32 ) ) ,
219+ ( Some ( l) , Some ( h) ) if l == u64:: MIN as i128 && h == u64:: MAX as i128 => Some ( RustType :: Primitive ( Primitive :: U64 ) ) ,
220+ ( Some ( l) , Some ( h) ) if l == i64:: MIN as i128 && h == i64:: MAX as i128 => Some ( RustType :: Primitive ( Primitive :: I64 ) ) ,
221221 _ => None
222222 }
223223}
0 commit comments