From e5d8077e3d345c609f561ecbeeeaf422534a82d8 Mon Sep 17 00:00:00 2001 From: LPeter1997 Date: Tue, 3 Oct 2023 20:34:10 +0200 Subject: [PATCH] Update IntegralDomain.cs --- .../FlowAnalysis/Domain/IntegralDomain.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Draco.Compiler/Internal/FlowAnalysis/Domain/IntegralDomain.cs b/src/Draco.Compiler/Internal/FlowAnalysis/Domain/IntegralDomain.cs index 733706877..6350777dc 100644 --- a/src/Draco.Compiler/Internal/FlowAnalysis/Domain/IntegralDomain.cs +++ b/src/Draco.Compiler/Internal/FlowAnalysis/Domain/IntegralDomain.cs @@ -30,7 +30,10 @@ internal sealed class IntegralDomain : ValueDomain /// /// The lower bound (inclusive). /// The upper bound (inclusive). - private readonly record struct Interval(TInteger From, TInteger To); + private readonly record struct Interval(TInteger From, TInteger To) + { + public override string ToString() => $"[{this.From}; {this.To}]"; + } public override bool IsEmpty => this.subtracted.Count == 1 @@ -191,10 +194,16 @@ private void SubtractRange(TInteger from, TInteger to) private BoundPattern ToPattern(TInteger integer) => new BoundLiteralPattern(null, integer, this.backingType); - private static bool Intersects(Interval a, Interval b) => !AreDisjunct(a, b); - private static bool AreDisjunct(Interval a, Interval b) => - a.From > b.To + TInteger.MultiplicativeIdentity - || a.To + TInteger.MultiplicativeIdentity > b.From; + private static bool Intersects(Interval a, Interval b) => + Touches(a, b) + || Contains(a, b.From) + || Contains(a, b.To) + || Contains(b, a.From) + || Contains(b, a.To); + private static bool Contains(Interval iv, TInteger n) => iv.From <= n && n <= iv.To; + private static bool Touches(Interval a, Interval b) => + a.To + TInteger.MultiplicativeIdentity == b.From + || b.To + TInteger.MultiplicativeIdentity == a.From; private static TInteger Min(TInteger a, TInteger b) => a > b ? b : a; private static TInteger Max(TInteger a, TInteger b) => a > b ? a : b; }