# HG changeset patch # User Jari-Matti M?kel? # Date 1192638236 -10800 # Node ID c82b36b9cadfc5694b1cf55a0e8eb99e314b16d8 # Parent 18a8c01e3d7a7ba484596567cfe91c046cffbe69 Simpler writer hierarchy. diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/graphutils/dotwriter.d --- a/trunk/src/docgen/graphutils/dotwriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/graphutils/dotwriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -14,10 +14,9 @@ * * TODO: support changing colors / graph style? */ -class DotWriter : AbstractGraphWriter { +class DotWriter : AbstractWriter!(GraphWriterFactory, 2), GraphWriter { this(GraphWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 2, "Wrong number of outputs"); } void generateGraph(Vertex[] vertices, Edge[] edges) { diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/graphutils/modulenamewriter.d --- a/trunk/src/docgen/graphutils/modulenamewriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/graphutils/modulenamewriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -12,10 +12,9 @@ /** * TODO: add support for html/xml/latex? */ -class ModuleNameWriter : AbstractGraphWriter { +class ModuleNameWriter : AbstractWriter!(GraphWriterFactory, 1), GraphWriter { this(GraphWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 1, "Wrong number of outputs"); } void generateGraph(Vertex[] vertices, Edge[] edges) { diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/graphutils/modulepathwriter.d --- a/trunk/src/docgen/graphutils/modulepathwriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/graphutils/modulepathwriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -12,10 +12,9 @@ /** * TODO: add support for html/xml/latex? */ -class ModulePathWriter : AbstractGraphWriter { +class ModulePathWriter : AbstractWriter!(GraphWriterFactory, 1), GraphWriter { this(GraphWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 1, "Wrong number of outputs"); } void generateGraph(Vertex[] vertices, Edge[] edges) { diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/graphutils/writer.d --- a/trunk/src/docgen/graphutils/writer.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/graphutils/writer.d Wed Oct 17 19:23:56 2007 +0300 @@ -6,7 +6,6 @@ public import docgen.misc.misc; public import docgen.graphutils.primitives; -import tango.io.model.IConduit : OutputStream; debug import tango.io.Stdout; interface GraphWriter { @@ -15,61 +14,52 @@ alias void delegate(Vertex[], Edge[]) GraphWriterDg; -abstract class AbstractGraphWriter : GraphWriter { - protected GraphWriterFactory factory; - protected OutputStream[] outputs; - - this(GraphWriterFactory factory, OutputStream[] outputs) { - this.factory = factory; - this.outputs = outputs; +/** + * Marks all cycles in the graph. + * + * May have bugs, but is a bit simpler than the previous version. + */ +void findCycles(Vertex[] vertices, Edge[] edges) { + debug void p() { + foreach(e; edges) Stderr(e.type)(" "c); + Stderr.newline; } - /** - * Marks all cycles in the graph. - * - * May have bugs, but is a bit simpler than the previous version. - */ - protected static void findCycles(Vertex[] vertices, Edge[] edges) { - debug void p() { - foreach(e; edges) Stderr(e.type)(" "c); - Stderr.newline; + bool visit(Edge edge) { + if (edge.type == EdgeType.Reserved) { + edge.type = EdgeType.CyclicDependency; + debug p(); + return true; } - bool visit(Edge edge) { - if (edge.type == EdgeType.Reserved) { + bool wasCyclic = edge.isCyclic(); + edge.type = EdgeType.Reserved; + debug p(); + + foreach(edge2; edge.incoming.outgoingEdges) + if (visit(edge2)) { + if (edge.isCyclic()) { + edge.type = EdgeType.Reserved; + wasCyclic = true; + debug p(); + continue; + } edge.type = EdgeType.CyclicDependency; - debug p(); return true; } - bool wasCyclic = edge.isCyclic(); - edge.type = EdgeType.Reserved; - debug p(); + edge.type = wasCyclic ? EdgeType.CyclicDependency : EdgeType.Dependency; + debug p(); + return false; + } - foreach(edge2; edge.incoming.outgoingEdges) - if (visit(edge2)) { - if (edge.isCyclic()) { - edge.type = EdgeType.Reserved; - wasCyclic = true; - debug p(); - continue; - } - edge.type = EdgeType.CyclicDependency; - return true; - } - - edge.type = wasCyclic ? EdgeType.CyclicDependency : EdgeType.Dependency; - debug p(); - return false; - } - - foreach(vertex; vertices) - foreach(edge; vertex.outgoingEdges) - if (edge.type == EdgeType.Unspecified) { - visit(edge); - debug Stderr("*\n"); - } - } + foreach(vertex; vertices) + foreach(edge; vertex.outgoingEdges) + if (edge.type == EdgeType.Unspecified) { + visit(edge); + debug Stderr("*\n"); + } +} /+ void analyzeGraph(Vertex[] vertices, Edge[] edges) @@ -134,7 +124,6 @@ recursive(vertices); } +/ -} interface GraphWriterFactory : WriterFactory { GraphWriterDg createGraphWriter(OutputStream[] outputs); diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/misc/misc.d --- a/trunk/src/docgen/misc/misc.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/misc/misc.d Wed Oct 17 19:23:56 2007 +0300 @@ -3,6 +3,7 @@ * License: GPL3 */ module docgen.misc.misc; +import tango.io.model.IConduit : OutputStream; char[] docgen_version = "Dil document generator 0.1"; @@ -83,4 +84,18 @@ this(DocGenerator generator) { this.generator = generator; } +} + +template AbstractWriter(T, int n = -1) { + abstract class AbstractWriter { + protected T factory; + protected OutputStream[] outputs; + + this(T factory, OutputStream[] outputs) { + this.factory = factory; + this.outputs = outputs; + static if (n > -1) + assert(outputs.length == n, "Incorrect number of outputs"); + } + } } \ No newline at end of file diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/sourcelisting/htmlwriter.d --- a/trunk/src/docgen/sourcelisting/htmlwriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/htmlwriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -15,10 +15,9 @@ /** * TODO */ -class HTMLWriter : AbstractListingWriter { +class HTMLWriter : AbstractWriter!(ListingWriterFactory, 2), ListingWriter { this(ListingWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 2, "Wrong number of outputs"); } void generateListing(Parser parser) { /* TODO */ } diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/sourcelisting/latexwriter.d --- a/trunk/src/docgen/sourcelisting/latexwriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/latexwriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -15,10 +15,9 @@ /** * Adds a code listing section for the given file. */ -class LaTeXWriter : AbstractListingWriter { +class LaTeXWriter : AbstractWriter!(ListingWriterFactory, 2), ListingWriter { this(ListingWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 2, "Wrong number of outputs"); } void generateListing(Parser parser) { diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/sourcelisting/plaintextwriter.d --- a/trunk/src/docgen/sourcelisting/plaintextwriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/plaintextwriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -14,10 +14,9 @@ /** * TODO */ -class PlainTextWriter : AbstractListingWriter { +class PlainTextWriter : AbstractWriter!(ListingWriterFactory, 2), ListingWriter { this(ListingWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 2, "Wrong number of outputs"); } void generateListing(Parser parser) { /* TODO */ } diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/sourcelisting/writer.d --- a/trunk/src/docgen/sourcelisting/writer.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/writer.d Wed Oct 17 19:23:56 2007 +0300 @@ -13,16 +13,6 @@ void generateListing(InputStream input); } -abstract class AbstractListingWriter : ListingWriter { - protected ListingWriterFactory factory; - protected OutputStream[] outputs; - - this(ListingWriterFactory factory, OutputStream[] outputs) { - this.factory = factory; - this.outputs = outputs; - } -} - interface ListingWriterFactory : WriterFactory { ListingWriter createListingWriter(OutputStream[] outputs); } \ No newline at end of file diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/sourcelisting/xmlwriter.d --- a/trunk/src/docgen/sourcelisting/xmlwriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/xmlwriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -14,10 +14,9 @@ /** * TODO */ -class XMLWriter : AbstractListingWriter { +class XMLWriter : AbstractWriter!(ListingWriterFactory, 2), ListingWriter { this(ListingWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 2, "Wrong number of outputs"); } void generateListing(Parser parser) { /* TODO */ } diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/templates/htmlwriter.d --- a/trunk/src/docgen/templates/htmlwriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/templates/htmlwriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -14,10 +14,9 @@ /** * Writes a HTML document skeleton. */ -class HTMLWriter : AbstractTemplateWriter { +class HTMLWriter : AbstractWriter!(TemplateWriterFactory, 2), TemplateWriter { this(TemplateWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 1, "Wrong number of outputs"); } void generateTemplate() { diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/templates/latexwriter.d --- a/trunk/src/docgen/templates/latexwriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/templates/latexwriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -12,10 +12,9 @@ /** * Writes a LaTeX document skeleton. */ -class LaTeXWriter : AbstractTemplateWriter { +class LaTeXWriter : AbstractWriter!(TemplateWriterFactory, 1), TemplateWriter { this(TemplateWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 1, "Wrong number of outputs"); } void generateTemplate() { diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/templates/plaintextwriter.d --- a/trunk/src/docgen/templates/plaintextwriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/templates/plaintextwriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -14,10 +14,9 @@ /** * Writes a plain text document skeleton. */ -class PlainTextWriter : AbstractTemplateWriter { +class PlainTextWriter : AbstractWriter!(TemplateWriterFactory, 1), TemplateWriter { this(TemplateWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 1, "Wrong number of outputs"); } void generateTemplate() { diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/templates/writer.d --- a/trunk/src/docgen/templates/writer.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/templates/writer.d Wed Oct 17 19:23:56 2007 +0300 @@ -5,7 +5,7 @@ module docgen.templates.writer; public import docgen.misc.misc; -import tango.io.model.IConduit : OutputStream, InputStream; +import tango.io.model.IConduit : OutputStream; import tango.util.time.Date; import tango.util.time.Clock; import tango.text.convert.Sprint; @@ -14,24 +14,14 @@ void generateTemplate(); } -abstract class AbstractTemplateWriter : TemplateWriter { - protected TemplateWriterFactory factory; - protected OutputStream[] outputs; - - this(TemplateWriterFactory factory, OutputStream[] outputs) { - this.factory = factory; - this.outputs = outputs; - } - - protected static char[] timeNow() { - auto date = Clock.toDate; - auto sprint = new Sprint!(char); - return sprint.format("{0} {1} {2} {3}", - date.asDay(), - date.asMonth(), - date.day, - date.year).dup; - } +char[] timeNow() { + auto date = Clock.toDate; + auto sprint = new Sprint!(char); + return sprint.format("{0} {1} {2} {3}", + date.asDay(), + date.asMonth(), + date.day, + date.year).dup; } interface TemplateWriterFactory : WriterFactory { diff -r 18a8c01e3d7a -r c82b36b9cadf trunk/src/docgen/templates/xmlwriter.d --- a/trunk/src/docgen/templates/xmlwriter.d Wed Oct 17 18:43:29 2007 +0300 +++ b/trunk/src/docgen/templates/xmlwriter.d Wed Oct 17 19:23:56 2007 +0300 @@ -14,10 +14,9 @@ /** * TODO */ -class XMLWriter : AbstractTemplateWriter { +class XMLWriter : AbstractWriter!(TemplateWriterFactory, 1), TemplateWriter { this(TemplateWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); - assert(outputs.length == 1, "Wrong number of outputs"); } void generateTemplate() { /* TODO */ }