public static IEnumerable <TryCatchBlock> GetSelfAndDescendants(this TryCatchBlock block) { yield return(block); foreach (var d in GetDescendants(block)) { yield return(d); } }
public static IEnumerable <TryCatchBlock> GetDescendants(this TryCatchBlock block) { foreach (var kid in block.Kids.OfType <TryCatchBlock>()) { yield return(kid); foreach (var d in GetDescendants(kid)) { yield return(d); } } }
private static TryCatchBlock CreateTryBlock(ILStream code, int tryOffset, int tryLength) { int entryIndex = code.GetOffsetIndex(tryOffset); int exitIndex = GetIndex(code, tryOffset, tryLength); var tryBlock = new TryCatchBlock { EntryPoint = code[entryIndex], ExitPoint = code[exitIndex] }; return(tryBlock); }
private static TryCatchBlock EnshureTryBlock(IList <SEHBlock> blocks, int i, TryCatchBlock tryBlock, ILStream code, SEHBlock block, ICollection <TryCatchBlock> list) { if (tryBlock == null) { tryBlock = CreateTryBlock(code, block.TryOffset, block.TryLength); list.Add(tryBlock); } else { var prev = blocks[i - 1]; if (prev.TryOffset != block.TryOffset || prev.TryLength != block.TryLength) { tryBlock = CreateTryBlock(code, block.TryOffset, block.TryLength); list.Add(tryBlock); } } return(tryBlock); }
private IReadOnlyList <TryCatchBlock> TranslateSehBlocks(IMethod method, IMethodContext context, IList <SEHBlock> blocks, ILStream code) { var list = new List <TryCatchBlock>(); var handlers = new BlockList(); TryCatchBlock tryBlock = null; int n = blocks.Count; for (int i = 0; i < n; ++i) { var block = blocks[i]; tryBlock = EnshureTryBlock(blocks, i, tryBlock, code, block, list); var handler = CreateHandlerBlock(method, context, code, block); int entryIndex = code.GetOffsetIndex(block.HandlerOffset); int exitIndex = GetIndex(code, block.HandlerOffset, block.HandlerLength); handler.EntryPoint = code[entryIndex]; handler.ExitPoint = code[exitIndex]; tryBlock.Handlers.Add(handler); handlers.Add(handler); } //set parents for (int i = 0; i < list.Count; ++i) { var block = list[i]; var parent = FindParent(list, block); if (parent != null) { parent.Add(block); list.RemoveAt(i); --i; } } foreach (var block in list) { SetupInstructions(code, block); } return(list.AsReadOnlyList()); }