예제 #1
0
        /// <summary>
        /// Creates merge operations for all indexes in the target collection. Source indexes for the operation are
        /// retreived from the source collections. When there is missing index in some collection the operation set
        /// to undefined.
        ///
        /// This method is for both phases of analysis.
        /// </summary>
        public void MergeContainers()
        {
            // Process all names which has unassociated index and creates one
            foreach (string indexName in undefinedIndexes)
            {
                writeableTargetContainer.AddIndex(indexName, targetIndex.CreateIndex(indexName));
            }

            foreach (var index in targetContainer.Indexes)
            {
                MergeOperation operation = new MergeOperation(index.Value);
                worker.addOperation(operation);

                if (isUndefined)
                {
                    operation.SetUndefined();
                }

                foreach (var source in sources)
                {
                    IReadonlyIndexContainer container = source.Item1;
                    Snapshot snapshot = source.Item2;

                    MemoryIndex containerIndex;
                    if (container.TryGetIndex(index.Key, out containerIndex))
                    {
                        operation.Add(containerIndex, snapshot);
                    }
                    else
                    {
                        operation.Add(container.UnknownIndex, snapshot);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Stores given collection as the source of indexes and adds its unknown index into unknown operation.
        /// Also gets all indexes from the source collection and inserts it into target collection.
        ///
        /// This method is for the first phase of anaysis.
        /// </summary>
        /// <param name="sourceSnapshot">The source snapshot.</param>
        /// <param name="sourceIndex">Index of the source.</param>
        /// <param name="sourceContainer">The source container.</param>
        public void CollectIndexes(
            Snapshot sourceSnapshot,
            MemoryIndex sourceIndex,
            IReadonlyIndexContainer sourceContainer)
        {
            sources.Add(new Tuple <IReadonlyIndexContainer, Snapshot>(sourceContainer, sourceSnapshot));

            unknownOperation.Add(sourceContainer.UnknownIndex, sourceSnapshot);

            bool indexEquals = targetIndex.Equals(sourceIndex);

            foreach (var index in sourceContainer.Indexes)
            {
                MemoryIndex containerIndex;
                if (targetContainer.TryGetIndex(index.Key, out containerIndex))
                {
                    if (containerIndex == null && indexEquals)
                    {
                        writeableTargetContainer.AddIndex(index.Key, index.Value);
                        undefinedIndexes.Remove(index.Key);
                    }
                }
                else if (indexEquals)
                {
                    writeableTargetContainer.AddIndex(index.Key, index.Value);
                }
                else
                {
                    writeableTargetContainer.AddIndex(index.Key, null);
                    undefinedIndexes.Add(index.Key);
                }
            }
        }
예제 #3
0
        public void MergeIndexes(MemoryIndex targetIndex, MemoryIndex sourceIndex)
        {
            if (!sourceIndex.IsPrefixOf(targetIndex) && !targetIndex.IsPrefixOf(sourceIndex))
            {
                MergeOperation operation = new MergeOperation(targetIndex);
                operation.Add(targetIndex, targetSnapshot);
                operation.Add(sourceIndex, targetSnapshot);
                operation.IsRoot = true;
                addOperation(operation);

                arrayCount = 2;

                processMerge();
            }
        }
예제 #4
0
        /// <summary>
        /// Creates merge operations for all temporary indexes in the target structure.
        /// </summary>
        /// <param name="index">The index.</param>
        private void mergeTemporary(int index)
        {
            foreach (var temp in Structure.Readonly.GetReadonlyStackContext(index).ReadonlyTemporaryVariables)
            {
                MergeOperation operation = new MergeOperation(temp);
                addOperation(operation);

                foreach (Snapshot snapshot in sourceSnapshots)
                {
                    if (snapshot.Structure.Readonly.IsDefined(temp))
                    {
                        operation.Add(temp, snapshot);
                    }
                    else
                    {
                        operation.SetUndefined();
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Creates merge operations for all temporary indexes in the target structure.
        /// </summary>
        /// <param name="index">The index.</param>
        private void mergeTemporary(int index)
        {
            IWriteableSet <MemoryIndex> temporary = writeableStrucure.GetWriteableStackContext(index).WriteableTemporaryVariables;

            foreach (var temp in temporary)
            {
                MergeOperation operation = new MergeOperation(temp);
                addOperation(operation);

                foreach (Snapshot snapshot in sourceSnapshots)
                {
                    if (snapshot.Structure.Readonly.IsDefined(temp))
                    {
                        operation.Add(temp, snapshot);
                    }
                    else
                    {
                        operation.SetUndefined();
                    }
                }
            }
        }
예제 #6
0
        private AssociativeArray mergeArrays(
            MemoryIndex targetIndex,
            HashSet <AssociativeArray> arrays,
            bool includeUndefined)
        {
            AssociativeArray arrayValue;

            if (!targetSnapshot.Structure.Readonly.TryGetArray(targetIndex, out arrayValue))
            {
                arrayValue = targetSnapshot.CreateArray(targetIndex);
            }
            IArrayDescriptor newDescriptor = targetSnapshot.Structure.Readonly.GetDescriptor(arrayValue);

            MergeOperation unknownMerge = new MergeOperation(newDescriptor.UnknownIndex);

            unknownMerge.SetUndefined();
            addOperation(unknownMerge);

            HashSet <string> indexNames = new HashSet <string>();

            foreach (AssociativeArray array in arrays)
            {
                foreach (Tuple <Snapshot, IArrayDescriptor> item in getIArrayDescriptor(array))
                {
                    Snapshot         snapshot   = item.Item1;
                    IArrayDescriptor descriptor = item.Item2;

                    unknownMerge.Add(descriptor.UnknownIndex, snapshot);

                    foreach (var index in descriptor.Indexes)
                    {
                        indexNames.Add(index.Key);
                    }
                }
            }

            foreach (string indexName in indexNames)
            {
                MergeOperation operation = new MergeOperation();

                if (includeUndefined)
                {
                    operation.SetUndefined();
                }

                foreach (var array in arrays)
                {
                    foreach (Tuple <Snapshot, IArrayDescriptor> item in getIArrayDescriptor(array))
                    {
                        Snapshot         snapshot   = item.Item1;
                        IArrayDescriptor descriptor = item.Item2;

                        MemoryIndex sourceIndex;
                        if (descriptor.TryGetIndex(indexName, out sourceIndex))
                        {
                            operation.Add(sourceIndex, snapshot);
                        }
                        else
                        {
                            operation.Add(descriptor.UnknownIndex, snapshot);
                        }
                    }
                }

                MemoryIndex arrayIndex;
                if (!newDescriptor.TryGetIndex(indexName, out arrayIndex))
                {
                    arrayIndex = targetSnapshot.CreateIndex(indexName, arrayValue, true, false);
                }
                operation.SetTargetIndex(arrayIndex);
                addOperation(operation);
            }

            return(arrayValue);
        }