Open peckto opened 4 years ago
There is already a Visitor pattern that you can use to traverse nodes of the graph using any "strategy" that you like (bfs, dfs, etc).
See VisitorTest
for usage:
https://github.com/Fraunhofer-AISEC/cpg/blob/f0dfe140418a2f5ac7f6bbb26afa28d967b8046e/src/test/java/de/fraunhofer/aisec/cpg/enhancements/VisitorTest.java
Does that suit your needs?
Thank you for the hint! That's basically what I'm looking for.
As far as I can see, there are certain strategies defined for the visitor in Strategy.java
: walking the EOG, DFG and AST.
What I'm looking for would be a "walk all edges" strategy.
This seems not so trivial, as every Node type can have its own list of edges.
So all this lists must be walked successive to visit all Nodes in the cpg.
From my understanding, thats what codyze is doing in OverflowDatabase.java
.
Is this understanding correct?
In my opinion, the "walk all edges" strategy would be nice to have as part of the cpg library.
Yes that is what codyze is doing when persisting the graph. I think such a reflection-based visiting strategy could be incorporated into the visitor that Julian created
Graph traversal is a basic task when working with graphs. It would be helpful to have such an algorithm build into the cpg library. Ideally, the user could specify a visitor function and this function is called for every edge or vertex. To discuss: traversing by edge or by vertex?
A vertex traversal algorithm is already part of codyze: OverflowDatabase.java
Maybe we can move this to cpg?