public override bool Equals(OrderedLiteralBase other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } switch (other) { case CharLiteral charLiteral: return(Equals(charLiteral)); case FloatLiteral floatLiteral: return(Equals(IntegerLiteral.From((long)floatLiteral.Value))); case IntegerLiteral integerLiteral: return(Equals(new CharLiteral(integerLiteral))); default: throw new ArgumentOutOfRangeException(nameof(other)); } }
public override int CompareTo(OrderedLiteralBase other) { if (ReferenceEquals(this, other)) { return(0); } if (ReferenceEquals(null, other)) { return(1); } switch (other) { case CharLiteral charLiteral: return(CompareTo(new FloatLiteral(IntegerLiteral.From(charLiteral.Value)))); case FloatLiteral floatLiteral: return(CompareTo(floatLiteral)); case IntegerLiteral integerLiteral: return(CompareTo(new FloatLiteral(integerLiteral))); default: throw new ArgumentOutOfRangeException(nameof(other)); } }
public static OrderedLiteralBase operator ~(OrderedLiteralBase a) { switch (a) { case CharLiteral charLiteralA: return(IntegerLiteral.From(~charLiteralA.Value)); case FloatLiteral _: return(null); case IntegerLiteral integerLiteralA: return(~integerLiteralA); default: throw new ArgumentOutOfRangeException(nameof(a)); } }
public static OrderedLiteralBase operator +(OrderedLiteralBase a, OrderedLiteralBase b) { (a, b) = LiftToCommonType(a, b); if (a.GetType() != b.GetType()) { throw new ApplicationException($"{a.GetType()} != {b.GetType()}"); } switch (a) { case CharLiteral charLiteralA when b is CharLiteral charLiteralB: return(IntegerLiteral.From(charLiteralA.Value + charLiteralB.Value)); case FloatLiteral floatLiteralA when b is FloatLiteral floatLiteralB: return(new FloatLiteral(floatLiteralA.Value + floatLiteralB.Value)); case IntegerLiteral integerLiteralA when b is IntegerLiteral integerLiteralB: return(integerLiteralA + integerLiteralB); default: throw new ArgumentOutOfRangeException(nameof(a)); } }
public static OrderedLiteralBase BitRightShift(OrderedLiteralBase a, OrderedLiteralBase b) { (a, b) = LiftToCommonType(a, b); if (a.GetType() != b.GetType()) { throw new ApplicationException($"{a.GetType()} != {b.GetType()}"); } switch (a) { case CharLiteral charLiteralA when b is CharLiteral charLiteralB: return(IntegerLiteral.From(charLiteralA.Value >> charLiteralB.Value)); case FloatLiteral _ when b is FloatLiteral: return(null); case IntegerLiteral integerLiteralA when b is IntegerLiteral integerLiteralB: return(IntegerLiteral.BitRightShift(integerLiteralA, integerLiteralB)); default: throw new ArgumentOutOfRangeException(nameof(a)); } }