I have just updated my reposistory so instead of using a ClassHierarchyInfo type for class diagrams and a ModuleDependencyInfo type for module diagrams, now digraph types are used, coming from my container library. I had to update my container library a little to get it to work, as I had some problems with const and immutable types, but I needed to fix those issues anyway. So now class diagrams use Digraph!(const(ClassInfo)) and module diagrams use Digraph!(const(ModuleInfo*)).

I have made some implementation changes for my container library, but the API for the graphs should be the same, and it is documented here.

https://w0rp.com/project/dstruct/dstruct/graph/

So now you can play around with the graphs directly if you want, so you can say manually that module foo imports bar, when the helper functions can't figure it out. I'm not exactly sure what kind of graph you were after Andrei, as I have one thing for direct imports and another for everything transitively, but you can probably make whatever it is happen in a few ways. The actual method for it is pretty short, so I'll paste the whole thing here. (Adding an edge twice does effectively nothing, as the edges aren't weighted here.)

void addModuleWithDependencies(Dependencies strategy = Dependencies.all)
(ref ModuleGraph graph, const(ModuleInfo*) mod) {
    graph.addVertex(mod);

    // Add the imported modules.
    foreach(importedModule; mod.importedModules) {
        static if (strategy == Dependencies.all) {
            if (!graph.hasEdge(mod, importedModule)) {
                graph.addEdge(mod, importedModule);

                // Add recursive dependencies.
                graph.addModuleWithDependencies(importedModule);
            }
        } else {
            graph.addEdge(mod, importedModule);
        }
    }
}

ModuleGraph is just an alias for the Digraph type mentioned before. I think my only pain point is that there's no way, at least that I know of, to just get ModuleInfo for a given module. I have to use a foreach over all modules until I find the module I'm after. It works, though.

Reply via email to