Mercurial > projects > dil
annotate trunk/src/cmd/ImportGraph.d @ 720:74cdbb25c7c8
Using old algo for cycle detection again.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Fri, 01 Feb 2008 15:40:32 +0100 |
parents | 8f8c9ab3f3ba |
children | 90668b83ae5e |
rev | line source |
---|---|
364 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
5 module cmd.ImportGraph; | |
580
fa6d3c52757d
Moved SyntaxTree.d to new package 'ast'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
576
diff
changeset
|
6 |
fa6d3c52757d
Moved SyntaxTree.d to new package 'ast'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
576
diff
changeset
|
7 import dil.ast.Node; |
585
05c375fb2d5c
Moved dil.Declarations to dil.ast.Declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
8 import dil.ast.Declarations; |
593
2848ce3becf5
Moved dil.Module to dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
585
diff
changeset
|
9 import dil.semantic.Module; |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
10 import dil.parser.ImportParser; |
364 | 11 import dil.File; |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
12 import dil.Settings; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
13 import tango.text.Regex : RegExp = Regex; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
14 import tango.io.FilePath; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
15 import tango.io.FileConst; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
16 import tango.text.Util; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
17 import common; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
18 |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
19 alias FileConst.PathSeparatorChar dirSep; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
20 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
21 enum IGraphOption |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
22 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
23 None, |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
24 IncludeUnlocatableModules = 1, |
427
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
25 PrintDot = 1<<1, |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
26 HighlightCyclicEdges = 1<<2, |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
27 HighlightCyclicVertices = 1<<3, |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
28 GroupByPackageNames = 1<<4, |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
29 GroupByFullPackageName = 1<<5, |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
30 PrintPaths = 1<<6, |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
31 PrintList = 1<<7, |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
32 MarkCyclicModules = 1<<8, |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
33 } |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
34 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
35 class Graph |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
36 { |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
37 Vertex[] vertices; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
38 Edge[] edges; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
39 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
40 void addVertex(Vertex vertex) |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
41 { |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
42 vertex.id = vertices.length; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
43 vertices ~= vertex; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
44 } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
45 |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
46 Edge addEdge(Vertex from, Vertex to) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
47 { |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
48 auto edge = new Edge(from, to); |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
49 edges ~= edge; |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
50 from.outgoing ~= to; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
51 to.incoming ~= from; |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
52 return edge; |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
53 } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
54 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
55 /// Walks the graph and marks cyclic vertices and edges. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
56 void detectCycles() |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
57 { // Cycles could also be detected in the GraphBuilder, |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
58 // but having the code here makes things much clearer. |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
59 |
720
74cdbb25c7c8
Using old algo for cycle detection again.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
60 // Commented out because this algorithm doesn't work. |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
61 // Returns true if the vertex is in status Visiting. |
720
74cdbb25c7c8
Using old algo for cycle detection again.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
62 /+bool visit(Vertex vertex) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
63 { |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
64 switch (vertex.status) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
65 { |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
66 case Vertex.Status.Visiting: |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
67 vertex.isCyclic = true; |
699
4c0ea78a7f8b
Fixed cycle detection algorithm.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
698
diff
changeset
|
68 return true; |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
69 case Vertex.Status.None: |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
70 vertex.status = Vertex.Status.Visiting; // Flag as visiting. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
71 foreach (outVertex; vertex.outgoing) // Visit successors. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
72 vertex.isCyclic |= visit(outVertex); |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
73 vertex.status = Vertex.Status.Visited; // Flag as visited. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
74 break; |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
75 case Vertex.Status.Visited: |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
76 break; |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
77 default: |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
78 assert(0, "unknown vertex status"); |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
79 } |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
80 return false; // return (vertex.status == Vertex.Status.Visiting); |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
81 } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
82 // Start visiting vertices. |
720
74cdbb25c7c8
Using old algo for cycle detection again.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
83 visit(vertices[0]);+/ |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
84 |
720
74cdbb25c7c8
Using old algo for cycle detection again.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
85 //foreach (edge; edges) |
74cdbb25c7c8
Using old algo for cycle detection again.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
86 // if (edge.from.isCyclic && edge.to.isCyclic) |
74cdbb25c7c8
Using old algo for cycle detection again.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
87 // edge.isCyclic = true; |
74cdbb25c7c8
Using old algo for cycle detection again.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
88 |
74cdbb25c7c8
Using old algo for cycle detection again.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
89 // Use functioning algorithm. |
74cdbb25c7c8
Using old algo for cycle detection again.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
90 analyzeGraph(vertices, edges); |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
91 } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
92 } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
93 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
94 /// Represents a directed connection between two vertices. |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
95 class Edge |
370 | 96 { |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
97 Vertex from; /// Coming from vertex. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
98 Vertex to; /// Going to vertex. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
99 bool isCyclic; /// Edge connects cyclic vertices. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
100 bool isPublic; /// Public import. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
101 bool isStatic; /// Static import. |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
102 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
103 this(Vertex from, Vertex to) |
370 | 104 { |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
105 this.from = from; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
106 this.to = to; |
370 | 107 } |
108 } | |
109 | |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
110 /// Represents a module in the graph. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
111 class Vertex |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
112 { |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
113 Module modul; /// The module represented by this vertex. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
114 uint id; /// The nth vertex in the graph. |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
115 Vertex[] incoming; /// Also called predecessors. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
116 Vertex[] outgoing; /// Also called successors. |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
117 bool isCyclic; /// Whether this vertex is in a cyclic relationship with other vertices. |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
118 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
119 enum Status : ubyte |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
120 { None, Visiting, Visited } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
121 Status status; /// Used by the cycle detection algorithm. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
122 } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
123 |
703
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
124 string findModuleFilePath(string moduleFQNPath, string[] importPaths) |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
125 { |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
126 auto filePath = new FilePath(); |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
127 foreach (importPath; importPaths) |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
128 { |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
129 filePath.set(importPath); |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
130 filePath.append(moduleFQNPath); |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
131 foreach (moduleSuffix; [".d", ".di"/*interface file*/]) |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
132 { |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
133 filePath.suffix(moduleSuffix); |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
134 if (filePath.exists()) |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
135 return filePath.toString(); |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
136 } |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
137 } |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
138 return null; |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
139 } |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
140 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
141 class GraphBuilder |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
142 { |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
143 Graph graph; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
144 IGraphOption options; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
145 string[] importPaths; /// Where to look for modules. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
146 Vertex[string] loadedModulesTable; /// Maps FQN paths to modules. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
147 bool delegate(string) filterPredicate; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
148 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
149 this() |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
150 { |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
151 this.graph = new Graph; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
152 } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
153 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
154 /// Start building the graph and return that. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
155 Graph start(string fileName) |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
156 { |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
157 loadModule(fileName); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
158 return graph; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
159 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
160 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
161 /++ |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
162 Loads all modules recursively and builds the graph at the same time. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
163 Params: |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
164 moduleFQNPath = e.g.: dil/ast/Node (module FQN = dil.ast.Node) |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
165 +/ |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
166 Vertex loadModule(string moduleFQNPath) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
167 { |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
168 // Look up in table if the module is already loaded. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
169 auto pVertex = moduleFQNPath in loadedModulesTable; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
170 if (pVertex !is null) |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
171 return *pVertex; // Returns null for filtered or unlocatable modules. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
172 |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
173 // Filter out modules. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
174 if (filterPredicate && filterPredicate(moduleFQNPath)) |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
175 { // Store null for filtered modules. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
176 loadedModulesTable[moduleFQNPath] = null; |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
177 return null; |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
178 } |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
179 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
180 // Locate the module in the file system. |
703
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
181 auto moduleFilePath = findModuleFilePath(moduleFQNPath, importPaths); |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
182 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
183 Vertex vertex; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
184 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
185 if (moduleFilePath is null) |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
186 { // Module not found. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
187 if (options & IGraphOption.IncludeUnlocatableModules) |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
188 { // Include module nevertheless. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
189 vertex = new Vertex; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
190 vertex.modul = new Module(""); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
191 vertex.modul.setFQN(replace(moduleFQNPath, dirSep, '.')); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
192 graph.addVertex(vertex); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
193 } |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
194 // Store vertex in the table (vertex may be null.) |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
195 loadedModulesTable[moduleFQNPath] = vertex; |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
196 } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
197 else |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
198 { |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
199 auto modul = new Module(moduleFilePath); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
200 // Use lightweight ImportParser. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
201 modul.parser = new ImportParser(loadFile(moduleFilePath), moduleFilePath); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
202 modul.parse(); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
203 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
204 vertex = new Vertex; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
205 vertex.modul = modul; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
206 |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
207 graph.addVertex(vertex); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
208 loadedModulesTable[modul.getFQNPath()] = vertex; |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
209 |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
210 // Load the modules which this module depends on. |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
211 foreach (importDecl; modul.imports) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
212 { |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
213 foreach (moduleFQNPath2; importDecl.getModuleFQNs(dirSep)) |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
214 { |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
215 auto loaded = loadModule(moduleFQNPath2); |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
216 if (loaded !is null) |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
217 { |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
218 auto edge = graph.addEdge(vertex, loaded); |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
219 edge.isPublic = importDecl.isPublic(); |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
220 edge.isStatic = importDecl.isStatic(); |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
221 } |
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
222 } |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
223 } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
224 } |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
225 return vertex; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
226 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
227 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
228 |
703
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
229 void execute(string filePathString, string[] importPaths, string[] strRegexps, |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
230 uint levels, string siStyle, string piStyle, IGraphOption options) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
231 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
232 // Init regular expressions. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
233 RegExp[] regexps; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
234 foreach (strRegexp; strRegexps) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
235 regexps ~= new RegExp(strRegexp); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
236 |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
237 // Add directory of file and global directories to import paths. |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
238 auto filePath = new FilePath(filePathString); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
239 auto fileDir = filePath.folder(); |
719
8f8c9ab3f3ba
Fixed code that finds out a modules FQN.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
703
diff
changeset
|
240 importPaths ~= fileDir; |
370 | 241 importPaths ~= GlobalSettings.importPaths; |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
242 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
243 auto gbuilder = new GraphBuilder; |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
244 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
245 gbuilder.importPaths = importPaths; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
246 gbuilder.options = options; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
247 gbuilder.filterPredicate = (string moduleFQNPath) { |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
248 foreach (rx; regexps) |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
249 // Replace slashes: dil/ast/Node -> dil.ast.Node |
702
e10838e0b182
Fixed filter delegate in cmd.ImportGraph.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
699
diff
changeset
|
250 if (rx.test(replace(moduleFQNPath.dup, dirSep, '.'))) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
251 return true; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
252 return false; |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
253 }; |
364 | 254 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
255 auto graph = gbuilder.start(filePath.name()); |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
256 |
427
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
257 if (options & (IGraphOption.PrintList | IGraphOption.PrintPaths)) |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
258 { |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
259 if (options & IGraphOption.MarkCyclicModules) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
260 graph.detectCycles(); |
427
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
261 |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
262 if (options & IGraphOption.PrintPaths) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
263 printModulePaths(graph.vertices, levels+1, ""); |
427
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
264 else |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
265 printModuleList(graph.vertices, levels+1, ""); |
427
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
266 } |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
267 else |
703
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
268 printDotDocument(graph, siStyle, piStyle, options); |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
269 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
270 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
271 void printModulePaths(Vertex[] vertices, uint level, char[] indent) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
272 { |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
273 if (level == 0) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
274 return; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
275 foreach (vertex; vertices) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
276 { |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
277 Stdout(indent)((vertex.isCyclic?"*":"")~vertex.modul.filePath).newline; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
278 if (vertex.outgoing.length) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
279 printModulePaths(vertex.outgoing, level-1, indent~" "); |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
280 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
281 } |
370 | 282 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
283 void printModuleList(Vertex[] vertices, uint level, char[] indent) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
284 { |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
285 if (level == 0) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
286 return; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
287 foreach (vertex; vertices) |
370 | 288 { |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
289 Stdout(indent)((vertex.isCyclic?"*":"")~vertex.modul.getFQN()).newline; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
290 if (vertex.outgoing.length) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
291 printModuleList(vertex.outgoing, level-1, indent~" "); |
370 | 292 } |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
293 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
294 |
703
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
295 void printDotDocument(Graph graph, string siStyle, string piStyle, |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
296 IGraphOption options) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
297 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
298 Vertex[][string] verticesByPckgName; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
299 if (options & IGraphOption.GroupByFullPackageName) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
300 foreach (vertex; graph.vertices) |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
301 verticesByPckgName[vertex.modul.packageName] ~= vertex; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
302 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
303 if (options & (IGraphOption.HighlightCyclicVertices | |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
304 IGraphOption.HighlightCyclicEdges)) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
305 graph.detectCycles(); |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
306 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
307 // Output header of the dot document. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
308 Stdout("Digraph ImportGraph\n{\n"); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
309 // Output nodes. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
310 // 'i' and vertex.id should be the same. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
311 foreach (i, vertex; graph.vertices) |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
312 Stdout.formatln(` n{} [label="{}"{}];`, i, vertex.modul.getFQN(), (vertex.isCyclic ? ",style=filled,fillcolor=tomato" : "")); |
703
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
313 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
314 // Output edges. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
315 foreach (edge; graph.edges) |
703
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
316 { |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
317 string edgeStyles = ""; |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
318 if (edge.isStatic || edge.isPublic) |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
319 { |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
320 edgeStyles = `[style="`; |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
321 edge.isStatic && (edgeStyles ~= siStyle ~ ","); |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
322 edge.isPublic && (edgeStyles ~= piStyle); |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
323 edgeStyles[$-1] == ',' && (edgeStyles = edgeStyles[0..$-1]); // Remove last comma. |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
324 edgeStyles ~= `"]`; |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
325 } |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
326 edge.isCyclic && (edgeStyles ~= "[color=red]"); |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
327 Stdout.formatln(` n{} -> n{} {};`, edge.from.id, edge.to.id, edgeStyles); |
bf10602159c1
Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
702
diff
changeset
|
328 } |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
329 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
330 if (options & IGraphOption.GroupByFullPackageName) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
331 foreach (packageName, vertices; verticesByPckgName) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
332 { // Output nodes in a cluster. |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
333 Stdout.format(` subgraph "cluster_{}" {`\n` label="{}";color=blue;`"\n ", packageName, packageName); |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
334 foreach (vertex; vertices) |
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
335 Stdout.format(`n{};`, vertex.id); |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
336 Stdout("\n }\n"); |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
337 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
338 |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
339 Stdout("}\n"); |
364 | 340 } |
370 | 341 |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
342 // This is the old algorithm that was used to detect cycles in a directed graph. |
431
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
343 void analyzeGraph(Vertex[] vertices_init, Edge[] edges) |
370 | 344 { |
720
74cdbb25c7c8
Using old algo for cycle detection again.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
719
diff
changeset
|
345 edges = edges.dup; |
431
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
346 void recursive(Vertex[] vertices) |
370 | 347 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
348 foreach (idx, vertex; vertices) |
370 | 349 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
350 uint outgoing, incoming; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
351 foreach (j, edge; edges) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
352 { |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
353 if (edge.from is vertex) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
354 outgoing++; |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
355 if (edge.to is vertex) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
356 incoming++; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
357 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
358 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
359 if (outgoing == 0) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
360 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
361 if (incoming != 0) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
362 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
363 // Vertex is a sink. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
364 alias outgoing i; // Reuse |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
365 alias incoming j; // Reuse |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
366 // Remove edges. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
367 for (i=j=0; i < edges.length; i++) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
368 if (edges[i].to !is vertex) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
369 edges[j++] = edges[i]; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
370 edges.length = j; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
371 vertices = vertices[0..idx] ~ vertices[idx+1..$]; |
431
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
372 recursive(vertices); |
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
373 return; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
374 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
375 else |
431
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
376 { |
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
377 // Edges to this vertex were removed previously. |
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
378 // Only remove vertex now. |
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
379 vertices = vertices[0..idx] ~ vertices[idx+1..$]; |
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
380 recursive(vertices); |
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
381 return; |
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
382 } |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
383 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
384 else if (incoming == 0) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
385 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
386 // Vertex is a source |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
387 alias outgoing i; // Reuse |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
388 alias incoming j; // Reuse |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
389 // Remove edges. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
390 for (i=j=0; i < edges.length; i++) |
698
1564e41f454e
Revised modules cmd.ImportGraph and dil.semantic.Module.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
391 if (edges[i].from !is vertex) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
392 edges[j++] = edges[i]; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
393 edges.length = j; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
394 vertices = vertices[0..idx] ~ vertices[idx+1..$]; |
431
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
395 recursive(vertices); |
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
396 return; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
397 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
398 // else |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
399 // { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
400 // // source && sink |
431
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
401 // // continue loop. |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
402 // } |
370 | 403 } |
404 | |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
405 // When reaching this point it means only cylic edges and vertices are left. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
406 foreach (vertex; vertices) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
407 vertex.isCyclic = true; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
408 foreach (edge; edges) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
409 if (edge) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
410 edge.isCyclic = true; |
370 | 411 } |
431
7a6bfa569a52
Fix: analyzeGraph() should work correctly now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
427
diff
changeset
|
412 recursive(vertices_init); |
370 | 413 } |