diff options
Diffstat (limited to 'crates/ra_hir/src/expr')
-rw-r--r-- | crates/ra_hir/src/expr/lower.rs | 82 |
1 files changed, 15 insertions, 67 deletions
diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index 6463dd65e..7b0bfd919 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs | |||
@@ -1,6 +1,10 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir_def::{path::GenericArgs, type_ref::TypeRef}; | 3 | use hir_def::{ |
4 | builtin_type::{BuiltinFloat, BuiltinInt}, | ||
5 | path::GenericArgs, | ||
6 | type_ref::TypeRef, | ||
7 | }; | ||
4 | use hir_expand::{ | 8 | use hir_expand::{ |
5 | hygiene::Hygiene, | 9 | hygiene::Hygiene, |
6 | name::{self, AsName, Name}, | 10 | name::{self, AsName, Name}, |
@@ -16,15 +20,13 @@ use ra_syntax::{ | |||
16 | use test_utils::tested_by; | 20 | use test_utils::tested_by; |
17 | 21 | ||
18 | use crate::{ | 22 | use crate::{ |
19 | db::HirDatabase, | 23 | db::HirDatabase, AstId, DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, |
20 | ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, | 24 | Mutability, Path, Resolver, Source, |
21 | AstId, DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path, Resolver, | ||
22 | Source, | ||
23 | }; | 25 | }; |
24 | 26 | ||
25 | use super::{ | 27 | use super::{ |
26 | ArithOp, Array, BinaryOp, BindingAnnotation, Body, BodySourceMap, CmpOp, Expr, ExprId, Literal, | 28 | Array, BinaryOp, BindingAnnotation, Body, BodySourceMap, Expr, ExprId, Literal, MatchArm, Pat, |
27 | LogicOp, MatchArm, Ordering, Pat, PatId, PatPtr, RecordFieldPat, RecordLitField, Statement, | 29 | PatId, PatPtr, RecordFieldPat, RecordLitField, Statement, |
28 | }; | 30 | }; |
29 | 31 | ||
30 | pub(super) fn lower( | 32 | pub(super) fn lower( |
@@ -46,7 +48,7 @@ pub(super) fn lower( | |||
46 | exprs: Arena::default(), | 48 | exprs: Arena::default(), |
47 | pats: Arena::default(), | 49 | pats: Arena::default(), |
48 | params: Vec::new(), | 50 | params: Vec::new(), |
49 | body_expr: ExprId((!0).into()), | 51 | body_expr: ExprId::dummy(), |
50 | }, | 52 | }, |
51 | } | 53 | } |
52 | .collect(params, body) | 54 | .collect(params, body) |
@@ -423,28 +425,18 @@ where | |||
423 | ast::Expr::Literal(e) => { | 425 | ast::Expr::Literal(e) => { |
424 | let lit = match e.kind() { | 426 | let lit = match e.kind() { |
425 | LiteralKind::IntNumber { suffix } => { | 427 | LiteralKind::IntNumber { suffix } => { |
426 | let known_name = suffix | 428 | let known_name = suffix.and_then(|it| BuiltinInt::from_suffix(&it)); |
427 | .and_then(|it| IntTy::from_suffix(&it).map(UncertainIntTy::Known)); | ||
428 | 429 | ||
429 | Literal::Int( | 430 | Literal::Int(Default::default(), known_name) |
430 | Default::default(), | ||
431 | known_name.unwrap_or(UncertainIntTy::Unknown), | ||
432 | ) | ||
433 | } | 431 | } |
434 | LiteralKind::FloatNumber { suffix } => { | 432 | LiteralKind::FloatNumber { suffix } => { |
435 | let known_name = suffix | 433 | let known_name = suffix.and_then(|it| BuiltinFloat::from_suffix(&it)); |
436 | .and_then(|it| FloatTy::from_suffix(&it).map(UncertainFloatTy::Known)); | ||
437 | 434 | ||
438 | Literal::Float( | 435 | Literal::Float(Default::default(), known_name) |
439 | Default::default(), | ||
440 | known_name.unwrap_or(UncertainFloatTy::Unknown), | ||
441 | ) | ||
442 | } | 436 | } |
443 | LiteralKind::ByteString => Literal::ByteString(Default::default()), | 437 | LiteralKind::ByteString => Literal::ByteString(Default::default()), |
444 | LiteralKind::String => Literal::String(Default::default()), | 438 | LiteralKind::String => Literal::String(Default::default()), |
445 | LiteralKind::Byte => { | 439 | LiteralKind::Byte => Literal::Int(Default::default(), Some(BuiltinInt::U8)), |
446 | Literal::Int(Default::default(), UncertainIntTy::Known(IntTy::u8())) | ||
447 | } | ||
448 | LiteralKind::Bool => Literal::Bool(Default::default()), | 440 | LiteralKind::Bool => Literal::Bool(Default::default()), |
449 | LiteralKind::Char => Literal::Char(Default::default()), | 441 | LiteralKind::Char => Literal::Char(Default::default()), |
450 | }; | 442 | }; |
@@ -601,47 +593,3 @@ where | |||
601 | Path::from_src(path, &hygiene) | 593 | Path::from_src(path, &hygiene) |
602 | } | 594 | } |
603 | } | 595 | } |
604 | |||
605 | impl From<ast::BinOp> for BinaryOp { | ||
606 | fn from(ast_op: ast::BinOp) -> Self { | ||
607 | match ast_op { | ||
608 | ast::BinOp::BooleanOr => BinaryOp::LogicOp(LogicOp::Or), | ||
609 | ast::BinOp::BooleanAnd => BinaryOp::LogicOp(LogicOp::And), | ||
610 | ast::BinOp::EqualityTest => BinaryOp::CmpOp(CmpOp::Eq { negated: false }), | ||
611 | ast::BinOp::NegatedEqualityTest => BinaryOp::CmpOp(CmpOp::Eq { negated: true }), | ||
612 | ast::BinOp::LesserEqualTest => { | ||
613 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Less, strict: false }) | ||
614 | } | ||
615 | ast::BinOp::GreaterEqualTest => { | ||
616 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Greater, strict: false }) | ||
617 | } | ||
618 | ast::BinOp::LesserTest => { | ||
619 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Less, strict: true }) | ||
620 | } | ||
621 | ast::BinOp::GreaterTest => { | ||
622 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Greater, strict: true }) | ||
623 | } | ||
624 | ast::BinOp::Addition => BinaryOp::ArithOp(ArithOp::Add), | ||
625 | ast::BinOp::Multiplication => BinaryOp::ArithOp(ArithOp::Mul), | ||
626 | ast::BinOp::Subtraction => BinaryOp::ArithOp(ArithOp::Sub), | ||
627 | ast::BinOp::Division => BinaryOp::ArithOp(ArithOp::Div), | ||
628 | ast::BinOp::Remainder => BinaryOp::ArithOp(ArithOp::Rem), | ||
629 | ast::BinOp::LeftShift => BinaryOp::ArithOp(ArithOp::Shl), | ||
630 | ast::BinOp::RightShift => BinaryOp::ArithOp(ArithOp::Shr), | ||
631 | ast::BinOp::BitwiseXor => BinaryOp::ArithOp(ArithOp::BitXor), | ||
632 | ast::BinOp::BitwiseOr => BinaryOp::ArithOp(ArithOp::BitOr), | ||
633 | ast::BinOp::BitwiseAnd => BinaryOp::ArithOp(ArithOp::BitAnd), | ||
634 | ast::BinOp::Assignment => BinaryOp::Assignment { op: None }, | ||
635 | ast::BinOp::AddAssign => BinaryOp::Assignment { op: Some(ArithOp::Add) }, | ||
636 | ast::BinOp::DivAssign => BinaryOp::Assignment { op: Some(ArithOp::Div) }, | ||
637 | ast::BinOp::MulAssign => BinaryOp::Assignment { op: Some(ArithOp::Mul) }, | ||
638 | ast::BinOp::RemAssign => BinaryOp::Assignment { op: Some(ArithOp::Rem) }, | ||
639 | ast::BinOp::ShlAssign => BinaryOp::Assignment { op: Some(ArithOp::Shl) }, | ||
640 | ast::BinOp::ShrAssign => BinaryOp::Assignment { op: Some(ArithOp::Shr) }, | ||
641 | ast::BinOp::SubAssign => BinaryOp::Assignment { op: Some(ArithOp::Sub) }, | ||
642 | ast::BinOp::BitOrAssign => BinaryOp::Assignment { op: Some(ArithOp::BitOr) }, | ||
643 | ast::BinOp::BitAndAssign => BinaryOp::Assignment { op: Some(ArithOp::BitAnd) }, | ||
644 | ast::BinOp::BitXorAssign => BinaryOp::Assignment { op: Some(ArithOp::BitXor) }, | ||
645 | } | ||
646 | } | ||
647 | } | ||