annotate trunk/src/docgen/document/generator.d @ 457:33a4cb255fcc

Cached images, small fixes, reorganizing.
author Jari-Matti M?kel? <jmjm@iki.fi>
date Tue, 30 Oct 2007 15:41:30 +0200
parents
children 1b5f1ce09f38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
457
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
1 module docgen.document.generator;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
2
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
3 import docgen.sourcelisting.writers;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
4 import docgen.page.writers;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
5 import docgen.graphutils.writers;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
6 import docgen.misc.misc;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
7 import docgen.misc.parser;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
8 import docgen.config.configurator;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
9 import tango.core.Array;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
10 import tango.io.stream.FileStream;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
11 import tango.text.Ascii;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
12 import tango.text.Util : replace;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
13 import tango.io.FilePath;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
14 debug import tango.io.Stdout;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
15
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
16 template DefaultDocGenerator(char[] genDir) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
17 abstract class DefaultDocGenerator : DocGenerator {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
18 DocGeneratorOptions m_options;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
19 PageWriter docWriter;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
20
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
21 GraphWriterFactory graphFactory;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
22 PageWriterFactory pageFactory;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
23
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
24 Module[] modules;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
25 Edge[] edges;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
26 Vertex[char[]] vertices;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
27
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
28 this(DocGeneratorOptions options) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
29 m_options = options;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
30
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
31 createGraphWriterFactory();
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
32 createPageWriterFactory();
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
33
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
34 // create output dir
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
35 (new FilePath(options.outputDir ~ "/" ~ genDir)).create();
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
36 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
37
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
38 // TODO: constructor for situations where parsing has happened elsewhere
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
39
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
40 protected void createGraphWriterFactory() {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
41 graphFactory = new DefaultGraphWriterFactory(this);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
42 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
43
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
44 protected void createPageWriterFactory() {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
45 pageFactory = new DefaultPageWriterFactory(this);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
46 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
47
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
48 protected char[] outPath(char[] file) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
49 return options.outputDir ~ "/" ~ genDir ~ "/" ~ file;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
50 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
51
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
52 protected void parseSources() {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
53 int id = 1;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
54
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
55 Parser.loadModules(
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
56 options.parser.rootPaths,
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
57 options.parser.importPaths,
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
58 options.parser.strRegexps,
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
59 options.graph.includeUnlocatableModules,
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
60 options.graph.depth,
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
61 (char[] fqn, char[] path, Module m) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
62 if (m is null) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
63 if (fqn in vertices) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
64 debug Stdout.format("{} already set.\n", fqn);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
65 return;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
66
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
67 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
68 auto vertex = new Vertex(fqn, path, id++);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
69 vertex.type = VertexType.UnlocatableModule;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
70 vertices[fqn] = vertex;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
71 debug Stdout.format("Setting {} = {}.\n", fqn, path);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
72
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
73 } else {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
74 vertices[m.moduleFQN] = new Vertex(m.moduleFQN, m.filePath, id++);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
75 debug Stdout.format("Setting {} = {}.\n", m.moduleFQN, m.filePath);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
76 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
77 },
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
78 (Module imported, Module importer) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
79 debug Stdout.format("Connecting {} - {}.\n", imported.moduleFQN, importer.moduleFQN);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
80 edges ~= vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
81 },
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
82 modules
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
83 );
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
84
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
85 modules.sort(
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
86 (Module a, Module b){ return icompare(a.moduleFQN, b.moduleFQN); }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
87 );
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
88 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
89
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
90 void createDepGraph(char[] depGraphFile) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
91 auto imgFile = new FileOutput(outPath(depGraphFile));
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
92
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
93 auto writer = graphFactory.createGraphWriter( docWriter, GraphFormat.Dot );
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
94
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
95 writer.generateDepGraph(vertices.values, edges, imgFile);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
96
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
97 imgFile.close();
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
98 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
99
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
100 public DocGeneratorOptions *options() {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
101 return &m_options;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
102 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
103 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
104 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
105
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
106 template DefaultCachingDocGenerator(char[] genDir) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
107 abstract class DefaultCachingDocGenerator : DefaultDocGenerator!(genDir), CachingDocGenerator {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
108 this(DocGeneratorOptions options) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
109 super(options);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
110 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
111
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
112 private char[][Object[]][Object[]][GraphFormat] m_graphCache;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
113
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
114 char[] getCachedGraph(Object[] vertices, Object[] edges, GraphFormat format) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
115 auto lookup1 = format in m_graphCache;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
116 if (lookup1) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
117 auto lookup2 = edges in *lookup1;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
118 if (lookup2) {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
119 auto lookup3 = vertices in *lookup2;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
120 if (lookup3)
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
121 return *lookup3;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
122 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
123 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
124 return null;
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
125 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
126
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
127 protected void createGraphWriterFactory() {
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
128 graphFactory = new DefaultCachingGraphWriterFactory(this);
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
129 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
130 }
33a4cb255fcc Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff changeset
131 }