Beispiel #1
0
        /// <summary>
        /// Processes the root indexes. This is the beginning of an computation which creates the root node from given sets of indexes.
        /// Used to collect all data from aliased locations.
        /// </summary>
        /// <param name="mustIndexes">The must indexes.</param>
        /// <param name="mayIndexes">The may indexes.</param>
        /// <param name="values">The values.</param>
        public void ProcessRootIndexes(HashSet <MemoryIndex> mustIndexes, HashSet <MemoryIndex> mayIndexes, IEnumerable <Value> values)
        {
            RootNode = new MemoryEntryCollectorNode();
            RootNode.SourceIndexes = new List <SourceIndex>();
            RootNode.IsMust        = true;

            foreach (MemoryIndex index in mustIndexes)
            {
                RootNode.SourceIndexes.Add(new SourceIndex(index, Snapshot));
                RootNode.CollectAliases(index, Snapshot, true);
            }
            foreach (MemoryIndex index in mayIndexes)
            {
                RootNode.SourceIndexes.Add(new SourceIndex(index, Snapshot));
                RootNode.CollectAliases(index, Snapshot, false);
            }

            RootNode.CollectValuesFromSources(this);
            RootNode.VisitValues(values);
            RootNode.CollectChildren(this);


            processQueue();
            RootMemoryEntry = RootNode.GenerateMemeoryEntry(values);
        }
Beispiel #2
0
        /// <summary>
        /// Processes the root memory entry. This is the beginning of an computation which creates the root node from given memory entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        public void ProcessRootMemoryEntry(MemoryEntry entry)
        {
            RootNode        = new MemoryEntryCollectorNode();
            RootNode.IsMust = true;
            RootNode.CollectValuesFromMemoryEntry(entry);
            RootNode.CollectChildren(this);

            processQueue();
            RootMemoryEntry = entry;
        }
Beispiel #3
0
        /// <summary>
        /// Process all nodes stored in the queue to build the tree.
        /// </summary>
        private void processQueue()
        {
            while (collectingQueue.Count > 0)
            {
                MemoryEntryCollectorNode node = collectingQueue.First.Value;
                collectingQueue.RemoveFirst();

                node.CollectAliasesFromSources(this);
                node.CollectValuesFromSources(this);
                node.CollectChildren(this);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Produce an empty node with no inner data an no childs. This node can be used as
        /// an unknown node in the assign algorithm.
        /// </summary>
        /// <param name="snapshot">The snapshot.</param>
        /// <returns>An empty node.</returns>
        public static MemoryEntryCollectorNode GetEmptyNode(Snapshot snapshot)
        {
            if (emptyNode != null)
            {
                return(emptyNode);
            }
            else
            {
                emptyNode = new MemoryEntryCollectorNode();
                emptyNode.ScalarValues = new HashSet <Value>();
                emptyNode.ScalarValues.Add(snapshot.UndefinedValue);

                return(emptyNode);
            }
        }
Beispiel #5
0
        public void CollectChildren(MemoryEntryCollector collector)
        {
            if (Arrays != null && Arrays.Count > 0)
            {
                // Create new collection for named children
                NamedChildren = new Dictionary <string, MemoryEntryCollectorNode>();

                // Any child node
                AnyChild = new MemoryEntryCollectorNode();
                AnyChild.SourceIndexes = new List <SourceIndex>();
                AnyChild.IsMust        = false;
                collector.AddNode(AnyChild);

                // Collect child names and adds any child sources
                HashSet <string> names = new HashSet <string>();
                List <Tuple <Snapshot, IArrayDescriptor> > sourceDescriptors = new List <Tuple <Snapshot, IArrayDescriptor> >();
                foreach (AssociativeArray arrayValue in Arrays)
                {
                    var descriptors = getIArrayDescriptors(collector, arrayValue);
                    foreach (var tuple in descriptors)
                    {
                        sourceDescriptors.Add(tuple);

                        Snapshot         sourceSnapshot = tuple.Item1;
                        IArrayDescriptor descriptor     = tuple.Item2;

                        AnyChild.SourceIndexes.Add(new SourceIndex(descriptor.UnknownIndex, sourceSnapshot));
                        foreach (var item in descriptor.Indexes)
                        {
                            names.Add(item.Key);
                        }
                    }
                }

                // Test whether new array as MAY or MUST
                bool mustHaveChildren = this.IsMust && mustHaveArray;
                mustHaveChildren &= (ScalarValues == null || ScalarValues.Count == 0);
                mustHaveChildren &= (Objects == null || Objects.Count == 0);

                // Iterates collected names and stors them into the structure
                foreach (string name in names)
                {
                    MemoryEntryCollectorNode childNode = new MemoryEntryCollectorNode();
                    childNode.SourceIndexes = new List <SourceIndex>();
                    childNode.IsMust        = mustHaveChildren;
                    collector.AddNode(childNode);
                    NamedChildren.Add(name, childNode);

                    // Collect sources for named child
                    foreach (var tuple in sourceDescriptors)
                    {
                        Snapshot         sourceSnapshot = tuple.Item1;
                        IArrayDescriptor descriptor     = tuple.Item2;

                        MemoryIndex index;
                        if (descriptor.TryGetIndex(name, out index))
                        {
                            childNode.SourceIndexes.Add(new SourceIndex(index, sourceSnapshot));
                        }
                        else
                        {
                            childNode.IsMust = false;
                            childNode.SourceIndexes.Add(new SourceIndex(descriptor.UnknownIndex, sourceSnapshot));
                        }
                    }
                }
            }
        }
Beispiel #6
0
 /// <summary>
 /// Adds the node to the collecting queue.
 /// </summary>
 /// <param name="node">The node.</param>
 public void AddNode(MemoryEntryCollectorNode node)
 {
     collectingQueue.AddLast(node);
 }