Exemplo n.º 1
0
        /// <summary>
        /// Shift given shiftedBlock behind target, if possible
        /// </summary>
        /// <param name="shiftedBlock"></param>
        /// <param name="target"></param>
        /// <param name="view"></param>
        private bool shiftBehind(ExecutedBlock shiftedBlock, ExecutedBlock target, ExecutionView view)
        {
            //cumulative list of blocks that has to be shifted
            //It has reverse ordering of transformations that will be generated
            var shiftedBlocks = new List <ExecutedBlock>();

            shiftedBlocks.Add(shiftedBlock);

            var borderInstances = new HashSet <Instance>();

            borderInstances.UnionWith(view.AffectedInstances(shiftedBlock));

            //find all colliding blocks, so we can move them with shifted block if possible
            var currentBlock = shiftedBlock;

            while (currentBlock != target)
            {
                currentBlock = view.NextBlock(currentBlock);

                if (!canCross(currentBlock, borderInstances, view))
                {
                    //this block cannot be crossed
                    borderInstances.UnionWith(view.AffectedInstances(currentBlock));
                    shiftedBlocks.Add(currentBlock);
                }
            }

            //shifting is not possible, due to collisions between blocks
            if (!canCross(target, borderInstances, view))
            {
                return(false);
            }

            shiftedBlocks.Reverse();
            foreach (var block in shiftedBlocks)
            {
                view.ShiftBehind(block, target);
            }

            return(true);
        }
Exemplo n.º 2
0
        private void initializeScopes(ExecutionView view, ExecutedBlock earliestStart)
        {
            var current = earliestStart;

            //initialize active scope index
            var activeScopes = new Dictionary <Instance, Dictionary <VariableName, ExecutedBlock> >();

            foreach (var instance in _monitoredInstances)
            {
                if (instance.CreationBlock == null)
                {
                    //earliest start cannot be determined - we have to traverse from begining
                    current = view.EntryBlock;
                }

                activeScopes.Add(instance, new Dictionary <VariableName, ExecutedBlock>());
            }

            //search block for scopes

            ExecutedBlock lastBlock = null;

            while (current != null)
            {
                foreach (var instance in _monitoredInstances)
                {
                    var scopeStarts = view.ScopeStarts(current, instance);
                    var scopeEnds   = view.ScopeEnds(current, instance);

                    //activate new scope starts
                    var scopesIndex = activeScopes[instance];
                    foreach (var variable in scopeStarts)
                    {
                        scopesIndex[variable] = current;
                    }

                    foreach (var variable in scopeEnds)
                    {
                        ExecutedBlock scopeStart;
                        if (!scopesIndex.TryGetValue(variable, out scopeStart))
                        {
                            //there is no matching start
                            continue;
                        }

                        scopesIndex.Remove(variable);

                        if (scopeStart == current)
                        {
                            //empty scope
                            continue;
                        }

                        var scope = new InstanceScope(variable, instance, scopeStart, current);
                        _scopes.Add(instance, scope);
                    }
                }

                lastBlock = current;
                current   = view.NextBlock(current);
            }

            //handle non-closed scopes
            foreach (var instance in _monitoredInstances)
            {
                //activate new scope starts
                var scopesIndex = activeScopes[instance];

                foreach (var scopePair in scopesIndex)
                {
                    var scope = new InstanceScope(scopePair.Key, instance, scopePair.Value, lastBlock);
                    //empty scope is allowed here, because it is not closed

                    _scopes.Add(instance, scope);
                }
            }
        }