aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/builtin_type.rs63
-rw-r--r--crates/ra_hir_def/src/lib.rs1
2 files changed, 64 insertions, 0 deletions
diff --git a/crates/ra_hir_def/src/builtin_type.rs b/crates/ra_hir_def/src/builtin_type.rs
new file mode 100644
index 000000000..12929caa9
--- /dev/null
+++ b/crates/ra_hir_def/src/builtin_type.rs
@@ -0,0 +1,63 @@
1//! This module defines built-in types.
2//!
3//! A peculiarity of built-in types is that they are always available and are
4//! not associated with any particular crate.
5
6use hir_expand::name::{self, Name};
7
8#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
9pub enum Signedness {
10 Signed,
11 Unsigned,
12}
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
15pub enum IntBitness {
16 Xsize,
17 X8,
18 X16,
19 X32,
20 X64,
21 X128,
22}
23
24#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
25pub enum FloatBitness {
26 X32,
27 X64,
28}
29
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31pub enum BuiltinType {
32 Char,
33 Bool,
34 Str,
35 Int { signedness: Signedness, bitness: IntBitness },
36 Float { bitness: FloatBitness },
37}
38
39impl BuiltinType {
40 #[rustfmt::skip]
41 pub const ALL: &'static [(Name, BuiltinType)] = &[
42 (name::CHAR, BuiltinType::Char),
43 (name::BOOL, BuiltinType::Bool),
44 (name::STR, BuiltinType::Str ),
45
46 (name::ISIZE, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::Xsize }),
47 (name::I8, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X8 }),
48 (name::I16, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X16 }),
49 (name::I32, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X32 }),
50 (name::I64, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X64 }),
51 (name::I128, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X128 }),
52
53 (name::USIZE, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize }),
54 (name::U8, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X8 }),
55 (name::U16, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X16 }),
56 (name::U32, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X32 }),
57 (name::U64, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X64 }),
58 (name::U128, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X128 }),
59
60 (name::F32, BuiltinType::Float { bitness: FloatBitness::X32 }),
61 (name::F64, BuiltinType::Float { bitness: FloatBitness::X64 }),
62 ];
63}
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 7a6c7b301..8cbff673c 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -11,6 +11,7 @@ pub mod db;
11pub mod attr; 11pub mod attr;
12pub mod path; 12pub mod path;
13pub mod type_ref; 13pub mod type_ref;
14pub mod builtin_type;
14 15
15// FIXME: this should be private 16// FIXME: this should be private
16pub mod nameres; 17pub mod nameres;