diff options
Diffstat (limited to 'crates/ra_hir_def/src/body')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs new file mode 100644 index 000000000..1a144b1f9 --- /dev/null +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -0,0 +1,49 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use ra_syntax::ast; | ||
4 | |||
5 | use crate::expr::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering}; | ||
6 | |||
7 | impl From<ast::BinOp> for BinaryOp { | ||
8 | fn from(ast_op: ast::BinOp) -> Self { | ||
9 | match ast_op { | ||
10 | ast::BinOp::BooleanOr => BinaryOp::LogicOp(LogicOp::Or), | ||
11 | ast::BinOp::BooleanAnd => BinaryOp::LogicOp(LogicOp::And), | ||
12 | ast::BinOp::EqualityTest => BinaryOp::CmpOp(CmpOp::Eq { negated: false }), | ||
13 | ast::BinOp::NegatedEqualityTest => BinaryOp::CmpOp(CmpOp::Eq { negated: true }), | ||
14 | ast::BinOp::LesserEqualTest => { | ||
15 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Less, strict: false }) | ||
16 | } | ||
17 | ast::BinOp::GreaterEqualTest => { | ||
18 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Greater, strict: false }) | ||
19 | } | ||
20 | ast::BinOp::LesserTest => { | ||
21 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Less, strict: true }) | ||
22 | } | ||
23 | ast::BinOp::GreaterTest => { | ||
24 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Greater, strict: true }) | ||
25 | } | ||
26 | ast::BinOp::Addition => BinaryOp::ArithOp(ArithOp::Add), | ||
27 | ast::BinOp::Multiplication => BinaryOp::ArithOp(ArithOp::Mul), | ||
28 | ast::BinOp::Subtraction => BinaryOp::ArithOp(ArithOp::Sub), | ||
29 | ast::BinOp::Division => BinaryOp::ArithOp(ArithOp::Div), | ||
30 | ast::BinOp::Remainder => BinaryOp::ArithOp(ArithOp::Rem), | ||
31 | ast::BinOp::LeftShift => BinaryOp::ArithOp(ArithOp::Shl), | ||
32 | ast::BinOp::RightShift => BinaryOp::ArithOp(ArithOp::Shr), | ||
33 | ast::BinOp::BitwiseXor => BinaryOp::ArithOp(ArithOp::BitXor), | ||
34 | ast::BinOp::BitwiseOr => BinaryOp::ArithOp(ArithOp::BitOr), | ||
35 | ast::BinOp::BitwiseAnd => BinaryOp::ArithOp(ArithOp::BitAnd), | ||
36 | ast::BinOp::Assignment => BinaryOp::Assignment { op: None }, | ||
37 | ast::BinOp::AddAssign => BinaryOp::Assignment { op: Some(ArithOp::Add) }, | ||
38 | ast::BinOp::DivAssign => BinaryOp::Assignment { op: Some(ArithOp::Div) }, | ||
39 | ast::BinOp::MulAssign => BinaryOp::Assignment { op: Some(ArithOp::Mul) }, | ||
40 | ast::BinOp::RemAssign => BinaryOp::Assignment { op: Some(ArithOp::Rem) }, | ||
41 | ast::BinOp::ShlAssign => BinaryOp::Assignment { op: Some(ArithOp::Shl) }, | ||
42 | ast::BinOp::ShrAssign => BinaryOp::Assignment { op: Some(ArithOp::Shr) }, | ||
43 | ast::BinOp::SubAssign => BinaryOp::Assignment { op: Some(ArithOp::Sub) }, | ||
44 | ast::BinOp::BitOrAssign => BinaryOp::Assignment { op: Some(ArithOp::BitOr) }, | ||
45 | ast::BinOp::BitAndAssign => BinaryOp::Assignment { op: Some(ArithOp::BitAnd) }, | ||
46 | ast::BinOp::BitXorAssign => BinaryOp::Assignment { op: Some(ArithOp::BitXor) }, | ||
47 | } | ||
48 | } | ||
49 | } | ||