Statement graph (Reflector Addin)
Statement graph (Reflector Addin)
Submitted by pelikhan on Tue, 31/08/2004 - 17:40.This post presents a new Reflector Addin that creates and diplays the graph of statement inside methods: the StatementGraph. This addin is an evolution of the IL graph. (this addin is not yet available for download).

The statement graph is built from the Reflector CodeModel where each IStatement instance is a vertex and edges are added accordingly to the code "flow" (creating the edges is the most involved task). The rest of the job is handled by the QuickGraph library. When it makes sense, the vertices are clickable and you can jump to the invoked method, etc... The next step will be to update the Automatic Unit Test generator with the StatementGraph...
Let's see some simple methods and their corresponding graphs:
Simple
- Original code:
public void Simple() { Console.WriteLine("hello"); } - Decompiled:
public void Simple() { Console.WriteLine("hello"); } - Graph:

Two statements in sequence
- Original code:
public void Body() { Console.WriteLine("hello"); Console.WriteLine("world"); } - Decompiled:
public void Body() { Console.WriteLine("hello"); Console.WriteLine("world"); } - Graph:

If - Then - Else
- Original code:
public void If(int value) { if (value<0) Console.WriteLine("true"); else Console.WriteLine("false"); } - Decompiled:
public void If(int value) { if (value < 0) { Console.WriteLine("true"); return; } Console.WriteLine("false"); } - Graph:

While
- Original code:
public void While() { int i = 0; while(i<10) { Console.Write(i++); } } - Decompiled:
public void While() { int num1 = 0; while ((num1 < 10)) { Console.Write(num1++); } } - Graph:

While with break and continue
- Original code:
public void WhileBreakContinue() { int i = 0; while (i < 10) { if (i == 5) continue; if (i == 7) break; Console.Write(i++); } Console.WriteLine("Finished"); } - Decompiled:
public void WhileBreakContinue() { int num1 = 0; while ((num1 < 10)) { if (num1 == 5) { continue; } if (num1 == 7) { break; } Console.Write(num1++); } Console.WriteLine("Finished"); } - Graph:

Try - Catch
- Original code:
public void TryCatch() { try { Console.WriteLine("hello"); } catch (Exception ex) { Console.WriteLine("Boom: {0}",ex); } } - Decompiled:
public void TryCatch() { try { Console.WriteLine("hello"); } catch (Exception exception1) { Console.WriteLine("Boom: {0}", exception1); } } - Graph:

