Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AssignOperation"/> class.
        /// </summary>
        /// <param name="worker">The worker.</param>
        /// <param name="targetIndex">Index of the target.</param>
        /// <param name="memoryEntryNode">The memory entry node.</param>
        /// <param name="processAliases">if set to <c>true</c> [process aliases].</param>
        public AssignOperation(AssignWorker worker, MemoryIndex targetIndex, MemoryEntryCollectorNode memoryEntryNode, bool processAliases)
        {
            TargetIndex    = targetIndex;
            Node           = memoryEntryNode;
            Worker         = worker;
            ProcessAliases = processAliases;

            Values = new HashSet <Value>();
        }
Ejemplo n.º 2
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.º 3
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.º 4
0
        private void mergeWithEmptyAssignedArray(AssociativeArray arrayValue)
        {
            IArrayDescriptor descriptor = Worker.Structure.GetDescriptor(arrayValue);

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

                Worker.AddOperation(new MemoryIndexMayAssignOperation(Worker, index, MemoryEntryCollectorNode.GetEmptyNode(Worker.Snapshot)));
            }
            Worker.AddOperation(new MemoryIndexMayAssignOperation(Worker, descriptor.UnknownIndex, MemoryEntryCollectorNode.GetEmptyNode(Worker.Snapshot)));
        }
Ejemplo n.º 5
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.º 6
0
 protected override AssignOperation prepareOperationToIndexOfCreatedArray(MemoryIndex targetIndex, MemoryEntryCollectorNode sourceNode)
 {
     return(new UndefinedMayAssignOperation(Worker, targetIndex, sourceNode));
 }
Ejemplo n.º 7
0
 public UndefinedMayAssignOperation(AssignWorker worker, MemoryIndex targetIndex, MemoryEntryCollectorNode memoryEntryNode, bool processAliases = true)
     : base(worker, targetIndex, memoryEntryNode, processAliases)
 {
 }
Ejemplo n.º 8
0
 protected override AssignOperation prepareOperationToUnknownOfCreatedArray(MemoryIndex targetIndex, MemoryEntryCollectorNode sourceNode)
 {
     return(new MemoryIndexMustAssignOperation(Worker, targetIndex, sourceNode));
 }
Ejemplo n.º 9
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.º 10
0
        public UnknownIndexMayAssign(AssignWorker worker, MemoryIndex sourceIndex, MemoryIndex targetIndex, MemoryEntryCollectorNode memoryEntryNode, bool processAliases = true)
            : base(worker, targetIndex, memoryEntryNode, processAliases)
        {
            SourceIndex = sourceIndex;

            CreateNewIndex = true;
        }
Ejemplo n.º 11
0
 protected override AssignOperation prepareOperationToIndexOfCreatedArray(MemoryIndex targetIndex, MemoryEntryCollectorNode sourceNode)
 {
     throw new InvalidOperationException();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Prepares the operation to index of created array.
 /// </summary>
 /// <param name="targetIndex">Index of the target.</param>
 /// <param name="sourceNode">The source node.</param>
 /// <returns>New operation of the child node processed by this node.</returns>
 protected abstract AssignOperation prepareOperationToIndexOfCreatedArray(MemoryIndex targetIndex, MemoryEntryCollectorNode sourceNode);