Skip to content

Commit

Permalink
Rename Complement to BitwiseNot (#1255)
Browse files Browse the repository at this point in the history
BitwiseNot is a much better name.

Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung authored Apr 6, 2023
1 parent c5afda5 commit 8cc4d51
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 48 deletions.
10 changes: 5 additions & 5 deletions solang-parser/src/helpers/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl Display for pt::Expression {
| Self::PreDecrement(..)
| Self::PostDecrement(..)
| Self::Not(..)
| Self::Complement(..)
| Self::BitwiseNot(..)
| Self::UnaryPlus(..)
| Self::Add(..)
| Self::Negate(..)
Expand Down Expand Up @@ -626,7 +626,7 @@ impl pt::Expression {
PreDecrement(..) | PostDecrement(..) => "--",

Not(..) => "!",
Complement(..) => "~",
BitwiseNot(..) => "~",
UnaryPlus(..) | Add(..) => "+",
Negate(..) | Subtract(..) => "-",
Power(..) => "**",
Expand Down Expand Up @@ -1041,7 +1041,7 @@ impl pt::UserDefinedOperator {
pub const fn as_str(&self) -> &'static str {
match self {
Self::BitwiseAnd => "&",
Self::Complement => "~",
Self::BitwiseNot => "~",
Self::Negate => "-",
Self::BitwiseOr => "|",
Self::BitwiseXor => "^",
Expand Down Expand Up @@ -2118,7 +2118,7 @@ mod tests {
pt::Expression::PreDecrement(loc!(), var("a")) => "--a",
pt::Expression::PostDecrement(loc!(), var("a")) => "a--",
pt::Expression::Not(loc!(), var("a")) => "!a",
pt::Expression::Complement(loc!(), var("a")) => "~a",
pt::Expression::BitwiseNot(loc!(), var("a")) => "~a",
pt::Expression::UnaryPlus(loc!(), var("a")) => "+a",
pt::Expression::Negate(loc!(), var("a")) => "-a",

Expand Down Expand Up @@ -2426,7 +2426,7 @@ mod tests {

pt::UserDefinedOperator: {
pt::UserDefinedOperator::BitwiseAnd => "&",
pt::UserDefinedOperator::Complement => "~",
pt::UserDefinedOperator::BitwiseNot => "~",
pt::UserDefinedOperator::Negate => "-",
pt::UserDefinedOperator::BitwiseOr => "|",
pt::UserDefinedOperator::BitwiseXor => "^",
Expand Down
2 changes: 1 addition & 1 deletion solang-parser/src/helpers/loc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl_for_enums! {
| Self::FunctionCallBlock(l, ..)
| Self::NamedFunctionCall(l, ..)
| Self::Not(l, ..)
| Self::Complement(l, ..)
| Self::BitwiseNot(l, ..)
| Self::Delete(l, ..)
| Self::PreIncrement(l, ..)
| Self::PreDecrement(l, ..)
Expand Down
6 changes: 3 additions & 3 deletions solang-parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub enum Token<'input> {
Colon,
OpenBracket,
CloseBracket,
Complement,
BitwiseNot,
Question,

Mapping,
Expand Down Expand Up @@ -244,7 +244,7 @@ impl<'input> fmt::Display for Token<'input> {
Token::Colon => write!(f, ":"),
Token::OpenBracket => write!(f, "["),
Token::CloseBracket => write!(f, "]"),
Token::Complement => write!(f, "~"),
Token::BitwiseNot => write!(f, "~"),
Token::Question => write!(f, "?"),
Token::ShiftRightAssign => write!(f, "<<="),
Token::ShiftRight => write!(f, "<<"),
Expand Down Expand Up @@ -985,7 +985,7 @@ impl<'input> Lexer<'input> {
Some((i, ')')) => return Some(Ok((i, Token::CloseParenthesis, i + 1))),
Some((i, '{')) => return Some(Ok((i, Token::OpenCurlyBrace, i + 1))),
Some((i, '}')) => return Some(Ok((i, Token::CloseCurlyBrace, i + 1))),
Some((i, '~')) => return Some(Ok((i, Token::Complement, i + 1))),
Some((i, '~')) => return Some(Ok((i, Token::BitwiseNot, i + 1))),
Some((i, '=')) => match self.chars.peek() {
Some((_, '=')) => {
self.chars.next();
Expand Down
15 changes: 7 additions & 8 deletions solang-parser/src/pt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,7 @@ pub enum UserDefinedOperator {
BitwiseAnd,
/// `~`
///
/// AKA BitwiseNot
Complement,
BitwiseNot,
/// `-`
///
/// Note that this is the same as `Subtract`, and that it is currently not being parsed.
Expand Down Expand Up @@ -619,15 +618,15 @@ impl UserDefinedOperator {
#[inline]
pub const fn args(&self) -> usize {
match self {
UserDefinedOperator::Complement | UserDefinedOperator::Negate => 1,
UserDefinedOperator::BitwiseNot | UserDefinedOperator::Negate => 1,
_ => 2,
}
}

/// Returns whether `self` is a unary operator.
#[inline]
pub const fn is_unary(&self) -> bool {
matches!(self, Self::Complement | Self::Negate)
matches!(self, Self::BitwiseNot | Self::Negate)
}

/// Returns whether `self` is a binary operator.
Expand All @@ -641,7 +640,7 @@ impl UserDefinedOperator {
pub const fn is_bitwise(&self) -> bool {
matches!(
self,
Self::BitwiseAnd | Self::BitwiseOr | Self::BitwiseXor | Self::Complement
Self::BitwiseAnd | Self::BitwiseOr | Self::BitwiseXor | Self::BitwiseNot
)
}

Expand Down Expand Up @@ -971,7 +970,7 @@ pub enum Expression {
/// `!<1>`
Not(Loc, Box<Expression>),
/// `~<1>`
Complement(Loc, Box<Expression>),
BitwiseNot(Loc, Box<Expression>),
/// `delete <1>`
Delete(Loc, Box<Expression>),
/// `++<1>`
Expand Down Expand Up @@ -1089,7 +1088,7 @@ macro_rules! expr_components {

// (None, Some)
Not(_, expr)
| Complement(_, expr)
| BitwiseNot(_, expr)
| New(_, expr)
| Delete(_, expr)
| UnaryPlus(_, expr)
Expand Down Expand Up @@ -1242,7 +1241,7 @@ impl Expression {
| PostDecrement(..)
| PreDecrement(..)
| Not(..)
| Complement(..)
| BitwiseNot(..)
| UnaryPlus(..)
| Negate(..)
)
Expand Down
6 changes: 3 additions & 3 deletions solang-parser/src/solidity.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ Precedence3: Expression = {

Precedence2: Expression = {
<a:@L> "!" <e:Precedence2> <b:@R> => Expression::Not(Loc::File(file_no, a, b), Box::new(e)),
<a:@L> "~" <e:Precedence2> <b:@R> => Expression::Complement(Loc::File(file_no, a, b), Box::new(e)),
<a:@L> "~" <e:Precedence2> <b:@R> => Expression::BitwiseNot(Loc::File(file_no, a, b), Box::new(e)),
<a:@L> "delete" <e:Precedence2> <b:@R> => Expression::Delete(Loc::File(file_no, a, b), Box::new(e)),
<a:@L> "new" <call:Precedence2> <b:@R> => Expression::New(Loc::File(file_no, a, b), Box::new(call)),
<a:@L> "++" <e:Precedence2> <b:@R> => Expression::PreIncrement(Loc::File(file_no, a, b), Box::new(e)),
Expand Down Expand Up @@ -738,7 +738,7 @@ UsingFunction: UsingFunction = {

UserDefinedOperator: UserDefinedOperator = {
"as" "&" => UserDefinedOperator::BitwiseAnd,
"as" "~" => UserDefinedOperator::Complement,
"as" "~" => UserDefinedOperator::BitwiseNot,
"as" "|" => UserDefinedOperator::BitwiseOr,
"as" "^" => UserDefinedOperator::BitwiseXor,
"as" "+" => UserDefinedOperator::Add,
Expand Down Expand Up @@ -1117,7 +1117,7 @@ extern {
"%" => Token::Modulo,
"**" => Token::Power,
"!" => Token::Not,
"~" => Token::Complement,
"~" => Token::BitwiseNot,
"++" => Token::Increment,
"--" => Token::Decrement,
"[" => Token::OpenBracket,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/languageserver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ impl<'a> Builder<'a> {
| ast::Expression::PostDecrement { expr, .. }
// Other Unary
| ast::Expression::Not { expr, .. }
| ast::Expression::Complement { expr, .. }
| ast::Expression::BitwiseNot { expr, .. }
| ast::Expression::Negate { expr, .. } => {
self.expression(expr, symtab);
}
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ impl ControlFlowGraph {
f
),
Expression::Not(_, e) => format!("!{}", self.expr_to_string(contract, ns, e)),
Expression::Complement(_, _, e) => format!("~{}", self.expr_to_string(contract, ns, e)),
Expression::BitwiseNot(_, _, e) => format!("~{}", self.expr_to_string(contract, ns, e)),
Expression::Negate(_, _, e) => format!("-{}", self.expr_to_string(contract, ns, e)),
Expression::Poison => "☠".to_string(),
Expression::AllocDynamicBytes(_, ty, size, None) => {
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/constant_folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,13 @@ fn expression(
)
}
}
Expression::Complement(loc, ty, expr) => {
Expression::BitwiseNot(loc, ty, expr) => {
let expr = expression(expr, vars, cfg, ns);
if let Expression::NumberLiteral(_, _, n) = expr.0 {
bigint_to_expression(loc, ty, !n)
} else {
(
Expression::Complement(*loc, ty.clone(), Box::new(expr.0)),
Expression::BitwiseNot(*loc, ty.clone(), Box::new(expr.0)),
expr.1,
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ pub fn expression(
*loc,
Box::new(expression(expr, cfg, contract_no, func, ns, vartab, opt)),
),
ast::Expression::Complement { loc, ty, expr } => Expression::Complement(
ast::Expression::BitwiseNot { loc, ty, expr } => Expression::BitwiseNot(
*loc,
ty.clone(),
Box::new(expression(expr, cfg, contract_no, func, ns, vartab, opt)),
Expand Down
12 changes: 6 additions & 6 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ pub enum Expression {
BytesCast(pt::Loc, Type, Type, Box<Expression>),
BytesLiteral(pt::Loc, Type, Vec<u8>),
Cast(pt::Loc, Type, Box<Expression>),
Complement(pt::Loc, Type, Box<Expression>),
BitwiseNot(pt::Loc, Type, Box<Expression>),
ConstArrayLiteral(pt::Loc, Type, Vec<u32>, Vec<Expression>),
UnsignedDivide(pt::Loc, Type, Box<Expression>, Box<Expression>),
SignedDivide(pt::Loc, Type, Box<Expression>, Box<Expression>),
Expand Down Expand Up @@ -465,7 +465,7 @@ impl CodeLocation for Expression {
| Expression::BitwiseXor(loc, ..)
| Expression::Equal(loc, ..)
| Expression::NotEqual(loc, ..)
| Expression::Complement(loc, ..)
| Expression::BitwiseNot(loc, ..)
| Expression::Negate(loc, ..)
| Expression::Less { loc, .. }
| Expression::Not(loc, ..)
Expand Down Expand Up @@ -535,7 +535,7 @@ impl Recurse for Expression {
| Expression::Negate(_, _, exp)
| Expression::ZeroExt(_, _, exp)
| Expression::SignExt(_, _, exp)
| Expression::Complement(_, _, exp)
| Expression::BitwiseNot(_, _, exp)
| Expression::Load(_, _, exp)
| Expression::StorageArrayLength { array: exp, .. }
| Expression::StructMember(_, _, exp, _)
Expand Down Expand Up @@ -607,7 +607,7 @@ impl RetrieveType for Expression {
| Expression::BitwiseXor(_, ty, ..)
| Expression::ShiftLeft(_, ty, ..)
| Expression::ShiftRight(_, ty, ..)
| Expression::Complement(_, ty, ..)
| Expression::BitwiseNot(_, ty, ..)
| Expression::StorageArrayLength { ty, .. }
| Expression::Negate(_, ty, ..)
| Expression::StructLiteral(_, ty, ..)
Expand Down Expand Up @@ -1146,8 +1146,8 @@ impl Expression {
bytes_offset: Box::new(filter(offset, ctx)),
},
Expression::Not(loc, expr) => Expression::Not(*loc, Box::new(filter(expr, ctx))),
Expression::Complement(loc, ty, expr) => {
Expression::Complement(*loc, ty.clone(), Box::new(filter(expr, ctx)))
Expression::BitwiseNot(loc, ty, expr) => {
Expression::BitwiseNot(*loc, ty.clone(), Box::new(filter(expr, ctx)))
}
Expression::Negate(loc, ty, expr) => {
Expression::Negate(*loc, ty.clone(), Box::new(filter(expr, ctx)))
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/strength_reduce/expression_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(super) fn expression_values(
not_equal_values(left_expr, right_expr, vars, ns)
}
Expression::Not(_, expr) => not_values(expr, vars, ns),
Expression::Complement(_, _, expr) => complement_values(expr, vars, ns),
Expression::BitwiseNot(_, _, expr) => complement_values(expr, vars, ns),
Expression::Variable(_, _, var_no) => variable_values(*var_no, vars),
Expression::InternalFunctionCfg(_) => {
// reference to a function; ignore
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/subexpression_elimination/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ impl Expression {

Expression::Not(loc, ..) => Expression::Not(*loc, Box::new(operand.clone())),

Expression::Complement(loc, expr_type, ..) => {
Expression::Complement(*loc, expr_type.clone(), Box::new(operand.clone()))
Expression::BitwiseNot(loc, expr_type, ..) => {
Expression::BitwiseNot(*loc, expr_type.clone(), Box::new(operand.clone()))
}

Expression::Negate(loc, expr_type, ..) => {
Expand Down Expand Up @@ -268,7 +268,7 @@ impl Expression {
| Expression::Cast(_, _, operand)
| Expression::BytesCast(_, _, _, operand)
| Expression::Not(_, operand)
| Expression::Complement(_, _, operand)
| Expression::BitwiseNot(_, _, operand)
| Expression::Negate(_, _, operand) => Some(operand),

_ => None,
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/subexpression_elimination/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub enum Operator {
Cast(Type),
BytesCast,
Negate,
Complement,
BitwiseNot,
}

impl Expression {
Expand Down Expand Up @@ -108,7 +108,7 @@ impl Expression {
Expression::LessEqual { signed: false, .. } => Operator::UnsignedLessEqual,
Expression::Equal(..) => Operator::Equal,
Expression::NotEqual(..) => Operator::NotEqual,
Expression::Complement(..) => Operator::Complement,
Expression::BitwiseNot(..) => Operator::BitwiseNot,
Expression::StringCompare(..) => Operator::StringCompare,
Expression::StringConcat(..) => Operator::StringConcat,
Expression::AdvancePointer { .. } => Operator::AdvancePointer,
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/yul/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(crate) fn process_builtin(
match builtin_ty {
YulBuiltInFunction::Not => {
let exp = expression(&args[0], contract_no, ns, vartab, cfg, opt);
Expression::Complement(*loc, exp.ty(), Box::new(exp))
Expression::BitwiseNot(*loc, exp.ty(), Box::new(exp))
}

YulBuiltInFunction::IsZero => {
Expand Down
2 changes: 1 addition & 1 deletion src/emit/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
.build_int_compare(IntPredicate::EQ, e, e.get_type().const_zero(), "")
.into()
}
Expression::Complement(_, _, e) => {
Expression::BitwiseNot(_, _, e) => {
let e = expression(target, bin, e, vartab, function, ns).into_int_value();

bin.builder.build_not(e, "").into()
Expand Down
6 changes: 3 additions & 3 deletions src/sema/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ pub enum Expression {
loc: pt::Loc,
expr: Box<Expression>,
},
Complement {
BitwiseNot {
loc: pt::Loc,
ty: Type,
expr: Box<Expression>,
Expand Down Expand Up @@ -1200,7 +1200,7 @@ impl Recurse for Expression {
| Expression::PostIncrement { expr, .. }
| Expression::PostDecrement { expr, .. }
| Expression::Not { expr, .. }
| Expression::Complement { expr, .. }
| Expression::BitwiseNot { expr, .. }
| Expression::Negate { expr, .. }
| Expression::StructMember { expr, .. } => expr.recurse(cx, f),

Expand Down Expand Up @@ -1357,7 +1357,7 @@ impl CodeLocation for Expression {
| Expression::Equal { loc, .. }
| Expression::NotEqual { loc, .. }
| Expression::Not { loc, expr: _ }
| Expression::Complement { loc, .. }
| Expression::BitwiseNot { loc, .. }
| Expression::Negate { loc, .. }
| Expression::ConditionalOperator { loc, .. }
| Expression::Subscript { loc, .. }
Expand Down
2 changes: 1 addition & 1 deletion src/sema/dotgraphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ impl Dot {

self.add_expression(expr, func, ns, node, String::from("expr"));
}
Expression::Complement { loc, ty, expr } => {
Expression::BitwiseNot { loc, ty, expr } => {
let node = self.add_node(
Node::new(
"complement",
Expand Down
2 changes: 1 addition & 1 deletion src/sema/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn eval_const_number(
Expression::SignExt { loc, expr, .. } => Ok((*loc, eval_const_number(expr, ns)?.1)),
Expression::Cast { loc, expr, .. } => Ok((*loc, eval_const_number(expr, ns)?.1)),
Expression::Not { loc, expr: n } => Ok((*loc, !eval_const_number(n, ns)?.1)),
Expression::Complement { loc, expr, .. } => Ok((*loc, !eval_const_number(expr, ns)?.1)),
Expression::BitwiseNot { loc, expr, .. } => Ok((*loc, !eval_const_number(expr, ns)?.1)),
Expression::Negate { loc, expr, .. } => Ok((*loc, -eval_const_number(expr, ns)?.1)),
Expression::ConstantVariable {
contract_no: Some(contract_no),
Expand Down
6 changes: 3 additions & 3 deletions src/sema/expression/resolve_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,15 @@ pub fn expression(
expr: Box::new(expr.cast(loc, &Type::Bool, true, ns, diagnostics)?),
})
}
pt::Expression::Complement(loc, e) => {
pt::Expression::BitwiseNot(loc, e) => {
let expr = expression(e, context, ns, symtable, diagnostics, resolve_to)?;

used_variable(ns, &expr, symtable);

if let Some(expr) = user_defined_operator(
loc,
&[&expr],
pt::UserDefinedOperator::Complement,
pt::UserDefinedOperator::BitwiseNot,
diagnostics,
ns,
) {
Expand All @@ -362,7 +362,7 @@ pub fn expression(

get_int_length(&expr_ty, loc, true, ns, diagnostics)?;

Ok(Expression::Complement {
Ok(Expression::BitwiseNot {
loc: *loc,
ty: expr_ty,
expr: Box::new(expr),
Expand Down
Loading

0 comments on commit 8cc4d51

Please sign in to comment.