annotate trunk/src/cmd/ImportGraph.d @ 367:dda55fae37de

- ImportGraph.execute() can parse all modules depending on the imports of the root module. - Added function findModule(). - Renamed option includes to import_paths. - Fix in ctor of ModuleDeclaration: check for pname.length before removing last separator. - Fixed scanning binary numbers. - Added member modules and method getFQN() to class Module. - Fix in parseIfStatement(): AttributeStatement mustn't have a null parameter. - Parsing import_paths in GlobalSettings.load().
author aziz
date Fri, 31 Aug 2007 23:07:05 +0000
parents dcbd3bf9bf74
children 2adf808343d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
364
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
1 /++
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
2 Author: Aziz Köksal
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
3 License: GPL3
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
4 +/
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
5 module cmd.ImportGraph;
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
6 import dil.SyntaxTree;
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
7 import dil.Declarations;
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
8 import dil.Token;
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
9 import dil.Parser, dil.Lexer;
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
10 import dil.File;
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
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;
366
dcbd3bf9bf74 - Added command importgraph/igraph to main.d.
aziz
parents: 365
diff changeset
13 import std.stdio : writefln;
367
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
14 import std.path : getDirName, dirSep = sep;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
15 import std.file : exists;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
16
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
17 string findModule(string moduleFQN, string[] importPaths)
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
18 {
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
19 string modulePath;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
20 foreach (path; importPaths)
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
21 {
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
22 modulePath = path ~ (path[$-1] == dirSep[0] ? "" : dirSep) ~ moduleFQN ~ ".d";
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
23 if (exists(modulePath))
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
24 return modulePath;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
25 }
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
26 return null;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
27 }
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
28
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
29 void execute(string fileName, string[] importPaths)
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
30 {
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
31 // Add directory of file and global directories to import paths.
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
32 importPaths ~= getDirName(fileName) ~ GlobalSettings.importPaths;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
33
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
34 Module[string] loadedModules;
364
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
35
367
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
36 Module loadModule(string moduleFQN)
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
37 {
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
38 auto mod_ = moduleFQN in loadedModules;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
39 if (mod_ !is null)
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
40 return *mod_;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
41
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
42 auto modulePath = findModule(moduleFQN, importPaths);
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
43 if (modulePath is null)
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
44 writefln("Warning: Module %s.d couldn't be found.", moduleFQN);
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
45 else
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
46 {
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
47 auto mod = new Module(modulePath);
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
48 mod.parse();
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
49
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
50 loadedModules[moduleFQN] = mod;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
51
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
52 auto moduleFQNs = mod.getImports();
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
53
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
54 foreach (moduleFQN_; moduleFQNs)
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
55 mod.modules ~= loadModule(moduleFQN_);
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
56 return mod;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
57 }
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
58 return null;
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
59 }
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
60
364
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
61 auto mod = new Module(fileName);
365
ed67acc82268 - Added option includes to config.d.
aziz
parents: 364
diff changeset
62 mod.parse();
364
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
63
367
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
64 auto moduleFQNs = mod.getImports();
364
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
65
367
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
66 foreach (moduleFQN_; moduleFQNs)
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
67 mod.modules ~= loadModule(moduleFQN_);
364
1059295c2727 - Every command module has an execute method now.
aziz
parents:
diff changeset
68 }