# HG changeset patch # User Jari-Matti M?kel? # Date 1202067520 -7200 # Node ID 231c9a44ba8eddad1bce7fd4d879b8f76715e66d # Parent 5cb236c6fe52b1c5d7ea53fbdf68837397fda9c2 Switch to ImportParser. diff -r 5cb236c6fe52 -r 231c9a44ba8e trunk/src/docgen/misc/parser.d --- a/trunk/src/docgen/misc/parser.d Sun Feb 03 18:59:34 2008 +0100 +++ b/trunk/src/docgen/misc/parser.d Sun Feb 03 21:38:40 2008 +0200 @@ -5,6 +5,8 @@ module docgen.misc.parser; import dil.parser.Parser; +import dil.parser.ImportParser; +import dil.File; import dil.Settings; public import dil.semantic.Module; import tango.text.Regex : RegExp = Regex; @@ -13,26 +15,26 @@ debug import tango.io.Stdout; alias void delegate (char[] fqn, char[] path, Module module_) modDg; -alias void delegate (Module imported, Module importer, bool isPublic) importDg; +alias void delegate (Module imported, Module importer, bool isPublic, bool isStatic) importDg; class Parser { private: - static char[] findModulePath(char[] moduleFQN, char[][] importPaths) { - char[] modulePath; - - foreach (path; importPaths) { - modulePath = path ~ (path[$-1] == dirSep ? "" : [dirSep]) ~ moduleFQN ~ ".d"; + static char[] findModuleFilePath(char[] moduleFQNPath, char[][] importPaths) { + auto filePath = new FilePath(); + foreach (importPath; importPaths) { + filePath.set(importPath); + filePath.append(moduleFQNPath); - // TODO: also check for *.di? - - if ((new FilePath(modulePath)).exists()) { - debug Stdout(" * File for ")(moduleFQN)(" found: ")(modulePath).newline; - return modulePath; + foreach (moduleSuffix; [".d", ".di"/*interface file*/]) + { + filePath.suffix(moduleSuffix); + if (filePath.exists()) + return filePath.toString(); } } - debug Stdout(" * ")(moduleFQN)(" does not exist in imports")().newline()(); + debug Stdout(" * ")(moduleFQNPath)(" does not exist in imports\n")(); return null; } @@ -56,8 +58,8 @@ * modules = List of parsed modules */ static void loadModules(char[] filePath, char[][] importPaths, char[][] strRegexps, - bool IncludeUnlocatableModules, int recursionDepth, - modDg mdg, importDg idg, out Module[] modules) { + bool IncludeUnlocatableModules, int recursionDepth, + modDg mdg, importDg idg, out Module[] modules) { loadModules([filePath], importPaths, strRegexps, IncludeUnlocatableModules, recursionDepth, mdg, idg, modules); @@ -81,8 +83,9 @@ * modules = List of parsed modules */ static void loadModules(char[][] filePaths, char[][] importPaths, char[][] strRegexps, - bool IncludeUnlocatableModules, int recursionDepth, - modDg mdg, importDg idg, out Module[] modules) { + bool IncludeUnlocatableModules, int recursionDepth, + modDg mdg, importDg idg, out Module[] modules) { + // Initialize regular expressions. RegExp[] regexps; foreach (strRegexp; strRegexps) @@ -121,33 +124,34 @@ foreach (rx; regexps) if (rx.test(FQN)) return null; - auto modulePath = findModulePath(moduleFQNPath, importPaths); + auto moduleFilePath = findModuleFilePath(moduleFQNPath, importPaths); //foreach(filePath; filePaths) //if (moduleFQNPath == filePath) modulePath = filePath; debug Stdout(" FQN ")(FQN).newline; - debug Stdout(" Module path ")(modulePath).newline; + debug Stdout(" Module path ")(moduleFilePath).newline; Module mod = null; - if (modulePath is null) { + if (moduleFilePath is null) { if (IncludeUnlocatableModules) mdg(FQN, moduleFQNPath, null); } else { - mod = new Module(modulePath); - loadedModules[moduleFQNPath] = mod; + mod = new Module(moduleFilePath); + + // Use lightweight ImportParser. + mod.parser = new ImportParser(loadFile(moduleFilePath), moduleFilePath); mod.parse(); mdg(FQN, moduleFQNPath, mod); - - auto imports = mod.imports; + loadedModules[moduleFQNPath] = mod; - foreach (importList; imports) - foreach(moduleFQN_; importList.getModuleFQNs(dirSep)) { + foreach (importDecl; mod.imports) + foreach(moduleFQN_; importDecl.getModuleFQNs(dirSep)) { auto loaded_mod = loadModule(moduleFQN_, depth == -1 ? depth : depth-1); if (loaded_mod !is null) { - idg(loaded_mod, mod, importList.isPublic()); + idg(loaded_mod, mod, importDecl.isPublic(), importDecl.isStatic()); } else if (IncludeUnlocatableModules) {/* FIXME auto tmp = new Module(null, true); tmp.moduleFQN = replace(moduleFQN_.dup, dirSep, '.'); diff -r 5cb236c6fe52 -r 231c9a44ba8e trunk/src/docgen/tests/graphs.d --- a/trunk/src/docgen/tests/graphs.d Sun Feb 03 18:59:34 2008 +0100 +++ b/trunk/src/docgen/tests/graphs.d Sun Feb 03 21:38:40 2008 +0200 @@ -135,9 +135,10 @@ (char[] fqn, char[] path, Module m) { vertices[m.moduleFQN] = new DepGraph.Vertex(m.moduleFQN, m.filePath, id++); }, - (Module imported, Module importer, bool isPublic) { + (Module imported, Module importer, bool isPublic, bool isStatic) { auto edge = vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]); edge.isPublic = isPublic; + edge.isStatic = isStatic; edges ~= edge; }, modules diff -r 5cb236c6fe52 -r 231c9a44ba8e trunk/src/docgen/tests/listing.d --- a/trunk/src/docgen/tests/listing.d Sun Feb 03 18:59:34 2008 +0100 +++ b/trunk/src/docgen/tests/listing.d Sun Feb 03 21:38:40 2008 +0200 @@ -29,7 +29,7 @@ [ "c" ], [ "docgen/teststuff/" ], null, true, -1, (char[] fqn, char[] path, Module m) {}, - (Module imported, Module importer, bool isPublic) {}, + (Module imported, Module importer, bool isPublic, bool isStatic) {}, modules ); diff -r 5cb236c6fe52 -r 231c9a44ba8e trunk/src/docgen/tests/parse.d --- a/trunk/src/docgen/tests/parse.d Sun Feb 03 18:59:34 2008 +0100 +++ b/trunk/src/docgen/tests/parse.d Sun Feb 03 21:38:40 2008 +0200 @@ -30,7 +30,7 @@ (char[] fqn, char[] path, Module m) { file.format("{0} = {1}\n", fqn, path); }, - (Module imported, Module importer, bool isPublic) { + (Module imported, Module importer, bool isPublic, bool isStatic) { file.format("{0} <- {1}\n", imported ? imported.moduleFQN : "null"[], importer ? importer.moduleFQN : "null"[] @@ -53,7 +53,7 @@ (char[] fqn, char[] path, Module m) { file.format("{0} = {1}\n", fqn, path); }, - (Module imported, Module importer, bool isPublic) { + (Module imported, Module importer, bool isPublic, bool isStatic) { file.format("{0} <- {1}\n", imported ? imported.moduleFQN : "null"[], importer ? importer.moduleFQN : "null"[] diff -r 5cb236c6fe52 -r 231c9a44ba8e trunk/src/docgen/testsuite.d --- a/trunk/src/docgen/testsuite.d Sun Feb 03 18:59:34 2008 +0100 +++ b/trunk/src/docgen/testsuite.d Sun Feb 03 21:38:40 2008 +0200 @@ -17,17 +17,26 @@ * */ void main() { - Stdout("Running.."); + Stdout("Running..\n")(); + Stdout(" Test1\n")(); graph1(); + Stdout(" Test2\n")(); graph2(); + Stdout(" Test3\n")(); graph3(); + Stdout(" Test4\n")(); graph4(); + Stdout(" Test5\n")(); graph5(); + Stdout(" Test6\n")(); parse1(); + Stdout(" Test7\n")(); parse2(); + Stdout(" Test8\n")(); doctemplate1(); + Stdout(" Test9\n")(); listing1(); // loadConfig(); - Stdout("done.\n"); + Stdout("done.\n")(); }