This will create a graph from destination to source, then flipping the direction will help to traverse from top to down.
I get lost on the problem, I made sure I'll not use computer science concept to solve this problem.
to be simple,
For each identifier in the code base, trace its source. For each trace, sort it in order of code execution. For example, in case of javascript this is simple problem because there is no concurrancy.
I'm trying to solve this to create a code base refactoring tool, and one step further to automatically watch the code refactor itself. Initially I thought it was cool, but I couldnt take a step or two.