From b20d37cb49536e19f6af57b00258f86eb8f19325 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 31 Oct 2019 10:51:54 +0300 Subject: move builtin types to hir_def --- crates/ra_hir_def/src/builtin_type.rs | 63 +++++++++++++++++++++++++++++++++++ crates/ra_hir_def/src/lib.rs | 1 + 2 files changed, 64 insertions(+) create mode 100644 crates/ra_hir_def/src/builtin_type.rs (limited to 'crates/ra_hir_def') 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 @@ +//! This module defines built-in types. +//! +//! A peculiarity of built-in types is that they are always available and are +//! not associated with any particular crate. + +use hir_expand::name::{self, Name}; + +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub enum Signedness { + Signed, + Unsigned, +} + +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub enum IntBitness { + Xsize, + X8, + X16, + X32, + X64, + X128, +} + +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub enum FloatBitness { + X32, + X64, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum BuiltinType { + Char, + Bool, + Str, + Int { signedness: Signedness, bitness: IntBitness }, + Float { bitness: FloatBitness }, +} + +impl BuiltinType { + #[rustfmt::skip] + pub const ALL: &'static [(Name, BuiltinType)] = &[ + (name::CHAR, BuiltinType::Char), + (name::BOOL, BuiltinType::Bool), + (name::STR, BuiltinType::Str ), + + (name::ISIZE, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::Xsize }), + (name::I8, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X8 }), + (name::I16, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X16 }), + (name::I32, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X32 }), + (name::I64, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X64 }), + (name::I128, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X128 }), + + (name::USIZE, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize }), + (name::U8, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X8 }), + (name::U16, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X16 }), + (name::U32, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X32 }), + (name::U64, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X64 }), + (name::U128, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X128 }), + + (name::F32, BuiltinType::Float { bitness: FloatBitness::X32 }), + (name::F64, BuiltinType::Float { bitness: FloatBitness::X64 }), + ]; +} 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; pub mod attr; pub mod path; pub mod type_ref; +pub mod builtin_type; // FIXME: this should be private pub mod nameres; -- cgit v1.2.3