6
6
use std:: fmt;
7
7
8
8
use hir_expand:: name:: { name, AsName , Name } ;
9
-
10
- #[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
11
- pub enum Signedness {
12
- Signed ,
13
- Unsigned ,
14
- }
15
-
16
- #[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
17
- pub enum IntBitness {
18
- Xsize ,
19
- X8 ,
20
- X16 ,
21
- X32 ,
22
- X64 ,
23
- X128 ,
24
- }
25
-
26
- #[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
27
- pub enum FloatBitness {
28
- X32 ,
29
- X64 ,
9
+ /// Different signed int types.
10
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
11
+ pub enum BuiltinInt {
12
+ Isize ,
13
+ I8 ,
14
+ I16 ,
15
+ I32 ,
16
+ I64 ,
17
+ I128 ,
30
18
}
31
19
32
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
33
- pub struct BuiltinInt {
34
- pub signedness : Signedness ,
35
- pub bitness : IntBitness ,
20
+ /// Different unsigned int types.
21
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
22
+ pub enum BuiltinUint {
23
+ Usize ,
24
+ U8 ,
25
+ U16 ,
26
+ U32 ,
27
+ U64 ,
28
+ U128 ,
36
29
}
37
30
38
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
39
- pub struct BuiltinFloat {
40
- pub bitness : FloatBitness ,
31
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
32
+ pub enum BuiltinFloat {
33
+ F32 ,
34
+ F64 ,
41
35
}
42
36
43
37
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
@@ -46,6 +40,7 @@ pub enum BuiltinType {
46
40
Bool ,
47
41
Str ,
48
42
Int ( BuiltinInt ) ,
43
+ Uint ( BuiltinUint ) ,
49
44
Float ( BuiltinFloat ) ,
50
45
}
51
46
@@ -56,19 +51,19 @@ impl BuiltinType {
56
51
( name ! [ bool ] , BuiltinType :: Bool ) ,
57
52
( name ! [ str ] , BuiltinType :: Str ) ,
58
53
59
- ( name ! [ isize ] , BuiltinType :: Int ( BuiltinInt :: ISIZE ) ) ,
54
+ ( name ! [ isize ] , BuiltinType :: Int ( BuiltinInt :: Isize ) ) ,
60
55
( name ! [ i8 ] , BuiltinType :: Int ( BuiltinInt :: I8 ) ) ,
61
56
( name ! [ i16 ] , BuiltinType :: Int ( BuiltinInt :: I16 ) ) ,
62
57
( name ! [ i32 ] , BuiltinType :: Int ( BuiltinInt :: I32 ) ) ,
63
58
( name ! [ i64 ] , BuiltinType :: Int ( BuiltinInt :: I64 ) ) ,
64
59
( name ! [ i128 ] , BuiltinType :: Int ( BuiltinInt :: I128 ) ) ,
65
60
66
- ( name ! [ usize ] , BuiltinType :: Int ( BuiltinInt :: USIZE ) ) ,
67
- ( name ! [ u8 ] , BuiltinType :: Int ( BuiltinInt :: U8 ) ) ,
68
- ( name ! [ u16 ] , BuiltinType :: Int ( BuiltinInt :: U16 ) ) ,
69
- ( name ! [ u32 ] , BuiltinType :: Int ( BuiltinInt :: U32 ) ) ,
70
- ( name ! [ u64 ] , BuiltinType :: Int ( BuiltinInt :: U64 ) ) ,
71
- ( name ! [ u128 ] , BuiltinType :: Int ( BuiltinInt :: U128 ) ) ,
61
+ ( name ! [ usize ] , BuiltinType :: Uint ( BuiltinUint :: Usize ) ) ,
62
+ ( name ! [ u8 ] , BuiltinType :: Uint ( BuiltinUint :: U8 ) ) ,
63
+ ( name ! [ u16 ] , BuiltinType :: Uint ( BuiltinUint :: U16 ) ) ,
64
+ ( name ! [ u32 ] , BuiltinType :: Uint ( BuiltinUint :: U32 ) ) ,
65
+ ( name ! [ u64 ] , BuiltinType :: Uint ( BuiltinUint :: U64 ) ) ,
66
+ ( name ! [ u128 ] , BuiltinType :: Uint ( BuiltinUint :: U128 ) ) ,
72
67
73
68
( name ! [ f32 ] , BuiltinType :: Float ( BuiltinFloat :: F32 ) ) ,
74
69
( name ! [ f64 ] , BuiltinType :: Float ( BuiltinFloat :: F64 ) ) ,
@@ -81,24 +76,25 @@ impl AsName for BuiltinType {
81
76
BuiltinType :: Char => name ! [ char ] ,
82
77
BuiltinType :: Bool => name ! [ bool ] ,
83
78
BuiltinType :: Str => name ! [ str ] ,
84
- BuiltinType :: Int ( BuiltinInt { signedness, bitness } ) => match ( signedness, bitness) {
85
- ( Signedness :: Signed , IntBitness :: Xsize ) => name ! [ isize ] ,
86
- ( Signedness :: Signed , IntBitness :: X8 ) => name ! [ i8 ] ,
87
- ( Signedness :: Signed , IntBitness :: X16 ) => name ! [ i16 ] ,
88
- ( Signedness :: Signed , IntBitness :: X32 ) => name ! [ i32 ] ,
89
- ( Signedness :: Signed , IntBitness :: X64 ) => name ! [ i64 ] ,
90
- ( Signedness :: Signed , IntBitness :: X128 ) => name ! [ i128 ] ,
91
-
92
- ( Signedness :: Unsigned , IntBitness :: Xsize ) => name ! [ usize ] ,
93
- ( Signedness :: Unsigned , IntBitness :: X8 ) => name ! [ u8 ] ,
94
- ( Signedness :: Unsigned , IntBitness :: X16 ) => name ! [ u16 ] ,
95
- ( Signedness :: Unsigned , IntBitness :: X32 ) => name ! [ u32 ] ,
96
- ( Signedness :: Unsigned , IntBitness :: X64 ) => name ! [ u64 ] ,
97
- ( Signedness :: Unsigned , IntBitness :: X128 ) => name ! [ u128 ] ,
79
+ BuiltinType :: Int ( it) => match it {
80
+ BuiltinInt :: Isize => name ! [ isize ] ,
81
+ BuiltinInt :: I8 => name ! [ i8 ] ,
82
+ BuiltinInt :: I16 => name ! [ i16 ] ,
83
+ BuiltinInt :: I32 => name ! [ i32 ] ,
84
+ BuiltinInt :: I64 => name ! [ i64 ] ,
85
+ BuiltinInt :: I128 => name ! [ i128 ] ,
86
+ } ,
87
+ BuiltinType :: Uint ( it) => match it {
88
+ BuiltinUint :: Usize => name ! [ usize ] ,
89
+ BuiltinUint :: U8 => name ! [ u8 ] ,
90
+ BuiltinUint :: U16 => name ! [ u16 ] ,
91
+ BuiltinUint :: U32 => name ! [ u32 ] ,
92
+ BuiltinUint :: U64 => name ! [ u64 ] ,
93
+ BuiltinUint :: U128 => name ! [ u128 ] ,
98
94
} ,
99
- BuiltinType :: Float ( BuiltinFloat { bitness } ) => match bitness {
100
- FloatBitness :: X32 => name ! [ f32 ] ,
101
- FloatBitness :: X64 => name ! [ f64 ] ,
95
+ BuiltinType :: Float ( it ) => match it {
96
+ BuiltinFloat :: F32 => name ! [ f32 ] ,
97
+ BuiltinFloat :: F64 => name ! [ f64 ] ,
102
98
} ,
103
99
}
104
100
}
@@ -113,31 +109,26 @@ impl fmt::Display for BuiltinType {
113
109
114
110
#[ rustfmt:: skip]
115
111
impl BuiltinInt {
116
- pub const ISIZE : BuiltinInt = BuiltinInt { signedness : Signedness :: Signed , bitness : IntBitness :: Xsize } ;
117
- pub const I8 : BuiltinInt = BuiltinInt { signedness : Signedness :: Signed , bitness : IntBitness :: X8 } ;
118
- pub const I16 : BuiltinInt = BuiltinInt { signedness : Signedness :: Signed , bitness : IntBitness :: X16 } ;
119
- pub const I32 : BuiltinInt = BuiltinInt { signedness : Signedness :: Signed , bitness : IntBitness :: X32 } ;
120
- pub const I64 : BuiltinInt = BuiltinInt { signedness : Signedness :: Signed , bitness : IntBitness :: X64 } ;
121
- pub const I128 : BuiltinInt = BuiltinInt { signedness : Signedness :: Signed , bitness : IntBitness :: X128 } ;
122
-
123
- pub const USIZE : BuiltinInt = BuiltinInt { signedness : Signedness :: Unsigned , bitness : IntBitness :: Xsize } ;
124
- pub const U8 : BuiltinInt = BuiltinInt { signedness : Signedness :: Unsigned , bitness : IntBitness :: X8 } ;
125
- pub const U16 : BuiltinInt = BuiltinInt { signedness : Signedness :: Unsigned , bitness : IntBitness :: X16 } ;
126
- pub const U32 : BuiltinInt = BuiltinInt { signedness : Signedness :: Unsigned , bitness : IntBitness :: X32 } ;
127
- pub const U64 : BuiltinInt = BuiltinInt { signedness : Signedness :: Unsigned , bitness : IntBitness :: X64 } ;
128
- pub const U128 : BuiltinInt = BuiltinInt { signedness : Signedness :: Unsigned , bitness : IntBitness :: X128 } ;
129
-
130
-
131
112
pub fn from_suffix ( suffix : & str ) -> Option < BuiltinInt > {
132
113
let res = match suffix {
133
- "isize" => Self :: ISIZE ,
114
+ "isize" => Self :: Isize ,
134
115
"i8" => Self :: I8 ,
135
116
"i16" => Self :: I16 ,
136
117
"i32" => Self :: I32 ,
137
118
"i64" => Self :: I64 ,
138
119
"i128" => Self :: I128 ,
139
120
140
- "usize" => Self :: USIZE ,
121
+ _ => return None ,
122
+ } ;
123
+ Some ( res)
124
+ }
125
+ }
126
+
127
+ #[ rustfmt:: skip]
128
+ impl BuiltinUint {
129
+ pub fn from_suffix ( suffix : & str ) -> Option < BuiltinUint > {
130
+ let res = match suffix {
131
+ "usize" => Self :: Usize ,
141
132
"u8" => Self :: U8 ,
142
133
"u16" => Self :: U16 ,
143
134
"u32" => Self :: U32 ,
@@ -152,9 +143,6 @@ impl BuiltinInt {
152
143
153
144
#[ rustfmt:: skip]
154
145
impl BuiltinFloat {
155
- pub const F32 : BuiltinFloat = BuiltinFloat { bitness : FloatBitness :: X32 } ;
156
- pub const F64 : BuiltinFloat = BuiltinFloat { bitness : FloatBitness :: X64 } ;
157
-
158
146
pub fn from_suffix ( suffix : & str ) -> Option < BuiltinFloat > {
159
147
let res = match suffix {
160
148
"f32" => BuiltinFloat :: F32 ,
0 commit comments