From 3238c06a5a122b7e7b9b6871484c700b7947fae1 Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Mon, 7 Jan 2019 19:03:25 +0100 Subject: Add remaining binary operations to AST --- crates/ra_syntax/src/ast.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/ast.rs') diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 9df8ec663..d8e187514 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -504,7 +504,52 @@ pub enum BinOp { LesserTest, /// The `>` operator for comparison GreaterTest, - // TODO: lots of others + /// The `+` operator for addition + Addition, + /// The `*` operator for multiplication + Multiplication, + /// The `-` operator for subtraction + Subtraction, + /// The `/` operator for division + Division, + /// The `%` operator for remainder after division + Remainder, + /// The `<<` operator for left shift + LeftShift, + /// The `>>` operator for right shift + RightShift, + /// The `^` operator for bitwise XOR + BitwiseXor, + /// The `|` operator for bitwise OR + BitwiseOr, + /// The `&` operator for bitwise AND + BitwiseAnd, + /// The `..` operator for right-open ranges + RangeRightOpen, + /// The `..=` operator for right-closed ranges + RangeRightClosed, + /// The `=` operator for assignment + Assignment, + /// The `+=` operator for assignment after additon + AddAssign, + /// The `/=` operator for assignment after division + DivAssign, + /// The `*=` operator for assignment after multiplication + MulAssign, + /// The `%=` operator for assignment after remainders + RemAssign, + /// The `>>=` operator for assignment after shifting right + ShrAssign, + /// The `<<=` operator for assignment after shifting left + ShlAssign, + /// The `-=` operator for assignment after subtraction + SubAssign, + /// The `|=` operator for assignment after bitwise OR + BitOrAssign, + /// The `&=` operator for assignment after bitwise AND + BitAndAssign, + /// The `^=` operator for assignment after bitwise XOR + BitXorAssin, } impl<'a> BinExpr<'a> { @@ -519,6 +564,29 @@ impl<'a> BinExpr<'a> { GTEQ => Some(BinOp::GreaterEqualTest), L_ANGLE => Some(BinOp::LesserTest), R_ANGLE => Some(BinOp::GreaterTest), + PLUS => Some(BinOp::Addition), + STAR => Some(BinOp::Multiplication), + MINUS => Some(BinOp::Subtraction), + SLASH => Some(BinOp::Division), + PERCENT => Some(BinOp::Remainder), + SHL => Some(BinOp::LeftShift), + SHR => Some(BinOp::RightShift), + CARET => Some(BinOp::BitwiseXor), + PIPE => Some(BinOp::BitwiseOr), + AMP => Some(BinOp::BitwiseAnd), + DOTDOT => Some(BinOp::RangeRightOpen), + DOTDOTEQ => Some(BinOp::RangeRightClosed), + EQ => Some(BinOp::Assignment), + PLUSEQ => Some(BinOp::AddAssign), + SLASHEQ => Some(BinOp::DivAssign), + STAREQ => Some(BinOp::MulAssign), + PERCENTEQ => Some(BinOp::RemAssign), + SHREQ => Some(BinOp::ShrAssign), + SHLEQ => Some(BinOp::ShlAssign), + MINUSEQ => Some(BinOp::SubAssign), + PIPEEQ => Some(BinOp::BitOrAssign), + AMPEQ => Some(BinOp::BitAndAssign), + CARETEQ => Some(BinOp::BitXorAssin), _ => None, }) .next() -- cgit v1.2.3 From 7b0eaef58072acc087d23faca5a9f9879f1765d5 Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Mon, 7 Jan 2019 20:11:31 +0100 Subject: Implement type inference for more binary operators Mostly just for primitive numeric types such as u32 and f64. Not yet a general solution using trait resolution. --- crates/ra_syntax/src/ast.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/ast.rs') diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index d8e187514..9ab59738f 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -549,7 +549,7 @@ pub enum BinOp { /// The `&=` operator for assignment after bitwise AND BitAndAssign, /// The `^=` operator for assignment after bitwise XOR - BitXorAssin, + BitXorAssign, } impl<'a> BinExpr<'a> { @@ -586,7 +586,7 @@ impl<'a> BinExpr<'a> { MINUSEQ => Some(BinOp::SubAssign), PIPEEQ => Some(BinOp::BitOrAssign), AMPEQ => Some(BinOp::BitAndAssign), - CARETEQ => Some(BinOp::BitXorAssin), + CARETEQ => Some(BinOp::BitXorAssign), _ => None, }) .next() -- cgit v1.2.3