public bool Equals(AnalysisProxy x, AnalysisProxy y) { #if FULL_VALIDATION if (x != null && y != null) { Validation.Assert(x.UnionEquals(y, Strength) == y.UnionEquals(x, Strength), string.Format("{0}\n{1}\n{2}", Strength, x, y)); if (x.UnionEquals(y, Strength)) { Validation.Assert(x.UnionHashCode(Strength) == y.UnionHashCode(Strength), string.Format("Strength:{0}\n{1} - {2}\n{3} - {4}", Strength, x, x.UnionHashCode(Strength), y, y.UnionHashCode(Strength))); } } #endif if (Object.ReferenceEquals(x, y)) { return(true); } else if (x == null) { return(y == null); } else if (y == null || x.Value == null || y.Value == null) { return(false); } return(x.Value.UnionEquals(y.Value, Strength)); }
/// <summary> /// Merges the provided sequence using the specified <see /// cref="UnionComparer"/>. /// </summary> #if FULL_VALIDATION internal static IEnumerable <AnalysisWrapper> UnionIter(this IEnumerable <AnalysisWrapper> items, UnionComparer comparer, out bool wasChanged) { var originalItems = items.ToList(); var newItems = UnionIterInternal(items, comparer, out wasChanged).ToList(); Validation.Assert(newItems.Count <= originalItems.Count); if (wasChanged) { Validation.Assert(newItems.Count < originalItems.Count); foreach (var x in newItems) { foreach (var y in newItems) { if (object.ReferenceEquals(x, y)) { continue; } Validation.Assert(!comparer.Equals(x, y)); Validation.Assert(!comparer.Equals(y, x)); } } } return(newItems); }
public bool Equals(AnalysisProxy x, AnalysisProxy y) { #if FULL_VALIDATION if (x != null && y != null) { Validation.Assert(x.Equals(y) == y.Equals(x)); if (x.Equals(y)) { Validation.Assert(x.GetHashCode() == y.GetHashCode()); } } #endif return((x == null) ? (y == null) : x.Equals(y)); }
public bool AddTypes(ProjectEntry projectEntry, IAnalysisSet newTypes, bool enqueue = true, ProjectEntry declaringScope = null) { object dummy; if (LockedVariableDefs.TryGetValue(this, out dummy)) { return(false); } bool added = false; if (newTypes.Count > 0) { var dependencies = GetDependentItems(projectEntry); foreach (var value in newTypes) { #if DEBUG || FULL_VALIDATION if (ENABLE_SET_CHECK) { bool testAdded; var original = dependencies.ToImmutableTypeSet(); var afterAdded = new AnalysisHashSet(original, original.Comparer).Add(value, out testAdded); if (afterAdded.Comparer == original.Comparer) { if (testAdded) { Validation.Assert(!ObjectComparer.Instance.Equals(afterAdded, original)); } else { Validation.Assert(ObjectComparer.Instance.Equals(afterAdded, original)); } } } #endif if (dependencies.AddType(value)) { added = true; } } if (added && enqueue) { EnqueueDependents(projectEntry, declaringScope); } } return(added); }
public AnalysisProxy MergeTypes(AnalysisProxy x, AnalysisProxy y, out bool wasChanged) { if (Object.ReferenceEquals(x, y)) { wasChanged = false; return(x); } var z = x.Value.UnionMergeTypes(y.Value, Strength).Proxy; wasChanged = !Object.ReferenceEquals(x, z); #if FULL_VALIDATION var z2 = y.UnionMergeTypes(x, Strength); if (!object.ReferenceEquals(z, z2)) { Validation.Assert(z.UnionEquals(z2, Strength), string.Format("{0}\n{1} + {2} => {3}\n{2} + {1} => {4}", Strength, x, y, z, z2)); Validation.Assert(z2.UnionEquals(z, Strength), string.Format("{0}\n{1} + {2} => {3}\n{2} + {1} => {4}", Strength, y, x, z2, z)); } #endif return(z); }
internal static IEnumerable <AnalysisProxy> UnionIter(this IEnumerable <AnalysisProxy> items, UnionComparer comparer, out bool wasChanged) { #endif wasChanged = false; var asSet = items as IAnalysisSet; if (asSet != null && asSet.Comparer == comparer) { return(items); } var newItems = new List <AnalysisProxy>(); var anyMerged = true; while (anyMerged) { anyMerged = false; var matches = new Dictionary <AnalysisProxy, List <AnalysisProxy> >(comparer); foreach (var ns in items) { List <AnalysisProxy> list; if (matches.TryGetValue(ns, out list)) { if (list == null) { matches[ns] = list = new List <AnalysisProxy>(); } list.Add(ns); } else { matches[ns] = null; } } newItems.Clear(); foreach (var keyValue in matches) { var item = keyValue.Key; if (keyValue.Value != null) { foreach (var other in keyValue.Value) { bool merged; #if FULL_VALIDATION Validation.Assert(comparer.Equals(item, other)); #endif item = comparer.MergeTypes(item, other, out merged); if (merged) { anyMerged = true; wasChanged = true; } } } newItems.Add(item); } items = newItems; } return(items); }