diff options
Diffstat (limited to 'crates/ra_hir/src/expr.rs')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index e07725d05..bc8515836 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -11,6 +11,7 @@ use ra_syntax::{ | |||
11 | }; | 11 | }; |
12 | 12 | ||
13 | use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName}; | 13 | use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName}; |
14 | use crate::ty::primitive::{UintTy, IntTy, FloatTy, UncertainIntTy, UncertainFloatTy}; | ||
14 | 15 | ||
15 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 16 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
16 | pub struct ExprId(RawId); | 17 | pub struct ExprId(RawId); |
@@ -112,9 +113,8 @@ pub enum Literal { | |||
112 | ByteString(Vec<u8>), | 113 | ByteString(Vec<u8>), |
113 | Char(char), | 114 | Char(char), |
114 | Bool(bool), | 115 | Bool(bool), |
115 | Byte(u8), | 116 | Int(u64, UncertainIntTy), |
116 | Int, // this and float need additional information | 117 | Float(u64, UncertainFloatTy), // FIXME: f64 is not Eq |
117 | Float, | ||
118 | Tuple { values: Vec<ExprId> }, | 118 | Tuple { values: Vec<ExprId> }, |
119 | Array { values: Vec<ExprId> }, | 119 | Array { values: Vec<ExprId> }, |
120 | } | 120 | } |
@@ -328,13 +328,7 @@ impl Expr { | |||
328 | f(val); | 328 | f(val); |
329 | } | 329 | } |
330 | } | 330 | } |
331 | Literal::String(..) | 331 | _ => {} |
332 | | Literal::ByteString(..) | ||
333 | | Literal::Byte(..) | ||
334 | | Literal::Bool(..) | ||
335 | | Literal::Char(..) | ||
336 | | Literal::Int | ||
337 | | Literal::Float => {} | ||
338 | }, | 332 | }, |
339 | } | 333 | } |
340 | } | 334 | } |
@@ -669,8 +663,43 @@ impl ExprCollector { | |||
669 | 663 | ||
670 | if let Some(c) = child { | 664 | if let Some(c) = child { |
671 | let lit = match c.kind() { | 665 | let lit = match c.kind() { |
672 | SyntaxKind::INT_NUMBER => Literal::Int, | 666 | SyntaxKind::INT_NUMBER => { |
673 | SyntaxKind::FLOAT_NUMBER => Literal::Float, | 667 | let text = c.text().to_string(); |
668 | |||
669 | // FIXME: don't do it like this. maybe use something like | ||
670 | // the IntTy::from_name functions | ||
671 | let ty = if text.ends_with("isize") { | ||
672 | UncertainIntTy::Signed(IntTy::Isize) | ||
673 | } else if text.ends_with("i128") { | ||
674 | UncertainIntTy::Signed(IntTy::I128) | ||
675 | } else if text.ends_with("i64") { | ||
676 | UncertainIntTy::Signed(IntTy::I64) | ||
677 | } else if text.ends_with("i32") { | ||
678 | UncertainIntTy::Signed(IntTy::I32) | ||
679 | } else if text.ends_with("i16") { | ||
680 | UncertainIntTy::Signed(IntTy::I16) | ||
681 | } else if text.ends_with("i8") { | ||
682 | UncertainIntTy::Signed(IntTy::I8) | ||
683 | } else if text.ends_with("usize") { | ||
684 | UncertainIntTy::Unsigned(UintTy::Usize) | ||
685 | } else if text.ends_with("u128") { | ||
686 | UncertainIntTy::Unsigned(UintTy::U128) | ||
687 | } else if text.ends_with("u64") { | ||
688 | UncertainIntTy::Unsigned(UintTy::U64) | ||
689 | } else if text.ends_with("u32") { | ||
690 | UncertainIntTy::Unsigned(UintTy::U32) | ||
691 | } else if text.ends_with("u16") { | ||
692 | UncertainIntTy::Unsigned(UintTy::U16) | ||
693 | } else if text.ends_with("u8") { | ||
694 | UncertainIntTy::Unsigned(UintTy::U8) | ||
695 | } else { | ||
696 | UncertainIntTy::Unknown | ||
697 | }; | ||
698 | |||
699 | // TODO: actually parse integer | ||
700 | Literal::Int(0u64, ty) | ||
701 | } | ||
702 | SyntaxKind::FLOAT_NUMBER => Literal::Float(0, UncertainFloatTy::Unknown), | ||
674 | SyntaxKind::STRING => { | 703 | SyntaxKind::STRING => { |
675 | // FIXME: this likely includes the " characters | 704 | // FIXME: this likely includes the " characters |
676 | let text = c.text().to_string(); | 705 | let text = c.text().to_string(); |
@@ -698,7 +727,10 @@ impl ExprCollector { | |||
698 | } | 727 | } |
699 | SyntaxKind::BYTE => { | 728 | SyntaxKind::BYTE => { |
700 | let character = c.text().char_at(1).unwrap_or('X'); | 729 | let character = c.text().char_at(1).unwrap_or('X'); |
701 | Literal::Byte(character as u8) | 730 | Literal::Int( |
731 | character as u8 as u64, | ||
732 | UncertainIntTy::Unsigned(UintTy::U8), | ||
733 | ) | ||
702 | } | 734 | } |
703 | _ => return self.alloc_expr(Expr::Missing, syntax_ptr), | 735 | _ => return self.alloc_expr(Expr::Missing, syntax_ptr), |
704 | }; | 736 | }; |