예제 #1
0
 void addTargets(List <BaseBlock> dest, ScopeBlock scopeBlock)
 {
     foreach (var block in scopeBlock.getAllBlocks())
     {
         addTargets(dest, block.getTargets());
     }
 }
예제 #2
0
        int RemoveDeadBlocks()
        {
            int numDeadBlocks = 0;

            var infos          = new Dictionary <ScopeBlock, ScopeBlockInfo>();
            var deadBlocksDict = new Dictionary <BaseBlock, bool>();

            foreach (var baseBlock in FindDeadBlocks())
            {
                deadBlocksDict[baseBlock] = true;
                ScopeBlock     parent = baseBlock.Parent;
                ScopeBlockInfo info;
                if (!infos.TryGetValue(parent, out info))
                {
                    infos[parent] = info = new ScopeBlockInfo(parent);
                }
                info.deadBlocks.Add(baseBlock);
                numDeadBlocks++;
            }

            foreach (var info in infos.Values)
            {
                //info.scopeBlock.RemoveAllDeadBlocks(info.deadBlocks, deadBlocksDict);
                info.scopeBlock.RemoveAllDeadBlocks(info.deadBlocks, null);
            }

            return(numDeadBlocks);
        }
예제 #3
0
        IEnumerable <ScopeBlock> GetAllScopeBlocks(ScopeBlock scopeBlock)
        {
            var list = new List <ScopeBlock>();

            list.Add(scopeBlock);
            list.AddRange(scopeBlock.GetAllScopeBlocks());
            return(list);
        }
예제 #4
0
 List <BaseBlock> updateParent(List <BaseBlock> lb, ScopeBlock parent)
 {
     foreach (var bb in lb)
     {
         bb.Parent = parent;
     }
     return(lb);
 }
        void doBaseBlock(BaseBlock bb)
        {
            BlockState current = stateStack.Peek();
            ScopeBlock newOne  = getScopeBlock(bb);

            if (newOne == null)
            {
                return;                         // Not a BaseBlock somewhere inside this ScopeBlock
            }
            if (newOne != current.scopeBlock)
            {
                bb = newOne;
            }

            bool hasVisited;

            if (!visited.TryGetValue(bb, out hasVisited))
            {
                visited[bb] = hasVisited = false;
            }
            if (hasVisited)
            {
                return;
            }
            visited[bb] = true;

            if (bb is Block)
            {
                doBlock(bb as Block);
            }
            else if (bb is TryBlock)
            {
                doTryBlock(bb as TryBlock);
            }
            else if (bb is FilterHandlerBlock)
            {
                doFilterHandlerBlock(bb as FilterHandlerBlock);
            }
            else if (bb is HandlerBlock)
            {
                doHandlerBlock(bb as HandlerBlock);
            }
            else if (bb is TryHandlerBlock)
            {
                // The try handler block is usually after the try block, but sometimes it isn't...
                // Handle that case here.
                visited.Remove(bb);
                notProcessedYet.Add(bb);
            }
            else
            {
                throw new ApplicationException("Invalid block found");
            }
        }
예제 #6
0
            public List <BaseBlock> getBlocks(ScopeBlock parent)
            {
                if (blocksLeft.Count == 0)
                {
                    return(new List <BaseBlock>());
                }
                int startIndex, endIndex;
                var lb = getBlocks(0, blocksLeft[blocksLeft.Count - 1].endInstr, out startIndex, out endIndex);

                return(updateParent(lb, parent));
            }
예제 #7
0
 void addBlocks <T>(IList <T> list, ScopeBlock scopeBlock) where T : BaseBlock
 {
     foreach (var bb in scopeBlock.getBaseBlocks())
     {
         T t = bb as T;
         if (t != null)
         {
             list.Add(t);
         }
         if (bb is ScopeBlock)
         {
             addBlocks(list, (ScopeBlock)bb);
         }
     }
 }
예제 #8
0
            // Replace the BaseBlocks with a new BaseBlock, returning the old ones.
            public List <BaseBlock> replace(int startInstr, int endInstr, ScopeBlock bb)
            {
                if (endInstr < startInstr)
                {
                    return(new List <BaseBlock>());
                }

                int startIndex, endIndex;
                var rv = getBlocks(startInstr, endInstr, out startIndex, out endIndex);

                updateParent(rv, bb);

                var bbi = new BaseBlockInfo(blocksLeft[startIndex].startInstr, blocksLeft[endIndex].endInstr, bb);

                blocksLeft.RemoveRange(startIndex, endIndex - startIndex + 1);
                blocksLeft.Insert(startIndex, bbi);

                return(rv);
            }
예제 #9
0
        void ProcessScopeBlock(ScopeBlock scopeBlock)
        {
            if (scopeBlock == null || checkedScopeBlocks.ContainsKey(scopeBlock))
            {
                return;
            }
            checkedScopeBlocks[scopeBlock] = true;
            AddBaseBlock(scopeBlock);

            if (scopeBlock is TryBlock)
            {
                var tryBlock = (TryBlock)scopeBlock;
                foreach (var handler in tryBlock.TryHandlerBlocks)
                {
                    AddScopeBlock(handler);
                }
            }
            else if (scopeBlock is TryHandlerBlock)
            {
                var tryHandlerBlock = (TryHandlerBlock)scopeBlock;
                AddScopeBlock(tryHandlerBlock.FilterHandlerBlock);
                AddScopeBlock(tryHandlerBlock.HandlerBlock);
            }
        }
예제 #10
0
 public ForwardScanOrder(ScopeBlock scopeBlock, IList <BaseBlock> sorted)
 {
     this.scopeBlock = scopeBlock;
     this.sorted     = sorted;
 }
예제 #11
0
 public Sorter(ScopeBlock scopeBlock, IList <BaseBlock> validBlocks, bool skipFirstBlock)
 {
     this.scopeBlock     = scopeBlock;
     this.validBlocks    = validBlocks;
     this.skipFirstBlock = skipFirstBlock;
 }
예제 #12
0
 public BlockState(ScopeBlock scopeBlock)
 {
     this.scopeBlock = scopeBlock;
 }
예제 #13
0
 void AddScopeBlock(ScopeBlock scopeBlock)
 {
     scopeBlocksToCheck.Push(scopeBlock);
 }
예제 #14
0
 public ScopeBlockInfo(ScopeBlock scopeBlock)
 {
     this.scopeBlock = scopeBlock;
 }
예제 #15
0
 public BlocksSorter(ScopeBlock scopeBlock)
 {
     this.scopeBlock = scopeBlock;
 }