Mercurial > projects > dil
annotate trunk/src/cmd/ImportGraph.d @ 391:33b566df6af4
Migrated project to Tango.
Decremented the numbers of the format placeholders in the localized messages
by one.
Replaced all instances of writef/ln with Stdout.
Added module common.d with string aliases and a global Layout!(char) instance.
Replaced %s format specifiers with index placeholders in html/xml_tags.
Changed member Information.arguments to string message.
Copied std.metastring, std.uni and std.utf from Phobos.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 15 Sep 2007 17:12:26 +0200 |
parents | 0bd21b746a04 |
children | e2bbc6406a14 |
rev | line source |
---|---|
364 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
5 module cmd.ImportGraph; | |
6 import dil.SyntaxTree; | |
7 import dil.Declarations; | |
8 import dil.Token; | |
9 import dil.Parser, dil.Lexer; | |
10 import dil.File; | |
11 import dil.Module; | |
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, |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
25 HighlightCyclicEdges = 1<<1, |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
26 HighlightCyclicVertices = 1<<2, |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
27 PrintDot = 1<<3, |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
28 PrintPaths = 1<<4, |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
29 PrintList = 1<<5, |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
30 GroupByPackageNames = 1<<6, |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
31 GroupByFullPackageName = 1<<7, |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
32 } |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
33 |
370 | 34 string findModulePath(string moduleFQN, string[] importPaths) |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
35 { |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
36 string modulePath; |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
37 foreach (path; importPaths) |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
38 { |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
39 modulePath = path ~ (path[$-1] == dirSep ? "" : [dirSep]) ~ moduleFQN ~ ".d"; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
40 // TODO: also check for *.di? |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
41 if ((new FilePath(modulePath)).exists()) |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
42 return modulePath; |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
43 } |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
44 return null; |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
45 } |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
46 |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
47 class Edge |
370 | 48 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
49 Vertex outgoing; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
50 Vertex incoming; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
51 bool isCyclic; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
52 this(Vertex o, Vertex i) |
370 | 53 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
54 this.outgoing = o; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
55 this.incoming = i; |
370 | 56 } |
57 } | |
58 | |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
59 class Vertex : Module |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
60 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
61 uint id; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
62 Vertex[] incoming; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
63 bool isCyclic; /// Whether this vertex is in a cyclic relationship with other vertices. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
64 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
65 this(string filePath) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
66 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
67 super(filePath, true); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
68 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
69 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
70 Vertex[] outgoing() |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
71 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
72 return cast(Vertex[])super.modules; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
73 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
74 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
75 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
76 void execute(string filePath, string[] importPaths, string[] strRegexps, uint levels, IGraphOption options) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
77 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
78 // Init regular expressions. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
79 RegExp[] regexps; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
80 foreach (strRegexp; strRegexps) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
81 regexps ~= new RegExp(strRegexp); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
82 |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
83 // Add directory of file and global directories to import paths. |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
84 auto fileDir = (new FilePath(filePath)).folder(); |
370 | 85 if (fileDir.length) |
86 importPaths ~= fileDir; | |
87 importPaths ~= GlobalSettings.importPaths; | |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
88 |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
89 Vertex[string] loadedModules; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
90 Vertex[] loadedModulesList; // Ordered list of loaded modules. |
370 | 91 Edge edges[]; |
364 | 92 |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
93 Vertex loadModule(string moduleFQNPath) |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
94 { |
370 | 95 auto mod_ = moduleFQNPath in loadedModules; |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
96 if (mod_ !is null) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
97 return *mod_; // Return already loaded module. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
98 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
99 // Ignore module names matching regular expressions. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
100 foreach (rx; regexps) |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
101 if (rx.test(replace(moduleFQNPath, dirSep, '.'))) |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
102 return null; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
103 |
370 | 104 auto modulePath = findModulePath(moduleFQNPath, importPaths); |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
105 Vertex mod; |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
106 if (modulePath is null) |
370 | 107 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
108 if (options & IGraphOption.IncludeUnlocatableModules) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
109 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
110 mod = new Vertex(null); |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
111 mod.setFQN(replace(moduleFQNPath, dirSep, '.')); |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
112 loadedModules[moduleFQNPath] = mod; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
113 loadedModulesList ~= mod; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
114 mod.id = loadedModulesList.length -1; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
115 } |
370 | 116 } |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
117 else |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
118 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
119 // writefln(modulePath); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
120 mod = new Vertex(modulePath); |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
121 mod.parse(); |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
122 |
370 | 123 loadedModules[moduleFQNPath] = mod; |
124 loadedModulesList ~= mod; | |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
125 mod.id = loadedModulesList.length -1; |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
126 |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
127 auto moduleFQNs = mod.getImports(); |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
128 |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
129 foreach (moduleFQN_; moduleFQNs) |
370 | 130 { |
131 auto loaded_mod = loadModule(moduleFQN_); | |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
132 if (loaded_mod !is null) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
133 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
134 edges ~= new Edge(mod, loaded_mod); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
135 mod.modules ~= loaded_mod; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
136 loaded_mod.incoming ~= mod; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
137 } |
370 | 138 } |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
139 } |
370 | 140 return mod; |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
141 } |
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
142 |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
143 auto mod = new Vertex(filePath); |
365 | 144 mod.parse(); |
364 | 145 |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
146 auto moduleFQNs = mod.getImports(); |
364 | 147 |
370 | 148 loadedModules[mod.getFQNPath()] = mod; |
149 loadedModulesList ~= mod; | |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
150 mod.id = 0; // loadedModulesList.length -1 |
370 | 151 |
367
dda55fae37de
- ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents:
366
diff
changeset
|
152 foreach (moduleFQN_; moduleFQNs) |
370 | 153 { |
154 auto loaded_mod = loadModule(moduleFQN_); | |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
155 if (loaded_mod !is null) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
156 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
157 edges ~= new Edge(mod, loaded_mod); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
158 mod.modules ~= loaded_mod; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
159 loaded_mod.incoming ~= mod; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
160 } |
370 | 161 } |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
162 // Finished loading modules. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
163 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
164 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
165 if (options & IGraphOption.PrintPaths) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
166 printPaths(loadedModulesList, levels+1, ""); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
167 else if (options & IGraphOption.PrintList) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
168 printList(loadedModulesList, levels+1, ""); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
169 else if (options & IGraphOption.PrintDot) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
170 printDot(loadedModulesList, edges, options); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
171 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
172 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
173 void printPaths(Vertex[] vertices, uint level, char[] indent) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
174 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
175 if (!level) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
176 return; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
177 foreach (vertex; vertices) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
178 { |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
179 Stdout(indent)(vertex.filePath).newline; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
180 if (vertex.outgoing.length) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
181 printPaths(vertex.outgoing, level-1, indent~" "); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
182 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
183 } |
370 | 184 |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
185 void printList(Vertex[] vertices, uint level, char[] indent) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
186 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
187 if (!level) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
188 return; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
189 foreach (vertex; vertices) |
370 | 190 { |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
191 Stdout(indent)(vertex.getFQN()).newline; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
192 if (vertex.outgoing.length) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
193 printList(vertex.outgoing, level-1, indent~" "); |
370 | 194 } |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
195 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
196 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
197 void printDot(Vertex[] loadedModulesList, Edge[] edges, IGraphOption options) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
198 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
199 Vertex[][string] verticesByPckgName; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
200 if (options & IGraphOption.GroupByFullPackageName) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
201 foreach (module_; loadedModulesList) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
202 verticesByPckgName[module_.packageName] ~= module_; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
203 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
204 if (options & (IGraphOption.HighlightCyclicVertices | |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
205 IGraphOption.HighlightCyclicEdges)) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
206 analyzeGraph(loadedModulesList, edges.dup); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
207 |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
208 Stdout("Digraph ModuleDependencies\n{\n"); |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
209 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
210 if (options & IGraphOption.HighlightCyclicVertices) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
211 foreach (i, module_; loadedModulesList) |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
212 Stdout.format(` n{0} [label="{1}"{2}];`, i, module_.getFQN(), (module_.isCyclic ? ",style=filled,fillcolor=tomato" : "")).newline; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
213 else |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
214 foreach (i, module_; loadedModulesList) |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
215 Stdout.format(` n{0} [label="{1}"];`, i, module_.getFQN()).newline; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
216 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
217 foreach (edge; edges) |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
218 Stdout.format(` n{0} -> n{1}{2};`, edge.outgoing.id, edge.incoming.id, (edge.isCyclic ? "[color=red]" : "")).newline; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
219 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
220 if (options & IGraphOption.GroupByFullPackageName) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
221 foreach (packageName, vertices; verticesByPckgName) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
222 { |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
223 Stdout.format(` subgraph "cluster_{0}" {`\n` label="{1}";color=blue;`"\n ", packageName, packageName); |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
224 foreach (module_; vertices) |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
225 Stdout.format(`n{0};`, module_.id); |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
226 Stdout("\n }\n"); |
375
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 |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
229 Stdout("}\n"); |
364 | 230 } |
370 | 231 |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
232 void analyzeGraph(Vertex[] vertices, Edge[] edges) |
370 | 233 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
234 void recursive(Vertex[] modules) |
370 | 235 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
236 foreach (idx, vertex; vertices) |
370 | 237 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
238 uint outgoing, incoming; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
239 foreach (j, edge; edges) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
240 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
241 if (edge.outgoing is vertex) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
242 outgoing++; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
243 if (edge.incoming is vertex) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
244 incoming++; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
245 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
246 |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
247 if (outgoing == 0) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
248 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
249 if (incoming != 0) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
250 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
251 // Vertex is a sink. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
252 alias outgoing i; // Reuse |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
253 alias incoming j; // Reuse |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
254 // Remove edges. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
255 for (i=j=0; i < edges.length; i++) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
256 if (edges[i].incoming !is vertex) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
257 edges[j++] = edges[i]; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
258 edges.length = j; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
259 vertices = vertices[0..idx] ~ vertices[idx+1..$]; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
260 return recursive(modules); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
261 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
262 else |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
263 assert(0, "orphaned module: "~vertex.getFQN()~" (has no edges in graph)"); // orphaned vertex (module) in graph |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
264 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
265 else if (incoming == 0) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
266 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
267 // Vertex is a source |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
268 alias outgoing i; // Reuse |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
269 alias incoming j; // Reuse |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
270 // Remove edges. |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
271 for (i=j=0; i < edges.length; i++) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
272 if (edges[i].outgoing !is vertex) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
273 edges[j++] = edges[i]; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
274 edges.length = j; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
275 vertices = vertices[0..idx] ~ vertices[idx+1..$]; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
276 return recursive(modules); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
277 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
278 // else |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
279 // { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
280 // // source && sink |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
281 // } |
370 | 282 } |
283 | |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
284 // 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
|
285 foreach (vertex; vertices) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
286 vertex.isCyclic = true; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
287 foreach (edge; edges) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
288 if (edge) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
289 edge.isCyclic = true; |
370 | 290 } |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
370
diff
changeset
|
291 recursive(vertices); |
370 | 292 } |