1227
|
1 |
(* ID: $Id$
|
|
2 |
Author: Mateja Jamnik, University of Cambridge
|
|
3 |
Copyright 1995 University of Cambridge
|
|
4 |
|
|
5 |
Generator of the dependency charts of Isabelle theories.
|
|
6 |
*)
|
|
7 |
|
|
8 |
|
|
9 |
(* --------------------
|
|
10 |
Declaration of the variables carrying the name
|
|
11 |
of the location of source files:
|
|
12 |
|
|
13 |
path - location where the generated HTML files
|
|
14 |
should be stored
|
|
15 |
srcpath - location where the source files are stored
|
|
16 |
(ie. the graphics files)
|
|
17 |
-------------------- *)
|
|
18 |
|
|
19 |
val htmlpath = "/homes/lcp/html_isa/";
|
|
20 |
val srcpath = "/homes/lcp/Isa/Theory/";
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
(* --------------------
|
|
25 |
Notices that display the legend for every dependency
|
|
26 |
chart, and the link back to the main listing of all
|
|
27 |
theories.
|
|
28 |
-------------------- *)
|
|
29 |
|
|
30 |
val notice1 =
|
|
31 |
"<BR>\n"^"The name of the file is linked to the theory file <BR>\n";
|
|
32 |
|
|
33 |
val notice2 =
|
|
34 |
"<IMG SRC = \""^srcpath^"red_arrow.gif\" ALT = (sub)></A>\n"^
|
|
35 |
" stands for subtheories (child theories) <BR>\n"^
|
|
36 |
|
|
37 |
"<IMG SRC = \""^srcpath^"blue_arrow.gif\" ALT = (super)></A>\n"^
|
|
38 |
" stands for supertheories (parent theories) <BR>\n<BR>\n";
|
|
39 |
|
|
40 |
|
|
41 |
val back = "<A HREF = \""^htmlpath^"00-chart.html\">Back</A>\n"^
|
|
42 |
" to the original listing of all the theories. <BR>\n<HR>\n<BR>\n";
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
(* --------------------
|
|
47 |
Get a list of all theory files in Isabelle
|
|
48 |
that have been loaded.
|
|
49 |
-------------------- *)
|
|
50 |
|
|
51 |
print_depth 1000;
|
|
52 |
|
|
53 |
val theory_list = !loaded_thys;
|
|
54 |
|
|
55 |
val files = Symtab.alist_of (theory_list);
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
(* --------------------
|
|
60 |
Get a list of all theory files and their children.
|
|
61 |
-------------------- *)
|
|
62 |
|
|
63 |
fun subtheory (tname, ThyInfo{children,...}) = (tname,children);
|
|
64 |
|
|
65 |
val subtheories = map subtheory (files);
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
(* --------------------
|
|
70 |
Extract a list of all theory files only.
|
|
71 |
-------------------- *)
|
|
72 |
|
|
73 |
fun theory ( [], list ) = list
|
|
74 |
| theory ( (string, _)::rest, list ) = theory(rest, string::list);
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
(* --------------------
|
|
79 |
Use quick sort to sort the theories in
|
|
80 |
the alphabetic order. Variable a as the first
|
|
81 |
element of the list is used as a pivot value.
|
|
82 |
-------------------- *)
|
|
83 |
|
|
84 |
fun quick [] = []
|
|
85 |
| quick [x] = [x]
|
|
86 |
| quick (a::bs) = let
|
|
87 |
fun part (l,r,[]) : string list = (quick l) @ (a::quick r)
|
|
88 |
| part (l,r,x::xs) = if x<=a then part(x::l, r, xs)
|
|
89 |
else part(l, x::r, xs)
|
|
90 |
in part([], [], bs) end;
|
|
91 |
|
|
92 |
val theories = quick(theory(subtheories,[]));
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
(* --------------------
|
|
97 |
Insert the identifier of the supertheory
|
|
98 |
matrix for every row. Also insert elements
|
|
99 |
into the list of identifier's parents in
|
|
100 |
alphabetic order.
|
|
101 |
-------------------- *)
|
|
102 |
|
|
103 |
fun listins ( l, [], x:string ) = l@[x]
|
|
104 |
| listins ( l, e::r, x ) = if x>e then listins( l@[e], r, x )
|
|
105 |
else if x<>e then l@[x,e]@r
|
|
106 |
else l@[x]@r;
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
(* --------------------
|
|
111 |
Arguments:
|
|
112 |
t - accumulator of the resulting supertheory matrix
|
|
113 |
result - temporary resulting matrix (up until now)
|
|
114 |
(e,ident) - a list of identifier and its child
|
|
115 |
The child e of subtheory matrix becomes identifier ident of
|
|
116 |
the supertheory matrix. The identifier ident of subtheory
|
|
117 |
matrix becomes the parent elem of supertheory matrix.
|
|
118 |
Call function:
|
|
119 |
- listins
|
|
120 |
-------------------- *)
|
|
121 |
|
|
122 |
fun matins ( t, [], (ident:string, elem:string) ) = t@[(ident,[elem])]
|
|
123 |
| matins ( t, (x:string,y:string list)::b,
|
|
124 |
(ident:string, elem:string) ) =
|
|
125 |
if x=ident then t@[(x,listins([],y,elem))]@b
|
|
126 |
else matins (t@[(x,y)], b, (ident,elem));
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
(* --------------------
|
|
131 |
Instantiate the identifier ident, and the list of
|
|
132 |
its children (e::l), where e is its first child.
|
|
133 |
Call function:
|
|
134 |
- matins
|
|
135 |
-------------------- *)
|
|
136 |
|
|
137 |
fun rowins ( (ident, []), result ) = result
|
|
138 |
| rowins ( (ident, e::l), result ) =
|
|
139 |
rowins ( (ident, l), matins([],result,(e,ident)) );
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
(* --------------------
|
|
144 |
Extract recursively one row at a time of the
|
|
145 |
subtheory matrix.
|
|
146 |
Call function:
|
|
147 |
-rowins
|
|
148 |
-------------------- *)
|
|
149 |
|
|
150 |
fun matinv ( [], result ) = result
|
|
151 |
| matinv ( l::b, result ) = matinv( b, rowins(l, result) );
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
(* --------------------
|
|
156 |
Holds the value of supertheory matrix.
|
|
157 |
Call function:
|
|
158 |
-matinv
|
|
159 |
-------------------- *)
|
|
160 |
|
|
161 |
val supertheories = matinv ( subtheories, [] );
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
(* ---------------------------------------------------------------------- *)
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
(* --------------------
|
|
172 |
Entries for the main chart of all the theories.
|
|
173 |
Every theory name is a link to the theory definition.
|
|
174 |
Down arrow is a link to the subtheory chart of that theory.
|
|
175 |
Up arrow is a link to the supertheory chart of that theory.
|
|
176 |
-------------------- *)
|
|
177 |
|
|
178 |
fun entries x = "\n"^
|
|
179 |
"<A HREF = \""^htmlpath^x^
|
|
180 |
"_sub.html\">\n<IMG SRC = \""^srcpath^
|
|
181 |
"red_arrow.gif\" ALT = (sub)></A>\n"^
|
|
182 |
|
|
183 |
"<A HREF = \""^htmlpath^x^
|
|
184 |
"_sup.html\">\n<IMG SRC = \""^srcpath^
|
|
185 |
"blue_arrow.gif\" ALT = (super)></A> \n"^
|
|
186 |
"<A HREF = \""^htmlpath^x^".html\">"^x^"</A><BR>\n";
|
|
187 |
|
|
188 |
fun all_list x = map entries x;
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
(* --------------------
|
|
193 |
Convert a list of characters and strings
|
|
194 |
into a string.
|
|
195 |
-------------------- *)
|
|
196 |
|
|
197 |
fun join ([],res) = res
|
|
198 |
| join (x::xs,res) = join(xs,res^x);
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
val bottom =
|
|
203 |
"<HR>\n\n"^
|
|
204 |
"<! ---------------------------------------------------------------- >\n\n";
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
(* --------------------
|
|
209 |
Find the row of the matrix into which
|
|
210 |
the parent (or children) theories
|
|
211 |
are going to be inserted.
|
|
212 |
-------------------- *)
|
|
213 |
|
|
214 |
fun findline (_,[]) = []
|
|
215 |
| findline (th:string,(id,row:string list)::mat) =
|
|
216 |
if th=id then row else findline(th,mat);
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
(* --------------------
|
|
221 |
Once a parent (or child) theory has been identified
|
|
222 |
make an entry for it with appropriate indentation and with
|
|
223 |
further links to its parent (or child) dependency chart.
|
|
224 |
It contains the subfunction:
|
|
225 |
- maketableentry
|
|
226 |
-------------------- *)
|
|
227 |
|
|
228 |
fun dependencies (th, mat) =
|
|
229 |
let
|
|
230 |
val stringlist = findline(th,mat);
|
|
231 |
fun maketableentry name =
|
|
232 |
"<LI> <A HREF=\""^htmlpath^name^".html\">"^name^"</A>\n"^
|
|
233 |
" <A HREF = \""^htmlpath^name^
|
|
234 |
"_sub.html\">\n<IMG SRC = \""^srcpath^
|
|
235 |
"red_arrow.gif\" ALT = (sub)></A> \n"^
|
|
236 |
"<A HREF = \""^htmlpath^name^
|
|
237 |
"_sup.html\">\n<IMG SRC = \""^srcpath^
|
|
238 |
"blue_arrow.gif\" ALT = (super)></A>\n"^
|
|
239 |
"<UL>\n"^
|
|
240 |
join(dependencies(name,mat),"")^
|
|
241 |
"</UL>\n"
|
|
242 |
in
|
|
243 |
map maketableentry stringlist
|
|
244 |
end;
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
(* --------------------
|
|
249 |
Create individual super- and sub-theory charts for
|
|
250 |
each theory. Store them in separate files.
|
|
251 |
It contains the subfunction:
|
|
252 |
- page
|
|
253 |
-------------------- *)
|
|
254 |
|
|
255 |
fun pages ([],_,_,_) = 0
|
|
256 |
| pages (th::theories,theorymatrix,suffix,headline) =
|
|
257 |
let
|
|
258 |
fun page th =
|
|
259 |
let
|
|
260 |
|
|
261 |
(* Open files for output of individual charts. *)
|
|
262 |
|
|
263 |
val outf_each = open_out (htmlpath^th^"_"^suffix^".html")
|
|
264 |
in
|
|
265 |
|
|
266 |
(* Recursively write to the output files the *)
|
|
267 |
(* dependent theories with appropriate links *)
|
|
268 |
(* depending upon the suffix. *)
|
|
269 |
|
|
270 |
output(outf_each,
|
|
271 |
|
|
272 |
(* Heading of each dependency chart. *)
|
|
273 |
|
|
274 |
"<A NAME=\""^th^"_"^suffix^".html\"></a>\n"^
|
|
275 |
"<BR><H1>"^headline^"</H1>\n\n"^notice1^notice2^back^
|
|
276 |
"\n"^"<A HREF=\""^htmlpath^th^".html\">"^th^"</A>\n"^
|
|
277 |
(if suffix="sup"
|
|
278 |
then ("<A HREF = \""^htmlpath^th^
|
|
279 |
"_sub.html\">\n<IMG SRC = \""^srcpath^
|
|
280 |
"red_arrow.gif\" ALT = (sub)></A>\n")
|
|
281 |
else ("<A HREF = \""^htmlpath^th^
|
|
282 |
"_sup.html\">\n<IMG SRC = \""^srcpath^
|
|
283 |
"blue_arrow.gif\" ALT = (super)></A>\n"))^
|
|
284 |
"<UL>\n");
|
|
285 |
|
|
286 |
(* Recursively call the function dependencies *)
|
|
287 |
(* to create an entry in the chart for all the *)
|
|
288 |
(* levels of dependencies in the hierarchical *)
|
|
289 |
(* structure of theory files for a given *)
|
|
290 |
(* theory. *)
|
|
291 |
|
|
292 |
output(outf_each,
|
|
293 |
join(dependencies(th,theorymatrix),""));
|
|
294 |
|
|
295 |
output(outf_each,
|
|
296 |
"</UL>\n"^bottom);
|
|
297 |
|
|
298 |
(* Close for output the individual *)
|
|
299 |
(* dependency charts. *)
|
|
300 |
|
|
301 |
close_out (outf_each)
|
|
302 |
end;
|
|
303 |
in
|
|
304 |
|
|
305 |
(* Anti-bugging technique to follow the *)
|
|
306 |
(* execution of the program. *)
|
|
307 |
|
|
308 |
output(std_out,"theory: "^th^"\n");
|
|
309 |
|
|
310 |
|
|
311 |
(* The main driver for the creation of the dependencies *)
|
|
312 |
(* which calls the functions page and pages. This will *)
|
|
313 |
(* go into depth of dependency of each theory with the *)
|
|
314 |
(* appropriate indentation. *)
|
|
315 |
|
|
316 |
page(th);
|
|
317 |
pages(theories,theorymatrix,suffix,headline)
|
|
318 |
end;
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
(* ---------------------------------------------------------------------- *)
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
(* --------------------
|
|
329 |
Generate the main chart 00-chart.html containing
|
|
330 |
the listing of all the theories and the links to charts.
|
|
331 |
-------------------- *)
|
|
332 |
|
|
333 |
val outtext = htmlpath^"00-chart.html";
|
|
334 |
val outfile = open_out outtext;
|
|
335 |
|
|
336 |
val head = "<HTML>\n<HEAD>\n<TITLE>"^outtext^
|
|
337 |
"</TITLE>\n</HEAD>\n\n"^"<BODY>\n";
|
|
338 |
|
|
339 |
val title = "<H1>Dependency Diagram</H1></P>\n\n"^notice1^notice2;
|
|
340 |
val page1part1 = "<H2>Subtheories and Supertheories</H2>\n<BR>\n\n"^
|
|
341 |
join(all_list(theories),"")^"<BR>\n";
|
|
342 |
val page1part3 = bottom;
|
|
343 |
|
|
344 |
val tail = "</BODY>\n"^"</HTML>";
|
|
345 |
|
|
346 |
output(outfile,head);
|
|
347 |
output(outfile,title);
|
|
348 |
output(outfile,page1part1);
|
|
349 |
output(outfile,page1part3);
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
(* ---------------------------------------------------------------------- *)
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
(* --------------------
|
|
358 |
The main driver to create individual super- and sub-theory
|
|
359 |
charts for each individual theory. The arguments passed are:
|
|
360 |
- the list of all the theories
|
|
361 |
- the super- or sub-theory matrix
|
|
362 |
- the appropriate suffix sup or sub
|
|
363 |
- the title of the chart
|
|
364 |
It calls the function:
|
|
365 |
- pages
|
|
366 |
-------------------- *)
|
|
367 |
|
|
368 |
pages(theories,subtheories,"sub","Subtheories");
|
|
369 |
pages(theories,supertheories,"sup","Supertheories");
|
|
370 |
output(outfile,tail);
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
(* --------------------
|
|
375 |
Close file for output.
|
|
376 |
-------------------- *)
|
|
377 |
close_out(outfile);
|