# HG changeset patch # User Jari-Matti M?kel? # Date 1193263718 -10800 # Node ID 4e5b35df3060bf65b6631e9619c622a5e77131f0 # Parent f658ec4a15ddf0e7e73fe01fbbcf53ec05e27b70 Parsing bugfixes, cleaned up imports. diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/docgen.d --- a/trunk/src/docgen/docgen.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/docgen.d Thu Oct 25 01:08:38 2007 +0300 @@ -4,17 +4,16 @@ */ module docgen.docgen; -import docgen.modulegraph.writer; import docgen.sourcelisting.writers; import docgen.document.writers; import docgen.graphutils.writers; import docgen.misc.misc; import docgen.misc.parser; -import dil.Module; import tango.core.Array; import tango.io.stream.FileStream; import tango.text.Ascii; import tango.text.Util : replace; +debug import tango.io.Stdout; abstract class DefaultDocGenerator : DocGenerator { DocGeneratorOptions m_options; @@ -44,9 +43,24 @@ options.parser.rootPaths, options.parser.importPaths, null, true, -1, (char[] fqn, char[] path, Module m) { - vertices[m.moduleFQN] = new Vertex(m.moduleFQN, m.filePath, id++); + if (m is null) { + if (fqn in vertices) { + debug Stdout.format("{} already set.\n", fqn); + return; + + } + auto vertex = new Vertex(fqn, path, id++); + vertex.type = VertexType.UnlocatableModule; + vertices[fqn] = vertex; + debug Stdout.format("Setting {} = {}.\n", fqn, path); + + } else { + vertices[m.moduleFQN] = new Vertex(m.moduleFQN, m.filePath, id++); + debug Stdout.format("Setting {} = {}.\n", m.moduleFQN, m.filePath); + } }, (Module imported, Module importer) { + debug Stdout.format("Connecting {} - {}.\n", imported.moduleFQN, importer.moduleFQN); edges ~= vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]); }, modules @@ -78,7 +92,7 @@ } /** - * Generates document skeleton + * Generates document skeleton. */ void generateDoc(char[] docFileName) { auto ddf = new DefaultDocumentWriterFactory(this); @@ -98,13 +112,39 @@ } /** - * Generates documentation for modules + * Generates D language definition file. */ - void generateModules() { + void generateLangDef() { + auto docFile = new FileOutput(outPath("lstlang0.sty")); + docWriter.setOutput([docFile]); + + docWriter.generateLangDef(); + + docFile.close(); } /** - * Generates source file listings.listings + * Generates "makefile" for processing the .dot and .tex files. + */ + void generateMakeFile() { + auto docFile = new FileOutput(outPath("make.sh")); + docWriter.setOutput([docFile]); + + docWriter.generateMakeFile(); + + docFile.close(); + } + + /** + * Generates documentation for modules. + */ + void generateModules(char[] modulesFile) { + auto docFile = new FileOutput(outPath(modulesFile)); + docFile.close(); + } + + /** + * Generates source file listings. */ void generateListings(char[] listingsFile) { auto dlwf = new DefaultListingWriterFactory(this); @@ -112,9 +152,9 @@ docWriter.setOutput([docFile]); auto writer = dlwf.createListingWriter(docWriter); - modules.sort( + /*modules.sort( (Module a, Module b){ return icompare(a.moduleFQN, b.moduleFQN); } - ); + );*/ foreach(mod; modules) { auto dstFname = replace(mod.moduleFQN.dup, '.', '_') ~ ".d"; @@ -148,14 +188,19 @@ auto depGraphTexFile = "dependencies.tex"; auto depGraphFile = "depgraph.dot"; auto listingsFile = "files.tex"; + auto modulesFile = "modules.tex"; generateDoc(docFileName); if (options.listings.enableListings) generateListings(listingsFile); + generateModules(modulesFile); + generateDependencies(depGraphTexFile, depGraphFile); + generateLangDef(); + generateMakeFile(); } } @@ -167,12 +212,13 @@ options.graph.depth = 0; options.graph.nodeColor = "tomato"; options.graph.cyclicNodeColor = "red"; + options.graph.unlocatableNodeColor = "gray"; options.graph.clusterColor = "blue"; options.graph.includeUnlocatableModules = true; options.graph.highlightCyclicEdges = true; options.graph.highlightCyclicVertices = true; - options.graph.groupByPackageNames = true; - options.graph.groupByFullPackageName = true; + options.graph.groupByPackageNames = false; + options.graph.groupByFullPackageName = false; options.listings.literateStyle = true; options.listings.enableListings = true; diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/document/writer.d --- a/trunk/src/docgen/document/writer.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/document/writer.d Thu Oct 25 01:08:38 2007 +0300 @@ -13,7 +13,7 @@ import tango.io.Stdout; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; -public import dil.Module; +public import docgen.misc.parser; char[] timeNow() { auto date = Clock.toDate; @@ -47,7 +47,7 @@ const templateNames = [ "firstpage"[], "toc"[], "modules"[], "listings"[], "dependencies"[], "index"[], - "lastpage"[], + "lastpage"[], "langdef"[], "makefile"[], "graphics"[], "listing"[] ]; @@ -67,6 +67,10 @@ void generateIndexSection(); void generateLastPage(); + + void generateLangDef(); + + void generateMakeFile(); /** * Writes a tag for the given image to the output stream @@ -135,6 +139,18 @@ print.format(templates["lastpage"]); } + void generateLangDef() { + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print(templates["langdef"]); + } + + void generateMakeFile() { + auto print = new Print!(char)(new Layout!(char), outputs[0]); + + print(templates["makefile"]); + } + // --- page components void addGraphics(char[] imageFile) { diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/graphutils/dotwriter.d --- a/trunk/src/docgen/graphutils/dotwriter.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/graphutils/dotwriter.d Thu Oct 25 01:08:38 2007 +0300 @@ -5,7 +5,6 @@ module docgen.graphutils.dotwriter; import docgen.graphutils.writer; -import tango.io.FileConduit : FileConduit; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; import tango.io.FilePath; @@ -30,29 +29,29 @@ factory.options.graph.highlightCyclicEdges) findCycles(vertices, edges); - if (cast(FileConduit)imageFile.conduit) { - // name of the .dot file - char[] fn = (cast(FileConduit)imageFile.conduit).toUtf8(); - fn = FilePath(fn).file; + // name of the .dot file + char[] fn = (cast(Object)imageFile.conduit).toUtf8(); + fn = FilePath(fn).file; - fn = fn[0..$-4]; - - writer.addGraphics(fn); - } + fn = fn[0..$-4]; + + writer.addGraphics(fn); image("Digraph ModuleDependencies {\n"); - if (factory.options.graph.highlightCyclicVertices) - foreach (module_; vertices) - image.format( - ` n{0} [label="{1}"{2}];`\n, - module_.id, - module_.name, - (module_.isCyclic ? ",style=filled,fillcolor=" ~ factory.options.graph.nodeColor : "") - ); - else - foreach (i, module_; vertices) - image.format(` n{0} [label="{1}"];`, i, module_.name); + foreach (module_; vertices) + image.format( + ` n{0} [label="{1}"{2}];`\n, + module_.id, + module_.name, + (module_.isCyclic && factory.options.graph.highlightCyclicVertices ? + ",style=filled,fillcolor=" ~ factory.options.graph.nodeColor : + (module_.type == VertexType.UnlocatableModule ? + ",style=filled,fillcolor=" ~ factory.options.graph.unlocatableNodeColor : + "" + ) + ) + ); foreach (edge; edges) image.format( diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/graphutils/modulenamewriter.d --- a/trunk/src/docgen/graphutils/modulenamewriter.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/graphutils/modulenamewriter.d Thu Oct 25 01:08:38 2007 +0300 @@ -5,7 +5,6 @@ module docgen.graphutils.modulenamewriter; import docgen.graphutils.writer; -import tango.io.FileConduit : FileConduit; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; @@ -28,4 +27,4 @@ doList(vertices, factory.options.graph.depth); } -} \ No newline at end of file +} diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/graphutils/modulepathwriter.d --- a/trunk/src/docgen/graphutils/modulepathwriter.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/graphutils/modulepathwriter.d Thu Oct 25 01:08:38 2007 +0300 @@ -5,7 +5,6 @@ module docgen.graphutils.modulepathwriter; import docgen.graphutils.writer; -import tango.io.FileConduit : FileConduit; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; @@ -28,4 +27,4 @@ doPaths(vertices, factory.options.graph.depth); } -} \ No newline at end of file +} diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/graphutils/primitives.d --- a/trunk/src/docgen/graphutils/primitives.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/graphutils/primitives.d Thu Oct 25 01:08:38 2007 +0300 @@ -34,6 +34,7 @@ enum VertexType { Module, + UnlocatableModule, Package, Class, Interface, @@ -91,4 +92,4 @@ return false; } -} \ No newline at end of file +} diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/misc/misc.d --- a/trunk/src/docgen/misc/misc.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/misc/misc.d Thu Oct 25 01:08:38 2007 +0300 @@ -50,6 +50,7 @@ uint depth; char[] nodeColor = "tomato"; char[] cyclicNodeColor = "red"; + char[] unlocatableNodeColor = "gray"; char[] clusterColor = "blue"; bool includeUnlocatableModules; bool highlightCyclicEdges; diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/misc/parser.d --- a/trunk/src/docgen/misc/parser.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/misc/parser.d Thu Oct 25 01:08:38 2007 +0300 @@ -4,21 +4,17 @@ */ module docgen.misc.parser; -import docgen.graphutils.writers; - import dil.Parser; -import dil.Module; import dil.Settings; +public import dil.Module; import tango.text.Regex : RegExp = Regex; import tango.io.FilePath; -import tango.io.FileConst; import tango.text.Util; -import common; debug import tango.io.Stdout; class Parser { - private static string findModulePath(string moduleFQN, string[] importPaths) { - string modulePath; + private static char[] findModulePath(char[] moduleFQN, char[][] importPaths) { + char[] modulePath; foreach (path; importPaths) { modulePath = path ~ (path[$-1] == dirSep ? "" : [dirSep]) ~ moduleFQN ~ ".d"; @@ -52,9 +48,9 @@ * idg = Delegate that gets called for every import found * modules = List of parsed modules */ - public static void loadModules(string filePath, string[] importPaths, string[] strRegexps, + public static void loadModules(char[] filePath, char[][] importPaths, char[][] strRegexps, bool IncludeUnlocatableModules, int recursionDepth, - void delegate (string fqn, string path, Module) mdg, + void delegate (char[] fqn, char[] path, Module) mdg, void delegate (Module imported, Module importer) idg, out Module[] modules) { @@ -79,9 +75,9 @@ * idg = Delegate that gets called for every import found * modules = List of parsed modules */ - public static void loadModules(string[] filePaths, string[] importPaths, string[] strRegexps, + public static void loadModules(char[][] filePaths, char[][] importPaths, char[][] strRegexps, bool IncludeUnlocatableModules, int recursionDepth, - void delegate (string fqn, string path, Module) mdg, + void delegate (char[] fqn, char[] path, Module) mdg, void delegate (Module imported, Module importer) idg, out Module[] modules) { // Initialize regular expressions. @@ -102,9 +98,9 @@ Stdout("Import path: ")(path).newline; } - Module[string] loadedModules; + Module[char[]] loadedModules; - Module loadModule(string moduleFQNPath, int depth) { + Module loadModule(char[] moduleFQNPath, int depth) { if (depth == 0) return null; debug Stdout("Loading ")(moduleFQNPath).newline; @@ -147,8 +143,13 @@ foreach (moduleFQN_; moduleFQNs) { auto loaded_mod = loadModule(moduleFQN_, depth == -1 ? depth : depth-1); - if (loaded_mod !is null) + if (loaded_mod !is null) { idg(loaded_mod, mod); + } else { + auto tmp = new Module(null, true); + tmp.moduleFQN = replace(moduleFQN_.dup, dirSep, '.'); + idg(tmp, mod); + } } } @@ -163,4 +164,4 @@ // Ordered list of loaded modules. modules = loadedModules.values; } -} \ No newline at end of file +} diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/misc/textutils.d --- a/trunk/src/docgen/misc/textutils.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/misc/textutils.d Thu Oct 25 01:08:38 2007 +0300 @@ -4,9 +4,6 @@ */ module docgen.misc.textutils; -import tango.io.model.IConduit; -import tango.io.stream.GreedyStream; - // copied from Generate.d char[] xml_escape(char[] text) { @@ -23,16 +20,6 @@ return result; } -class XMLEscapeOutput : GreedyOutput { - this (OutputStream stream) { - super(stream); - } - - uint write (void[] src) { - return super.write( xml_escape(cast(char[])src) ); - } -} - char[] plainTextHeading(char[] s) { char[] line; line.length = 80; @@ -47,4 +34,4 @@ line[] = "-"; return line[0..l].dup ~ \n; -} \ No newline at end of file +} diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/sourcelisting/htmlwriter.d --- a/trunk/src/docgen/sourcelisting/htmlwriter.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/htmlwriter.d Thu Oct 25 01:08:38 2007 +0300 @@ -4,15 +4,10 @@ */ module docgen.sourcelisting.htmlwriter; -public import docgen.sourcelisting.writer; +import docgen.sourcelisting.writer; import docgen.misc.textutils; -import dil.Parser; -import tango.io.protocol.Writer : Writer; -import tango.io.FileConduit : FileConduit; +//import dil.Parser; import tango.io.stream.FileStream; -import tango.io.Print: Print; -import tango.text.convert.Layout : Layout; -import tango.text.stream.LineIterator; /** @@ -26,7 +21,7 @@ this.writer = writer; } - void generateListing(Parser parser) { /* TODO */ } + //void generateListing(Parser parser) { /* TODO */ } void generateListing(InputStream input, OutputStream output, char[] moduleName) { auto inputStream = cast(FileInput)input; @@ -40,4 +35,4 @@ xml_escape(content) ); } -} \ No newline at end of file +} diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/sourcelisting/latexwriter.d --- a/trunk/src/docgen/sourcelisting/latexwriter.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/latexwriter.d Thu Oct 25 01:08:38 2007 +0300 @@ -4,13 +4,9 @@ */ module docgen.sourcelisting.latexwriter; -public import docgen.sourcelisting.writer; -import dil.Parser; -import tango.io.protocol.Writer : Writer; -import tango.io.FileConduit : FileConduit; -import tango.io.Print: Print; +import docgen.sourcelisting.writer; +//import dil.Parser; import tango.io.FilePath; -import tango.text.convert.Layout : Layout; /** * Adds a code listing section for the given file. @@ -23,14 +19,14 @@ this.writer = writer; } - void generateListing(Parser parser) { /* TODO */ } + //void generateListing(Parser parser) { /* TODO */ } void generateListing(InputStream input, OutputStream output, char[] moduleName) { output.copy(input); writer.addListing( moduleName, - FilePath((cast(FileConduit)output.conduit).toUtf8()).file + FilePath((cast(Object)output.conduit).toUtf8()).file ); } } diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/sourcelisting/plaintextwriter.d --- a/trunk/src/docgen/sourcelisting/plaintextwriter.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/plaintextwriter.d Thu Oct 25 01:08:38 2007 +0300 @@ -4,13 +4,9 @@ */ module docgen.sourcelisting.plaintextwriter; -public import docgen.sourcelisting.writer; +import docgen.sourcelisting.writer; import docgen.misc.textutils; -import dil.Parser; -import tango.io.protocol.Writer : Writer; -import tango.io.FileConduit : FileConduit; -import tango.io.Print: Print; -import tango.text.convert.Layout : Layout; +//import dil.Parser; import tango.io.FilePath; /** @@ -24,14 +20,14 @@ this.writer = writer; } - void generateListing(Parser parser) { /* TODO */ } + //void generateListing(Parser parser) { /* TODO */ } void generateListing(InputStream input, OutputStream output, char[] moduleName) { output.copy(input); writer.addListing( moduleName, - FilePath((cast(FileConduit)output.conduit).toUtf8()).file + FilePath((cast(Object)output.conduit).toUtf8()).file ); } -} \ No newline at end of file +} diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/sourcelisting/writer.d --- a/trunk/src/docgen/sourcelisting/writer.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/writer.d Thu Oct 25 01:08:38 2007 +0300 @@ -6,14 +6,14 @@ public import docgen.misc.misc; public import docgen.document.writer; -import dil.Parser; +//import dil.Parser; import tango.io.model.IConduit : OutputStream, InputStream; interface ListingWriter { - void generateListing(Parser parser); + //void generateListing(Parser parser); void generateListing(InputStream input, OutputStream output, char[] moduleName); } interface ListingWriterFactory : WriterFactory { ListingWriter createListingWriter(DocumentWriter writer); -} \ No newline at end of file +} diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/sourcelisting/xmlwriter.d --- a/trunk/src/docgen/sourcelisting/xmlwriter.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/xmlwriter.d Thu Oct 25 01:08:38 2007 +0300 @@ -4,12 +4,8 @@ */ module docgen.sourcelisting.xmlwriter; -public import docgen.sourcelisting.writer; -import dil.Parser; -import tango.io.protocol.Writer : Writer; -import tango.io.FileConduit : FileConduit; -import tango.io.Print: Print; -import tango.text.convert.Layout : Layout; +import docgen.sourcelisting.writer; +//import dil.Parser; /** * TODO @@ -22,6 +18,6 @@ this.writer = writer; } - void generateListing(Parser parser) { /* TODO */ } + //void generateListing(Parser parser) { /* TODO */ } void generateListing(InputStream input, OutputStream output, char[] moduleName) { /* TODO */ } -} \ No newline at end of file +} diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/templates/default/latex/langdef.tpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/default/latex/langdef.tpl Thu Oct 25 01:08:38 2007 +0300 @@ -0,0 +1,22 @@ +%% +%% D definition (c) 2007 Jari-Matti Mäkelä +%% +\lst@definelanguage{D}% + {morekeywords={abstract,alias,align,asm,assert,auto,body,bool,break,% + byte,case,cast,catch,cdouble,cent,cfloat,char,class,const,continue,% + creal,dchar,debug,default,delegate,delete,deprecated,do,double,% + else,enum,export,extern,false,final,finally,float,for,foreach,% + foreach_reverse,function,goto,idouble,if,ifloat,import,in,inout,% + int,interface,invariant,ireal,is,lazy,long,macro,mixin,module,new,% + null,out,override,package,pragma,private,protected,public,real,ref,% + return,scope,short,static,struct,super,switch,synchronized,template,% + this,throw,true,try,typedef,typeid,typeof,ubyte,ucent,uint,ulong,% + union,unittest,ushort,version,void,volatile,wchar,while,with},% + sensitive,% + + morecomment=[s]{/*}{*/},% + morecomment=[n]{/+}{+/},% + morecomment=[l]//,% + morestring=[b]",% + morestring=[b]`% + }[keywords,comments,strings]% diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/templates/default/latex/makefile.tpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/templates/default/latex/makefile.tpl Thu Oct 25 01:08:38 2007 +0300 @@ -0,0 +1,10 @@ +#!/bin/sh + +for i in *.dot; do + F=`echo $i|sed 's/dot/ps/'` + dot $i -Tps2 -o$F + ps2pdf $F +done + +pdflatex document.tex +pdflatex document.tex diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/tests/doctemplate.d --- a/trunk/src/docgen/tests/doctemplate.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/tests/doctemplate.d Thu Oct 25 01:08:38 2007 +0300 @@ -6,9 +6,7 @@ import docgen.tests.common; import docgen.document.writers; -import tango.io.Stdout; import tango.io.FileConduit; -import tango.io.protocol.Writer : Writer; // doc template //@unittest diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/tests/graphs.d --- a/trunk/src/docgen/tests/graphs.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/tests/graphs.d Thu Oct 25 01:08:38 2007 +0300 @@ -8,7 +8,6 @@ import docgen.misc.parser; import docgen.graphutils.writers; import docgen.document.writers; -import tango.io.Stdout; import tango.io.FileConduit; import dil.Module; diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/tests/listing.d --- a/trunk/src/docgen/tests/listing.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/tests/listing.d Thu Oct 25 01:08:38 2007 +0300 @@ -8,11 +8,8 @@ import docgen.tests.common; import docgen.sourcelisting.writers; import docgen.document.writers; -import dil.Module; -import tango.io.Stdout; import tango.io.FileConduit; import tango.text.Util; -import tango.io.protocol.Writer : Writer; // doc template //@unittest diff -r f658ec4a15dd -r 4e5b35df3060 trunk/src/docgen/tests/parse.d --- a/trunk/src/docgen/tests/parse.d Wed Oct 24 22:31:38 2007 +0300 +++ b/trunk/src/docgen/tests/parse.d Thu Oct 25 01:08:38 2007 +0300 @@ -5,11 +5,9 @@ module docgen.tests.parse; import docgen.misc.parser; -import tango.io.Stdout; import tango.io.FileConduit; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; -import dil.Module; void saveToFile(char[] fname, void delegate(Print!(char) file) foo) { auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); @@ -64,4 +62,4 @@ modules ); }); -} \ No newline at end of file +}