コード例 #1
0
        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);
        }
コード例 #2
0
        public void HashSet()
        {
            var projectEntry            = CreateProjectEntry();
            List <AnalysisProxy> values = new List <AnalysisProxy>();

            for (int i = 0; i < 10; i++)
            {
                values.Add(new TestAnalysisValue(projectEntry).Proxy);
            }

            var set = new AnalysisHashSet();

            for (int i = 0; i < values.Count; i++)
            {
                Assert.IsFalse(set.Contains(values[i]));
                Assert.AreEqual(set, set.Add(values[i]));
                Assert.AreEqual(i + 1, set.Count);
                Assert.IsTrue(set.Contains(values[i]));

                for (int j = 0; j <= i; j++)
                {
                    Assert.AreEqual(set, set.Add(values[j]));
                    Assert.AreEqual(i + 1, set.Count);
                }
            }

            foreach (var enumMaker in EnumMaker)
            {
                set = new AnalysisHashSet();
                for (int i = 0; i < values.Count; i++)
                {
                    Assert.IsFalse(set.Contains(values[i]));
                    Assert.AreEqual(set, set.Union(enumMaker(values[i])));
                    Assert.AreEqual(i + 1, set.Count);
                    Assert.IsTrue(set.Contains(values[i]));

                    for (int j = 0; j <= i; j++)
                    {
                        Assert.AreEqual(set, set.Union(enumMaker(values[j])));
                        Assert.AreEqual(i + 1, set.Count);
                    }
                }
            }

            set = new AnalysisHashSet();
            for (int i = 0; i < values.Count; i++)
            {
                Assert.IsFalse(set.Contains(values[i]));
                bool wasChanged;
                Assert.AreEqual(set, set.Add(values[i], out wasChanged));
                Assert.AreEqual(true, wasChanged);
                Assert.AreEqual(i + 1, set.Count);
                Assert.IsTrue(set.Contains(values[i]));

                for (int j = 0; j <= i; j++)
                {
                    Assert.AreEqual(set, set.Add(values[j], out wasChanged));
                    Assert.IsFalse(wasChanged);
                    Assert.AreEqual(i + 1, set.Count);
                }
            }

            foreach (var enumMaker in EnumMaker)
            {
                set = new AnalysisHashSet();
                for (int i = 0; i < values.Count; i++)
                {
                    Assert.IsFalse(set.Contains(values[i]));
                    bool wasChanged;
                    Assert.AreEqual(set, set.Union(enumMaker(values[i]), out wasChanged));
                    Assert.IsTrue(wasChanged);
                    Assert.AreEqual(i + 1, set.Count);

                    for (int j = 0; j <= i; j++)
                    {
                        Assert.AreEqual(set, set.Union(enumMaker(values[j]), out wasChanged));
                        Assert.IsFalse(wasChanged);
                        Assert.AreEqual(i + 1, set.Count);
                    }
                }
            }
        }