2016-04-07 15:46:48 +00:00
|
|
|
use rustc::hir::{BinOp_, Expr};
|
2016-03-26 05:57:03 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
|
|
|
pub enum Rel {
|
|
|
|
Lt,
|
|
|
|
Le,
|
2016-03-29 05:06:57 +00:00
|
|
|
Eq,
|
|
|
|
Ne,
|
2016-03-26 05:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Put the expression in the form `lhs < rhs` or `lhs <= rhs`.
|
|
|
|
pub fn normalize_comparison<'a>(op: BinOp_, 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)),
|
2016-03-29 05:06:57 +00:00
|
|
|
BinOp_::BiEq => Some((Rel::Eq, rhs, lhs)),
|
|
|
|
BinOp_::BiNe => Some((Rel::Ne, rhs, lhs)),
|
2016-03-26 05:57:03 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|