diff options
Diffstat (limited to 'crates/ra_hir_def/src/builtin_type.rs')
-rw-r--r-- | crates/ra_hir_def/src/builtin_type.rs | 86 |
1 files changed, 70 insertions, 16 deletions
diff --git a/crates/ra_hir_def/src/builtin_type.rs b/crates/ra_hir_def/src/builtin_type.rs index 996e86fd9..5e8157144 100644 --- a/crates/ra_hir_def/src/builtin_type.rs +++ b/crates/ra_hir_def/src/builtin_type.rs | |||
@@ -56,22 +56,22 @@ impl BuiltinType { | |||
56 | (name::BOOL, BuiltinType::Bool), | 56 | (name::BOOL, BuiltinType::Bool), |
57 | (name::STR, BuiltinType::Str ), | 57 | (name::STR, BuiltinType::Str ), |
58 | 58 | ||
59 | (name::ISIZE, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::Xsize })), | 59 | (name::ISIZE, BuiltinType::Int(BuiltinInt::ISIZE)), |
60 | (name::I8, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X8 })), | 60 | (name::I8, BuiltinType::Int(BuiltinInt::I8)), |
61 | (name::I16, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X16 })), | 61 | (name::I16, BuiltinType::Int(BuiltinInt::I16)), |
62 | (name::I32, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X32 })), | 62 | (name::I32, BuiltinType::Int(BuiltinInt::I32)), |
63 | (name::I64, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X64 })), | 63 | (name::I64, BuiltinType::Int(BuiltinInt::I64)), |
64 | (name::I128, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X128 })), | 64 | (name::I128, BuiltinType::Int(BuiltinInt::I128)), |
65 | 65 | ||
66 | (name::USIZE, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })), | 66 | (name::USIZE, BuiltinType::Int(BuiltinInt::USIZE)), |
67 | (name::U8, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })), | 67 | (name::U8, BuiltinType::Int(BuiltinInt::U8)), |
68 | (name::U16, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })), | 68 | (name::U16, BuiltinType::Int(BuiltinInt::U16)), |
69 | (name::U32, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })), | 69 | (name::U32, BuiltinType::Int(BuiltinInt::U32)), |
70 | (name::U64, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })), | 70 | (name::U64, BuiltinType::Int(BuiltinInt::U64)), |
71 | (name::U128, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })), | 71 | (name::U128, BuiltinType::Int(BuiltinInt::U128)), |
72 | 72 | ||
73 | (name::F32, BuiltinType::Float(BuiltinFloat { bitness: FloatBitness::X32 })), | 73 | (name::F32, BuiltinType::Float(BuiltinFloat::F32)), |
74 | (name::F64, BuiltinType::Float(BuiltinFloat { bitness: FloatBitness::X64 })), | 74 | (name::F64, BuiltinType::Float(BuiltinFloat::F64)), |
75 | ]; | 75 | ]; |
76 | } | 76 | } |
77 | 77 | ||
@@ -104,3 +104,57 @@ impl fmt::Display for BuiltinType { | |||
104 | f.write_str(type_name) | 104 | f.write_str(type_name) |
105 | } | 105 | } |
106 | } | 106 | } |
107 | |||
108 | #[rustfmt::skip] | ||
109 | impl BuiltinInt { | ||
110 | pub const ISIZE: BuiltinInt = BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::Xsize }; | ||
111 | pub const I8 : BuiltinInt = BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X8 }; | ||
112 | pub const I16 : BuiltinInt = BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X16 }; | ||
113 | pub const I32 : BuiltinInt = BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X32 }; | ||
114 | pub const I64 : BuiltinInt = BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X64 }; | ||
115 | pub const I128 : BuiltinInt = BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X128 }; | ||
116 | |||
117 | pub const USIZE: BuiltinInt = BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize }; | ||
118 | pub const U8 : BuiltinInt = BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X8 }; | ||
119 | pub const U16 : BuiltinInt = BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X16 }; | ||
120 | pub const U32 : BuiltinInt = BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X32 }; | ||
121 | pub const U64 : BuiltinInt = BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X64 }; | ||
122 | pub const U128 : BuiltinInt = BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X128 }; | ||
123 | |||
124 | |||
125 | pub fn from_suffix(suffix: &str) -> Option<BuiltinInt> { | ||
126 | let res = match suffix { | ||
127 | "isize" => Self::ISIZE, | ||
128 | "i8" => Self::I8, | ||
129 | "i16" => Self::I16, | ||
130 | "i32" => Self::I32, | ||
131 | "i64" => Self::I64, | ||
132 | "i128" => Self::I128, | ||
133 | |||
134 | "usize" => Self::USIZE, | ||
135 | "u8" => Self::U8, | ||
136 | "u16" => Self::U16, | ||
137 | "u32" => Self::U32, | ||
138 | "u64" => Self::U64, | ||
139 | "u128" => Self::U128, | ||
140 | |||
141 | _ => return None, | ||
142 | }; | ||
143 | Some(res) | ||
144 | } | ||
145 | } | ||
146 | |||
147 | #[rustfmt::skip] | ||
148 | impl BuiltinFloat { | ||
149 | pub const F32: BuiltinFloat = BuiltinFloat { bitness: FloatBitness::X32 }; | ||
150 | pub const F64: BuiltinFloat = BuiltinFloat { bitness: FloatBitness::X64 }; | ||
151 | |||
152 | pub fn from_suffix(suffix: &str) -> Option<BuiltinFloat> { | ||
153 | let res = match suffix { | ||
154 | "f32" => BuiltinFloat::F32, | ||
155 | "f64" => BuiltinFloat::F64, | ||
156 | _ => return None, | ||
157 | }; | ||
158 | Some(res) | ||
159 | } | ||
160 | } | ||