Ejemplo n.º 1
0
        private void mergeWithEmptyAssignedArray(AssociativeArray sourceArray, AssociativeArray targetArray)
        {
            // Get descriptors
            IArrayDescriptor        sourceDescriptor        = Worker.Structure.GetDescriptor(sourceArray);
            IArrayDescriptorBuilder targetDescriptorBuilder = Worker.Structure.GetDescriptor(targetArray).Builder(Worker.Structure);

            // Create child index and merge with empty node
            foreach (var item in sourceDescriptor.Indexes)
            {
                string      name  = item.Key;
                MemoryIndex index = item.Value;

                MemoryIndex createdIndex = TargetIndex.CreateIndex(name);
                targetDescriptorBuilder.AddIndex(name, createdIndex);

                Worker.AddOperation(new UnknownIndexMayAssign(Worker, index, createdIndex, MemoryEntryCollectorNode.GetEmptyNode(Worker.Snapshot)));
            }

            // Merge unknown index with empty node (unknown index was created in array initialization - scip new array)
            UnknownIndexMayAssign toUnknownAssignOperation = new UnknownIndexMayAssign(Worker, sourceDescriptor.UnknownIndex,
                                                                                       targetDescriptorBuilder.UnknownIndex, MemoryEntryCollectorNode.GetEmptyNode(Worker.Snapshot));

            toUnknownAssignOperation.CreateNewIndex = false;
            Worker.AddOperation(toUnknownAssignOperation);

            // Build and set modified target descriptor
            Worker.Structure.SetDescriptor(targetArray, targetDescriptorBuilder.Build(Worker.Structure));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public IWriteableIndexContainer getWriteableSourceContainer()
        {
            if (builder == null)
            {
                builder = arrayDescriptor.Builder(strucure);
            }

            return(builder);
        }
Ejemplo n.º 3
0
        private void mergeWithAssignedArray(AssociativeArray sourceArray, AssociativeArray targetArray)
        {
            // Get descriptors
            IArrayDescriptor        sourceDescriptor        = Worker.Structure.GetDescriptor(sourceArray);
            IArrayDescriptorBuilder targetDescriptorBuilder = Worker.Structure.GetDescriptor(targetArray).Builder(Worker.Structure);

            // Iterate source indexes which are not present in node
            foreach (var item in sourceDescriptor.Indexes)
            {
                string      name  = item.Key;
                MemoryIndex index = item.Value;

                if (!Node.NamedChildren.ContainsKey(name))
                {
                    // Index is present in source but not in node
                    MemoryIndex createdIndex = TargetIndex.CreateIndex(name);
                    targetDescriptorBuilder.AddIndex(name, createdIndex);

                    Worker.AddOperation(new UnknownIndexMayAssign(Worker, index, createdIndex, MemoryEntryCollectorNode.GetEmptyNode(Worker.Snapshot)));
                }
            }

            // Iterate all child nodes
            foreach (var item in Node.NamedChildren)
            {
                string name = item.Key;
                MemoryEntryCollectorNode node = item.Value;

                if (sourceDescriptor.ContainsIndex(name))
                {
                    // Index is present in source and node
                    MemoryIndex createdIndex = TargetIndex.CreateIndex(name);
                    targetDescriptorBuilder.AddIndex(name, createdIndex);

                    Worker.AddOperation(new UnknownIndexMayAssign(Worker, sourceDescriptor.GetIndex(name), createdIndex, node));
                }
                else
                {
                    // Index is present in node but not in source
                    MemoryIndex createdIndex = TargetIndex.CreateIndex(name);
                    targetDescriptorBuilder.AddIndex(name, createdIndex);

                    Worker.AddOperation(new UnknownIndexMayAssign(Worker, sourceDescriptor.UnknownIndex, createdIndex, node));
                }
            }

            // Merge unknown index with unknown node (unknown index was created in array initialization - scip new array)
            UnknownIndexMayAssign toUnknownAssignOperation = new UnknownIndexMayAssign(Worker, sourceDescriptor.UnknownIndex,
                                                                                       targetDescriptorBuilder.UnknownIndex, Node.AnyChild);

            toUnknownAssignOperation.CreateNewIndex = false;
            Worker.AddOperation(toUnknownAssignOperation);

            // Build and set modified target descriptor
            Worker.Structure.SetDescriptor(targetArray, targetDescriptorBuilder.Build(Worker.Structure));
        }
Ejemplo n.º 4
0
        private void mergeWithAssignedArray(AssociativeArray arrayValue)
        {
            // Get descriptors
            IArrayDescriptor        descriptor = Worker.Structure.GetDescriptor(arrayValue);
            IArrayDescriptorBuilder builder    = Worker.Structure.GetDescriptor(arrayValue).Builder(Worker.Structure);

            // Iterate source indexes which are not present in node
            List <string> namesToRemove = new List <string>();

            foreach (var item in descriptor.Indexes)
            {
                string      name  = item.Key;
                MemoryIndex index = item.Value;

                if (!Node.NamedChildren.ContainsKey(name))
                {
                    // Index is present in source but not in node
                    Worker.AddOperation(new MemoryIndexDeleteAssignOperation(Worker, index));
                    namesToRemove.Add(name);
                }
            }

            // Safely removes nodes which are no longer used (prevents changes in lazy builder)
            foreach (string name in namesToRemove)
            {
                builder.RemoveIndex(name);
            }

            // Iterate all child nodes
            foreach (var item in Node.NamedChildren)
            {
                string name = item.Key;
                MemoryEntryCollectorNode node = item.Value;

                if (descriptor.ContainsIndex(name))
                {
                    // Index is present in source and node
                    Worker.AddOperation(new MemoryIndexMustAssignOperation(Worker, descriptor.GetIndex(name), node));
                }
                else
                {
                    // Index is present in node but not in source
                    MemoryIndex createdIndex = TargetIndex.CreateIndex(name);
                    builder.AddIndex(name, createdIndex);

                    Worker.AddOperation(new UndefinedMustAssignOperation(Worker, createdIndex, node));
                }
            }

            // Merge unknown index with unknown node (unknown index was created in array initialization - scip new array)
            Worker.AddOperation(new MemoryIndexMustAssignOperation(Worker, descriptor.UnknownIndex, Node.AnyChild));

            // Build and set modified target descriptor
            Worker.Structure.SetDescriptor(arrayValue, builder.Build(Worker.Structure));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Prepares operation for every descendant index and merge the array into one which will be
        /// stored in the target memory entry.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <returns>Array where the input arrays is merged into.</returns>
        private Value mergeArrays(MergeOperation operation)
        {
            var structure = writeableStrucure;
            IArrayDescriptorBuilder builder = Factories.StructuralContainersFactories.ArrayDescriptorFactory.CreateArrayDescriptor(writeableStrucure, null, operation.TargetIndex).Builder(structure);

            builder.SetUnknownIndex(operation.TargetIndex.CreateUnknownIndex());

            ContainerOperations collectVariables = new ContainerOperations(this, builder, operation.TargetIndex, builder.UnknownIndex);

            // Collecting possible indexes of merged array
            AssociativeArray targetArray = null;

            foreach (var operationData in operation.Indexes)
            {
                MemoryIndex index    = operationData.Item1;
                Snapshot    snapshot = operationData.Item2;

                AssociativeArray arrayValue;
                if (snapshot.Structure.Readonly.TryGetArray(index, out arrayValue))
                {
                    // Target array value will be the firs one
                    if (targetArray == null)
                    {
                        if (index.Equals(operation.TargetIndex))
                        {
                            targetArray = arrayValue;
                        }
                    }

                    IArrayDescriptor descriptor = snapshot.Structure.Readonly.GetDescriptor(arrayValue);
                    collectVariables.CollectIndexes(snapshot, index, descriptor);
                }
                else
                {
                    collectVariables.SetUndefined();
                }
            }

            if (targetArray == null)
            {
                targetArray = targetSnapshot.CreateArray();
            }
            builder.SetArrayValue(targetArray);

            collectVariables.MergeContainers();

            structure.SetArray(operation.TargetIndex, targetArray);
            structure.SetDescriptor(targetArray, builder.Build(structure));

            return(targetArray);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates the assigned array.
        /// </summary>
        /// <returns>New array which should be inserted into the node.</returns>
        protected AssociativeArray createAssignedArray()
        {
            // Creates new empty array
            AssociativeArray        arrayValue = Worker.Snapshot.CreateArray(TargetIndex);
            IArrayDescriptorBuilder builder    = Worker.Structure.GetDescriptor(arrayValue).Builder(Worker.Structure);

            // Adds nodes children into array
            foreach (var item in Node.NamedChildren)
            {
                string name = item.Key;
                MemoryEntryCollectorNode node = item.Value;

                MemoryIndex childIndex = TargetIndex.CreateIndex(name);
                builder.AddIndex(name, childIndex);
                Worker.AddOperation(prepareOperationToIndexOfCreatedArray(childIndex, node));
            }
            Worker.AddOperation(prepareOperationToUnknownOfCreatedArray(builder.UnknownIndex, Node.AnyChild));

            // Sets the updated descriptor
            Worker.Structure.SetDescriptor(arrayValue, builder.Build(Worker.Structure));
            return(arrayValue);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Tests the and create undefined children.
        /// </summary>
        /// <param name="node">The node.</param>
        private void testAndCreateUndefinedChildren(MemoryCollectorNode node)
        {
            if (node.HasUndefinedChildren)
            {
                AssociativeArray arrayValue = Structure.GetArray(node.TargetIndex);

                IArrayDescriptor        oldDescriptor = Structure.GetDescriptor(arrayValue);
                IArrayDescriptorBuilder builder       = oldDescriptor.Builder(Structure);

                foreach (var newChild in node.UndefinedChildren)
                {
                    string childName = newChild.Item1;
                    MemoryCollectorNode childNode = newChild.Item2;

                    MemoryIndex index = node.TargetIndex.CreateIndex(childName);
                    childNode.TargetIndex = index;

                    builder.AddIndex(childName, index);
                }

                IArrayDescriptor newDescriptor = builder.Build(Structure);
                Structure.SetDescriptor(arrayValue, newDescriptor);
            }
        }