Beispiel #1
0
        /// <summary>
        /// Assigns the specified collector.
        /// </summary>
        /// <param name="collector">The collector.</param>
        /// <param name="sourceIndex">Index of the source.</param>
        internal void Assign(IIndexCollector collector, MemoryIndex sourceIndex)
        {
            foreach (MemoryIndex mustIndex in collector.MustIndexes)
            {
                snapshot.DestroyMemory(mustIndex);
                CopyWithinSnapshotWorker copyWorker = new CopyWithinSnapshotWorker(snapshot, true);
                copyWorker.Copy(sourceIndex, mustIndex);
            }

            foreach (MemoryIndex mayIndex in collector.MayIndexes)
            {
                MergeWithinSnapshotWorker mergeWorker = new MergeWithinSnapshotWorker(snapshot);
                mergeWorker.MergeIndexes(mayIndex, sourceIndex);
            }

            MemoryEntry entry = SnapshotDataUtils.GetMemoryEntry(snapshot, snapshot.CurrentData.Readonly, sourceIndex);

            LocationVisitor mustVisitor = new LocationVisitor(snapshot, entry, true);

            foreach (ValueLocation location in collector.MustLocation)
            {
                location.Accept(mustVisitor);
            }

            LocationVisitor mayVisitor = new LocationVisitor(snapshot, entry, false);

            foreach (ValueLocation location in collector.MayLocaton)
            {
                location.Accept(mayVisitor);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Makes the aliases.
        /// </summary>
        /// <param name="collector">The collector.</param>
        /// <param name="data">The data.</param>
        private void makeAliases(IIndexCollector collector, AliasData data)
        {
            //Must target
            foreach (MemoryIndex index in collector.MustIndexes)
            {
                snapshot.MustSetAliases(index, data.MustIndexes, data.MayIndexes);
            }

            //Must source
            foreach (MemoryIndex index in data.MustIndexes)
            {
                snapshot.AddAliases(index, collector.MustIndexes, collector.MayIndexes);
            }

            //May target
            HashSet <MemoryIndex> sourceAliases = new HashSet <MemoryIndex>(data.MustIndexes.Concat(data.MayIndexes));

            foreach (MemoryIndex index in collector.MayIndexes)
            {
                snapshot.MaySetAliases(index, sourceAliases);
            }

            //May source
            HashSet <MemoryIndex> targetAliases = new HashSet <MemoryIndex>(collector.MustIndexes.Concat(collector.MayIndexes));

            foreach (MemoryIndex index in data.MayIndexes)
            {
                snapshot.AddAliases(index, null, targetAliases);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Makes the aliases.
        /// </summary>
        /// <param name="sourceCollector">The source collector.</param>
        /// <param name="targetCollector">The target collector.</param>
        private void makeAliases(IIndexCollector sourceCollector, IIndexCollector targetCollector)
        {
            if (snapshot.AssignInfo == null)
            {
                snapshot.AssignInfo = new AssignInfo();
            }

            //Must target
            foreach (MemoryIndex index in targetCollector.MustIndexes)
            {
                snapshot.MustSetAliases(index, sourceCollector.MustIndexes, sourceCollector.MayIndexes);

                //Must source
                foreach (MemoryIndex alias in sourceCollector.MustIndexes)
                {
                    if (!alias.Equals(index))
                    {
                        snapshot.AssignInfo.AliasAssignModifications.GetOrCreateModification(index).AddDatasource(alias, snapshot);
                    }
                }

                //May source
                foreach (MemoryIndex alias in sourceCollector.MayIndexes)
                {
                    if (!alias.Equals(index))
                    {
                        snapshot.AssignInfo.AliasAssignModifications.GetOrCreateModification(index).AddDatasource(alias, snapshot);
                    }
                }
            }

            //Must source
            foreach (MemoryIndex index in sourceCollector.MustIndexes)
            {
                snapshot.AddAliases(index, targetCollector.MustIndexes, targetCollector.MayIndexes);
            }

            //May target
            HashSet <MemoryIndex> sourceAliases = new HashSet <MemoryIndex>(sourceCollector.MustIndexes.Concat(sourceCollector.MayIndexes));

            foreach (MemoryIndex index in targetCollector.MayIndexes)
            {
                snapshot.MaySetAliases(index, sourceAliases);
            }

            //May source
            HashSet <MemoryIndex> targetAliases = new HashSet <MemoryIndex>(targetCollector.MustIndexes.Concat(targetCollector.MayIndexes));

            foreach (MemoryIndex index in sourceCollector.MayIndexes)
            {
                snapshot.AddAliases(index, null, targetAliases);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Reads the values from locations specified by given collector.
        /// </summary>
        /// <param name="collector">The collector.</param>
        /// <returns>Memory entry with values from locations specified by given collector.</returns>
        public MemoryEntry ReadValue(IIndexCollector collector)
        {
            if (collector.MustIndexesCount == 1 && collector.IsDefined)
            {
                MemoryIndex index = collector.MustIndexes.First();
                return(snapshot.Structure.GetMemoryEntry(index));
            }
            else
            {
                HashSet <Value> values = new HashSet <Value>();
                if (!collector.IsDefined)
                {
                    values.Add(snapshot.UndefinedValue);
                }

                foreach (MemoryIndex index in collector.MustIndexes)
                {
                    MemoryEntry entry = snapshot.Structure.GetMemoryEntry(index);
                    HashSetTools.AddAll(values, entry.PossibleValues);
                }

                foreach (ValueLocation location in collector.MustLocation)
                {
                    if (snapshot.CurrentMode == SnapshotMode.MemoryLevel)
                    {
                        HashSetTools.AddAll(values, location.ReadValues(snapshot.MemoryAssistant));
                    }
                    else
                    {
                        InfoLocationVisitor visitor = new InfoLocationVisitor(snapshot);
                        location.Accept(visitor);
                        HashSetTools.AddAll(values, visitor.Value);
                    }
                }

                return(new MemoryEntry(values));
            }
        }
Beispiel #5
0
 /// <summary>
 /// Assigns the alias.
 /// </summary>
 /// <param name="sourceCollector">The source collector.</param>
 /// <param name="targetCollector">The target collector.</param>
 /// <param name="dataIndex">Index of the data.</param>
 internal void AssignAlias(IIndexCollector sourceCollector, IIndexCollector targetCollector, MemoryIndex dataIndex)
 {
     assignWorker.Assign(targetCollector, dataIndex);
     makeAliases(sourceCollector, targetCollector);
 }
Beispiel #6
0
 /// <summary>
 /// Assigns the alias.
 /// </summary>
 /// <param name="collector">The collector.</param>
 /// <param name="data">The data.</param>
 internal void AssignAlias(IIndexCollector collector, AliasData data)
 {
     assignWorker.Assign(collector, data.SourceIndex);
     makeAliases(collector, data);
 }