aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/expr
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/expr')
-rw-r--r--crates/ra_hir/src/expr/lower.rs84
1 files changed, 15 insertions, 69 deletions
diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs
index 6463dd65e..adc68b23c 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
3use hir_def::{path::GenericArgs, type_ref::TypeRef}; 3use hir_def::{
4 builtin_type::{BuiltinFloat, BuiltinInt},
5 path::GenericArgs,
6 type_ref::TypeRef,
7};
4use hir_expand::{ 8use hir_expand::{
5 hygiene::Hygiene, 9 hygiene::Hygiene,
6 name::{self, AsName, Name}, 10 name::{self, AsName, Name},
@@ -16,22 +20,19 @@ use ra_syntax::{
16use test_utils::tested_by; 20use test_utils::tested_by;
17 21
18use crate::{ 22use crate::{
19 db::HirDatabase, 23 db::HirDatabase, AstId, Either, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path,
20 ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, 24 Resolver, Source,
21 AstId, DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path, Resolver,
22 Source,
23}; 25};
24 26
25use super::{ 27use 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
30pub(super) fn lower( 32pub(super) fn lower(
31 db: &impl HirDatabase, 33 db: &impl HirDatabase,
32 resolver: Resolver, 34 resolver: Resolver,
33 file_id: HirFileId, 35 file_id: HirFileId,
34 owner: DefWithBody,
35 params: Option<ast::ParamList>, 36 params: Option<ast::ParamList>,
36 body: Option<ast::Expr>, 37 body: Option<ast::Expr>,
37) -> (Body, BodySourceMap) { 38) -> (Body, BodySourceMap) {
@@ -42,11 +43,10 @@ pub(super) fn lower(
42 current_file_id: file_id, 43 current_file_id: file_id,
43 source_map: BodySourceMap::default(), 44 source_map: BodySourceMap::default(),
44 body: Body { 45 body: Body {
45 owner,
46 exprs: Arena::default(), 46 exprs: Arena::default(),
47 pats: Arena::default(), 47 pats: Arena::default(),
48 params: Vec::new(), 48 params: Vec::new(),
49 body_expr: ExprId((!0).into()), 49 body_expr: ExprId::dummy(),
50 }, 50 },
51 } 51 }
52 .collect(params, body) 52 .collect(params, body)
@@ -423,28 +423,18 @@ where
423 ast::Expr::Literal(e) => { 423 ast::Expr::Literal(e) => {
424 let lit = match e.kind() { 424 let lit = match e.kind() {
425 LiteralKind::IntNumber { suffix } => { 425 LiteralKind::IntNumber { suffix } => {
426 let known_name = suffix 426 let known_name = suffix.and_then(|it| BuiltinInt::from_suffix(&it));
427 .and_then(|it| IntTy::from_suffix(&it).map(UncertainIntTy::Known));
428 427
429 Literal::Int( 428 Literal::Int(Default::default(), known_name)
430 Default::default(),
431 known_name.unwrap_or(UncertainIntTy::Unknown),
432 )
433 } 429 }
434 LiteralKind::FloatNumber { suffix } => { 430 LiteralKind::FloatNumber { suffix } => {
435 let known_name = suffix 431 let known_name = suffix.and_then(|it| BuiltinFloat::from_suffix(&it));
436 .and_then(|it| FloatTy::from_suffix(&it).map(UncertainFloatTy::Known));
437 432
438 Literal::Float( 433 Literal::Float(Default::default(), known_name)
439 Default::default(),
440 known_name.unwrap_or(UncertainFloatTy::Unknown),
441 )
442 } 434 }
443 LiteralKind::ByteString => Literal::ByteString(Default::default()), 435 LiteralKind::ByteString => Literal::ByteString(Default::default()),
444 LiteralKind::String => Literal::String(Default::default()), 436 LiteralKind::String => Literal::String(Default::default()),
445 LiteralKind::Byte => { 437 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()), 438 LiteralKind::Bool => Literal::Bool(Default::default()),
449 LiteralKind::Char => Literal::Char(Default::default()), 439 LiteralKind::Char => Literal::Char(Default::default()),
450 }; 440 };
@@ -601,47 +591,3 @@ where
601 Path::from_src(path, &hygiene) 591 Path::from_src(path, &hygiene)
602 } 592 }
603} 593}
604
605impl 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}