Rename bitwise operators for readability (#5937)

This commit is contained in:
JT
2022-07-03 10:05:02 +12:00
committed by GitHub
parent b82dccf0bd
commit a48616697a
5 changed files with 29 additions and 29 deletions

View File

@ -440,19 +440,19 @@ pub fn eval_expression(
}
Operator::BitOr => {
let rhs = eval_expression(engine_state, stack, rhs)?;
lhs.bor(op_span, &rhs, expr.span)
lhs.bit_or(op_span, &rhs, expr.span)
}
Operator::BitAnd => {
let rhs = eval_expression(engine_state, stack, rhs)?;
lhs.band(op_span, &rhs, expr.span)
lhs.bit_and(op_span, &rhs, expr.span)
}
Operator::ShiftRight => {
let rhs = eval_expression(engine_state, stack, rhs)?;
lhs.bshr(op_span, &rhs, expr.span)
lhs.bit_shr(op_span, &rhs, expr.span)
}
Operator::ShiftLeft => {
let rhs = eval_expression(engine_state, stack, rhs)?;
lhs.bshl(op_span, &rhs, expr.span)
lhs.bit_shl(op_span, &rhs, expr.span)
}
}
}

View File

@ -4106,10 +4106,10 @@ pub fn parse_operator(
b"in" => Operator::In,
b"not-in" => Operator::NotIn,
b"mod" => Operator::Modulo,
b"bor" => Operator::BitOr,
b"band" => Operator::BitAnd,
b"bshl" => Operator::ShiftLeft,
b"bshr" => Operator::ShiftRight,
b"bit-or" => Operator::BitOr,
b"bit-and" => Operator::BitAnd,
b"bit-shl" => Operator::ShiftLeft,
b"bit-shr" => Operator::ShiftRight,
b"starts-with" => Operator::StartsWith,
b"ends-with" => Operator::EndsWith,
b"&&" | b"and" => Operator::And,

View File

@ -52,10 +52,10 @@ impl Display for Operator {
Operator::And => write!(f, "&&"),
Operator::Or => write!(f, "||"),
Operator::Pow => write!(f, "**"),
Operator::BitOr => write!(f, "bor"),
Operator::BitAnd => write!(f, "band"),
Operator::ShiftLeft => write!(f, "bshl"),
Operator::ShiftRight => write!(f, "bshr"),
Operator::BitOr => write!(f, "bit-or"),
Operator::BitAnd => write!(f, "bit-and"),
Operator::ShiftLeft => write!(f, "bit-shl"),
Operator::ShiftRight => write!(f, "bit-shr"),
Operator::LessThanOrEqual => write!(f, "<="),
Operator::GreaterThanOrEqual => write!(f, ">="),
Operator::StartsWith => write!(f, "starts-with"),

View File

@ -2240,7 +2240,7 @@ impl Value {
}
}
pub fn bshl(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
pub fn bit_shl(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
match (self, rhs) {
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => Ok(Value::Int {
span,
@ -2259,7 +2259,7 @@ impl Value {
}
}
pub fn bshr(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
pub fn bit_shr(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
match (self, rhs) {
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => Ok(Value::Int {
span,
@ -2278,7 +2278,7 @@ impl Value {
}
}
pub fn bor(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
pub fn bit_or(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
match (self, rhs) {
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => Ok(Value::Int {
span,
@ -2297,7 +2297,7 @@ impl Value {
}
}
pub fn band(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
pub fn bit_and(&self, op: Span, rhs: &Value, span: Span) -> Result<Value, ShellError> {
match (self, rhs) {
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => Ok(Value::Int {
span,