BinOpKind
This commit is contained in:
parent
1bd17e4fa2
commit
5d4102ee78
36 changed files with 260 additions and 248 deletions
|
|
@ -240,7 +240,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
|
|||
let left_pat = self.next("left");
|
||||
let right_pat = self.next("right");
|
||||
println!("Binary(ref {}, ref {}, ref {}) = {};", op_pat, left_pat, right_pat, current);
|
||||
println!(" if BinOp_::{:?} == {}.node;", op.node, op_pat);
|
||||
println!(" if BinOpKind::{:?} == {}.node;", op.node, op_pat);
|
||||
self.current = left_pat;
|
||||
self.visit_expr(left);
|
||||
self.current = right_pat;
|
||||
|
|
@ -385,7 +385,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
|
|||
let target_pat = self.next("target");
|
||||
let value_pat = self.next("value");
|
||||
println!("AssignOp(ref {}, ref {}, ref {}) = {};", op_pat, target_pat, value_pat, current);
|
||||
println!(" if BinOp_::{:?} == {}.node;", op.node, op_pat);
|
||||
println!(" if BinOpKind::{:?} == {}.node;", op.node, op_pat);
|
||||
self.current = target_pat;
|
||||
self.visit_expr(target);
|
||||
self.current = value_pat;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#![deny(missing_docs_in_private_items)]
|
||||
|
||||
use rustc::hir::{BinOp_, Expr};
|
||||
use rustc::hir::{BinOpKind, Expr};
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
||||
/// Represent a normalized comparison operator.
|
||||
|
|
@ -19,14 +19,14 @@ pub enum Rel {
|
|||
|
||||
/// Put the expression in the form `lhs < rhs`, `lhs <= rhs`, `lhs == rhs` or
|
||||
/// `lhs != rhs`.
|
||||
pub fn normalize_comparison<'a>(op: BinOp_, lhs: &'a Expr, rhs: &'a Expr) -> Option<(Rel, &'a Expr, &'a Expr)> {
|
||||
pub fn normalize_comparison<'a>(op: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(Rel, &'a Expr, &'a Expr)> {
|
||||
match op {
|
||||
BinOp_::BiLt => Some((Rel::Lt, lhs, rhs)),
|
||||
BinOp_::BiLe => Some((Rel::Le, lhs, rhs)),
|
||||
BinOp_::BiGt => Some((Rel::Lt, rhs, lhs)),
|
||||
BinOp_::BiGe => Some((Rel::Le, rhs, lhs)),
|
||||
BinOp_::BiEq => Some((Rel::Eq, rhs, lhs)),
|
||||
BinOp_::BiNe => Some((Rel::Ne, rhs, lhs)),
|
||||
BinOpKind::Lt => Some((Rel::Lt, lhs, rhs)),
|
||||
BinOpKind::Le => Some((Rel::Le, lhs, rhs)),
|
||||
BinOpKind::Gt => Some((Rel::Lt, rhs, lhs)),
|
||||
BinOpKind::Ge => Some((Rel::Le, rhs, lhs)),
|
||||
BinOpKind::Eq => Some((Rel::Eq, rhs, lhs)),
|
||||
BinOpKind::Ne => Some((Rel::Ne, rhs, lhs)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use syntax::ast;
|
|||
use crate::utils::{is_expn_of, match_def_path, match_qpath, opt_def_id, paths, resolve_node};
|
||||
|
||||
/// Convert a hir binary operator to the corresponding `ast` type.
|
||||
pub fn binop(op: hir::BinOp_) -> ast::BinOpKind {
|
||||
pub fn binop(op: hir::BinOpKind) -> ast::BinOpKind {
|
||||
match op {
|
||||
hir::BinOpKind::Eq => ast::BinOpKind::Eq,
|
||||
hir::BinOpKind::Ge => ast::BinOpKind::Ge,
|
||||
|
|
|
|||
|
|
@ -280,14 +280,26 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn swap_binop<'a>(binop: BinOp_, lhs: &'a Expr, rhs: &'a Expr) -> Option<(BinOp_, &'a Expr, &'a Expr)> {
|
||||
fn swap_binop<'a>(binop: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(BinOpKind, &'a Expr, &'a Expr)> {
|
||||
match binop {
|
||||
BiAdd | BiMul | BiBitXor | BiBitAnd | BiEq | BiNe | BiBitOr => Some((binop, rhs, lhs)),
|
||||
BiLt => Some((BiGt, rhs, lhs)),
|
||||
BiLe => Some((BiGe, rhs, lhs)),
|
||||
BiGe => Some((BiLe, rhs, lhs)),
|
||||
BiGt => Some((BiLt, rhs, lhs)),
|
||||
BiShl | BiShr | BiRem | BiSub | BiDiv | BiAnd | BiOr => None,
|
||||
BinOpKind::Add |
|
||||
BinOpKind::Mul |
|
||||
BinOpKind::Eq |
|
||||
BinOpKind::Ne |
|
||||
BinOpKind::BitAnd |
|
||||
BinOpKind::BitXor |
|
||||
BinOpKind::BitOr => Some((binop, rhs, lhs)),
|
||||
BinOpKind::Lt => Some((BinOpKind::Gt, rhs, lhs)),
|
||||
BinOpKind::Le => Some((BinOpKind::Ge, rhs, lhs)),
|
||||
BinOpKind::Ge => Some((BinOpKind::Le, rhs, lhs)),
|
||||
BinOpKind::Gt => Some((BinOpKind::Lt, rhs, lhs)),
|
||||
BinOpKind::Shl |
|
||||
BinOpKind::Shr |
|
||||
BinOpKind::Rem |
|
||||
BinOpKind::Sub |
|
||||
BinOpKind::Div |
|
||||
BinOpKind::And |
|
||||
BinOpKind::Or => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -382,21 +382,21 @@ fn associativity(op: &AssocOp) -> Associativity {
|
|||
|
||||
/// Convert a `hir::BinOp` to the corresponding assigning binary operator.
|
||||
fn hirbinop2assignop(op: hir::BinOp) -> AssocOp {
|
||||
use rustc::hir::BinOp_::*;
|
||||
use rustc::hir::BinOpKind::*;
|
||||
use syntax::parse::token::BinOpToken::*;
|
||||
|
||||
AssocOp::AssignOp(match op.node {
|
||||
BiAdd => Plus,
|
||||
BiBitAnd => And,
|
||||
BiBitOr => Or,
|
||||
BiBitXor => Caret,
|
||||
BiDiv => Slash,
|
||||
BiMul => Star,
|
||||
BiRem => Percent,
|
||||
BiShl => Shl,
|
||||
BiShr => Shr,
|
||||
BiSub => Minus,
|
||||
BiAnd | BiEq | BiGe | BiGt | BiLe | BiLt | BiNe | BiOr => panic!("This operator does not exist"),
|
||||
BinOpKind::Add => Plus,
|
||||
BinOpKind::BitAnd => And,
|
||||
BinOpKind::BitOr => Or,
|
||||
BinOpKind::BitXor => Caret,
|
||||
BinOpKind::Div => Slash,
|
||||
BinOpKind::Mul => Star,
|
||||
BinOpKind::Rem => Percent,
|
||||
BinOpKind::Shl => Shl,
|
||||
BinOpKind::Shr => Shr,
|
||||
BinOpKind::Sub => Minus,
|
||||
BinOpKind::And | BinOpKind::Eq | BinOpKind::Ge | BinOpKind::Gt | BinOpKind::Le | BinOpKind::Lt | BinOpKind::Ne | BinOpKind::Or => panic!("This operator does not exist"),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue