Skip to content

Commit

Permalink
Merge pull request #1012 from lana-shanghai/feat/add_usize_isize_types
Browse files Browse the repository at this point in the history
add usize and isize primitive types
  • Loading branch information
Y-Nak authored Jun 10, 2024
2 parents 5b405ad + 96acdc4 commit 5f36438
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/hir-analysis/src/ty/ty_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,14 @@ impl TyBase {
PrimTy::U64 => "u64",
PrimTy::U128 => "u128",
PrimTy::U256 => "u256",
PrimTy::Usize => "usize",
PrimTy::I8 => "i8",
PrimTy::I16 => "i16",
PrimTy::I32 => "i32",
PrimTy::I64 => "i64",
PrimTy::I128 => "i128",
PrimTy::I256 => "i256",
PrimTy::Isize => "isize",
PrimTy::String => "String",
PrimTy::Array => "[]",
PrimTy::Tuple(_) => "()",
Expand Down Expand Up @@ -849,6 +851,7 @@ impl From<HirPrimTy> for TyBase {
HirIntTy::I64 => Self::Prim(PrimTy::I64),
HirIntTy::I128 => Self::Prim(PrimTy::I128),
HirIntTy::I256 => Self::Prim(PrimTy::I256),
HirIntTy::Isize => Self::Prim(PrimTy::Isize),
},

HirPrimTy::Uint(uint_ty) => match uint_ty {
Expand All @@ -858,6 +861,7 @@ impl From<HirPrimTy> for TyBase {
HirUintTy::U64 => Self::Prim(PrimTy::U64),
HirUintTy::U128 => Self::Prim(PrimTy::U128),
HirUintTy::U256 => Self::Prim(PrimTy::U256),
HirUintTy::Usize => Self::Prim(PrimTy::Usize),
},

HirPrimTy::String => Self::Prim(PrimTy::String),
Expand All @@ -874,12 +878,14 @@ pub enum PrimTy {
U64,
U128,
U256,
Usize,
I8,
I16,
I32,
I64,
I128,
I256,
Isize,
String,
Array,
Tuple(usize),
Expand All @@ -896,12 +902,14 @@ impl PrimTy {
| Self::U64
| Self::U128
| Self::U256
| Self::Usize
| Self::I8
| Self::I16
| Self::I32
| Self::I64
| Self::I128
| Self::I256
| Self::Isize
)
}

Expand Down
2 changes: 2 additions & 0 deletions crates/hir/src/hir_def/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ pub mod kw {
(U64, "u64"),
(U128, "u128"),
(U256, "u256"),
(USIZE, "usize"),
(I8, "i8"),
(I16, "i16"),
(I32, "i32"),
(I64, "i64"),
(I128, "i128"),
(I256, "i256"),
(ISIZE, "isize"),
}
}
6 changes: 6 additions & 0 deletions crates/hir/src/hir_def/prim_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ impl PrimTy {
PrimTy::Int(IntTy::I64),
PrimTy::Int(IntTy::I128),
PrimTy::Int(IntTy::I256),
PrimTy::Int(IntTy::Isize),
PrimTy::Uint(UintTy::U8),
PrimTy::Uint(UintTy::U16),
PrimTy::Uint(UintTy::U32),
PrimTy::Uint(UintTy::U64),
PrimTy::Uint(UintTy::U128),
PrimTy::Uint(UintTy::U256),
PrimTy::Uint(UintTy::Usize),
PrimTy::String,
]
}
Expand All @@ -47,6 +49,7 @@ pub enum IntTy {
I64,
I128,
I256,
Isize,
}

impl IntTy {
Expand All @@ -58,6 +61,7 @@ impl IntTy {
IntTy::I64 => kw::I64,
IntTy::I128 => kw::I128,
IntTy::I256 => kw::I256,
IntTy::Isize => kw::ISIZE,
}
}
}
Expand All @@ -70,6 +74,7 @@ pub enum UintTy {
U64,
U128,
U256,
Usize,
}

impl UintTy {
Expand All @@ -81,6 +86,7 @@ impl UintTy {
UintTy::U64 => kw::U64,
UintTy::U128 => kw::U128,
UintTy::U256 => kw::U256,
UintTy::Usize => kw::USIZE,
}
}
}

0 comments on commit 5f36438

Please sign in to comment.