void addTargets(List <BaseBlock> dest, ScopeBlock scopeBlock) { foreach (var block in scopeBlock.getAllBlocks()) { addTargets(dest, block.getTargets()); } }
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); }
IEnumerable <ScopeBlock> GetAllScopeBlocks(ScopeBlock scopeBlock) { var list = new List <ScopeBlock>(); list.Add(scopeBlock); list.AddRange(scopeBlock.GetAllScopeBlocks()); return(list); }
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"); } }
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)); }
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); } } }
// 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); }
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); } }
public ForwardScanOrder(ScopeBlock scopeBlock, IList <BaseBlock> sorted) { this.scopeBlock = scopeBlock; this.sorted = sorted; }
public Sorter(ScopeBlock scopeBlock, IList <BaseBlock> validBlocks, bool skipFirstBlock) { this.scopeBlock = scopeBlock; this.validBlocks = validBlocks; this.skipFirstBlock = skipFirstBlock; }
public BlockState(ScopeBlock scopeBlock) { this.scopeBlock = scopeBlock; }
void AddScopeBlock(ScopeBlock scopeBlock) { scopeBlocksToCheck.Push(scopeBlock); }
public ScopeBlockInfo(ScopeBlock scopeBlock) { this.scopeBlock = scopeBlock; }
public BlocksSorter(ScopeBlock scopeBlock) { this.scopeBlock = scopeBlock; }