The basic algorithm is discreet:
- Translate your offer files into ASTs.
- Obtain all characteristic definitions.
- Decide the keep those capabilities are called.
- Join the dots.
Code2flow is superb for:
- Untangling spaghetti code.
- Figuring out orphaned capabilities.
- Getting contemporary developers as a lot as trip.
Code2flow will present a shimmering unprejudiced estimate of your venture’s structure. No algorithm can generate a very most attention-grabbing name graph for a dynamic language – even much less so if that language is duck-typed. Gaze the known limitations within the part below.
While you happen to build no longer maintain it already, you are going to additionally deserve to set up graphviz. Installation directions is also stumbled on here.
Moreover, counting on the language you derive to deserve to parse, that you just may perhaps additionally want to set up additional dependencies:
- Ruby: Parser
- PHP: PHP-Parser
- Python: No extra dependencies wanted
To generate a DOT file urge one thing love:
You are going to also additionally specify more than one files or import directories:
code2flow venture/itemizing/source_a.js venture/itemizing/source_b.js
code2flow venture/itemizing --language js
There are a ton of bid line alternatives, to be aware all of them, urge:
How code2flow works
Code2flow approximates the structure of tasks in dynamic languages. It’s no longer doable to generate a very most attention-grabbing callgraph for a dynamic language.
- Generate an AST of the offer code
- Recursively separate groups and nodes. Teams are files, modules, or lessons. More precisely, groups are namespaces the keep capabilities are living. Nodes are the capabilities themselves.
- For all nodes, name characteristic calls in those nodes.
- For all nodes, name in-scope variables. Strive to put those variables to explicit nodes and groups. Here’s the keep there may perhaps be just a few ambiguity within the algorithm consequently of it’s far doable to know the forms of variables in dynamic languages. So, as a change, heuristics wishes to be worn.
- For all calls in all nodes, try to derive a match from the in-scope variables. This will also be an edge.
- If a definitive match from in-scope variables can’t be stumbled on, try to derive a single match from all diverse groups and nodes.
- Neat orphaned nodes and groups.
- Output results.
Why is it no longer doable to generate a very most attention-grabbing name graph?
Take care of in mind this toy instance in Python
def func_factory(param): if param < .5: