Skip to content
Prev Previous commit
Next Next commit
#57 Operands (constants and register operands) can be compared for eq…
…uality
  • Loading branch information
dibyendumajumdar committed Aug 10, 2025
commit c77a931de1fea400bdc6e1e8ee4e5566df16c855
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.compilerprogramming.ezlang.types.Symbol;
import com.compilerprogramming.ezlang.types.EZType;

import java.util.Objects;

public class Operand {

EZType type;
Expand All @@ -17,6 +19,19 @@ public ConstantOperand(long value, EZType type) {
public String toString() {
return String.valueOf(value);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConstantOperand that = (ConstantOperand) o;
return value == that.value;
}

@Override
public int hashCode() {
return Objects.hashCode(value);
}
}

public static class NullConstantOperand extends Operand {
Expand Down Expand Up @@ -46,6 +61,19 @@ public RegisterOperand copy(Register register) {
public String toString() {
return reg.name();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RegisterOperand operand = (RegisterOperand) o;
return Objects.equals(reg, operand.reg);
}

@Override
public int hashCode() {
return Objects.hashCode(reg);
}
}

public static class LocalRegisterOperand extends RegisterOperand {
Expand Down