public void UnionUniverse() { Assert.AreEqual(LongSet.Universe, LongSet.Universe.UnionWith(LongSet.Universe)); Assert.AreEqual(LongSet.Universe, LongSet.Universe.UnionWith(LongSet.Empty)); Assert.AreEqual(LongSet.Universe, LongSet.Universe.UnionWith(new LongSet(long.MaxValue))); var longSet = new LongSet(new[] { new LongInterval(1, 5), new LongInterval(6, 7) }.ToImmutableArray()); Assert.AreEqual(LongSet.Universe, longSet.UnionWith(LongSet.Universe)); }
internal override void CheckInvariant(ILPhase phase) { base.CheckInvariant(phase); LongSet sets = LongSet.Empty; foreach (var section in Sections) { Debug.Assert(!section.Labels.IsEmpty); Debug.Assert(!section.Labels.Overlaps(sets)); sets = sets.UnionWith(section.Labels); } }
private bool AnalyzeSwitch(SwitchInstruction inst, LongSet inputValues, out LongSet anyMatchValues) { Debug.Assert(inst.DefaultBody is Nop); anyMatchValues = LongSet.Empty; long offset; if (MatchSwitchVar(inst.Value)) { offset = 0; } else if (inst.Value is BinaryNumericInstruction bop) { if (bop.CheckForOverflow) { return(false); } if (MatchSwitchVar(bop.Left) && bop.Right.MatchLdcI(out long val)) { switch (bop.Operator) { case BinaryNumericOperator.Add: offset = unchecked (-val); break; case BinaryNumericOperator.Sub: offset = val; break; default: // unknown bop.Operator return(false); } } else // unknown bop.Left { return(false); } } else // unknown inst.Value { return(false); } foreach (var section in inst.Sections) { var matchValues = section.Labels.AddOffset(offset).IntersectWith(inputValues); AddSection(matchValues, section.Body); anyMatchValues = anyMatchValues.UnionWith(matchValues); } return(true); }
internal override void CheckInvariant(ILPhase phase) { base.CheckInvariant(phase); bool expectNullSection = this.IsLifted; LongSet sets = LongSet.Empty; foreach (var section in Sections) { if (section.HasNullLabel) { Debug.Assert(expectNullSection, "Duplicate 'case null' or 'case null' in non-lifted switch."); expectNullSection = false; } Debug.Assert(!section.Labels.IsEmpty || section.HasNullLabel); Debug.Assert(!section.Labels.Overlaps(sets)); sets = sets.UnionWith(section.Labels); } Debug.Assert(sets.SetEquals(LongSet.Universe), "switch does not handle all possible cases"); Debug.Assert(!expectNullSection, "Lifted switch is missing 'case null'"); }