static Segment FindFilterBlock(EHClausesArray clauses, int index) { if (clauses[index].Kind != EHClauseKind.UserFilteredHandler) { throw new ConvertionException(); } return(new Segment(clauses[index].FilterStart, clauses[index].FilterEnd)); }
static Segment FindProtectedBlock(EHClausesArray clauses, int index) { return(new Segment(clauses[index].TryStart, clauses[index].TryEnd)); }
private static void FindNextBlockStart(EHClausesArray clauses, out BlockType blockType, ref int blockStart, ref int blockEnd, out Type catchBlockType, out int index) { //given a block [blockStart,blockEnd) we search for the block [newBlockStart,newBlockEnd) such that: //1) IsBlockLater([blockStart,blockEnd) , [newBlockStart,newBlockEnd)) //2) if IsBlockLater([blockStart,blockEnd) , [newBlockStart',newBlockEnd')) // then IsBlockLater([newBlockStart,newBlockEnd) , [newBlockStart',newBlockEnd')) int newBlockStart = 1 << 30; int newBlockEnd = 1 << 30; blockType = BlockType.None; catchBlockType = null; index = -1; for (int i = 0; i < clauses.Count; i++) { EHClause c = clauses[i]; if (IsBlockLater(blockStart, blockEnd, c.TryStart, c.TryEnd) && IsBlockLater(c.TryStart, c.TryEnd, newBlockStart, newBlockEnd)) { blockType = BlockType.Try; newBlockStart = c.TryStart; newBlockEnd = c.TryEnd; index = i; } if (IsBlockLater(blockStart, blockEnd, c.HandlerStart, c.HandlerEnd) && IsBlockLater(c.HandlerStart, c.HandlerEnd, newBlockStart, newBlockEnd)) { //Andrew: mb treat filters another way... newBlockStart = c.HandlerStart; newBlockEnd = c.HandlerEnd; index = i; switch (c.Kind) { case EHClauseKind.FinallyHandler: blockType = BlockType.Finally; break; case EHClauseKind.TypeFilteredHandler: blockType = BlockType.Catch; catchBlockType = c.ClassObject; break; case EHClauseKind.FaultHandler: blockType = BlockType.Catch; break; case EHClauseKind.UserFilteredHandler: blockType = BlockType.FilteredCatch; break; } } if (c.Kind == EHClauseKind.UserFilteredHandler) { if (IsBlockLater(blockStart, blockEnd, c.FilterStart, c.FilterEnd) && IsBlockLater(c.FilterStart, c.FilterEnd, newBlockStart, newBlockEnd)) { newBlockStart = c.FilterStart; newBlockEnd = c.FilterEnd; blockType = BlockType.Filter; index = i; } } } blockStart = newBlockStart; blockEnd = newBlockEnd; }