author | clasohm |
Tue, 21 Nov 1995 12:36:31 +0100 | |
changeset 1348 | b9305143fa91 |
parent 1332 | a60d1abb06c0 |
child 1359 | 71124bd19b40 |
permissions | -rw-r--r-- |
391 | 1 |
(* Title: Pure/Thy/thy_read.ML |
2 |
ID: $Id$ |
|
559 | 3 |
Author: Carsten Clasohm and Markus Wenzel and Sonia Mahjoub and |
4 |
Tobias Nipkow and L C Paulson |
|
5 |
Copyright 1994 TU Muenchen |
|
391 | 6 |
|
1242 | 7 |
Functions for reading theory files, and storing and retrieving theories, |
8 |
theorems and the global simplifier set. |
|
391 | 9 |
*) |
10 |
||
1157 | 11 |
(*Type for theory storage*) |
1291 | 12 |
datatype thy_info = |
13 |
ThyInfo of {path: string, |
|
14 |
children: string list, parents: string list, |
|
15 |
thy_time: string option, ml_time: string option, |
|
16 |
theory: theory option, thms: thm Symtab.table, |
|
17 |
thy_ss: Simplifier.simpset option, |
|
18 |
simpset: Simplifier.simpset option}; |
|
1157 | 19 |
(*meaning of special values: |
20 |
thy_time, ml_time = None theory file has not been read yet |
|
21 |
= Some "" theory was read but has either been marked |
|
22 |
as outdated or there is no such file for |
|
23 |
this theory (see e.g. 'virtual' theories |
|
24 |
like Pure or theories without a ML file) |
|
25 |
theory = None theory has not been read yet |
|
1291 | 26 |
|
27 |
parents: While 'children' contains all theories the theory depends |
|
28 |
on (i.e. also ones quoted in the .thy file), |
|
29 |
'parents' only contains the theories which were used to form |
|
30 |
the base of this theory. |
|
31 |
||
32 |
origin of the simpsets: |
|
33 |
thy_ss: snapshot of !Simpset.simpset after .thy file was read |
|
34 |
simpset: snapshot of !Simpset.simpset after .ML file was read |
|
1157 | 35 |
*) |
391 | 36 |
|
412 | 37 |
signature READTHY = |
391 | 38 |
sig |
39 |
datatype basetype = Thy of string |
|
40 |
| File of string |
|
41 |
||
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
42 |
val loaded_thys : thy_info Symtab.table ref |
391 | 43 |
val loadpath : string list ref |
44 |
val delete_tmpfiles: bool ref |
|
45 |
||
46 |
val use_thy : string -> unit |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
47 |
val time_use_thy : string -> unit |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
48 |
val use_dir : string -> unit |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
49 |
val exit_use_dir : string -> unit |
391 | 50 |
val update : unit -> unit |
51 |
val unlink_thy : string -> unit |
|
586
201e115d8031
renamed base_on into mk_base and moved it to the beginning of the generated
clasohm
parents:
559
diff
changeset
|
52 |
val mk_base : basetype list -> string -> bool -> theory |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
53 |
val store_theory : theory * string -> unit |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
54 |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
55 |
val theory_of_sign : Sign.sg -> theory |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
56 |
val theory_of_thm : thm -> theory |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
57 |
val children_of : string -> string list |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
58 |
val parents_of : string -> string list |
1291 | 59 |
|
559 | 60 |
val store_thm: string * thm -> thm |
758 | 61 |
val bind_thm: string * thm -> unit |
559 | 62 |
val qed: string -> unit |
758 | 63 |
val qed_thm: thm ref |
746 | 64 |
val qed_goal: string -> theory -> string -> (thm list -> tactic list) -> unit |
65 |
val qed_goalw: string -> theory->thm list->string->(thm list->tactic list) |
|
66 |
-> unit |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
67 |
val get_thm : theory -> string -> thm |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
68 |
val thms_of : theory -> (string * thm) list |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
69 |
val simpset_of : string -> Simplifier.simpset |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
70 |
val print_theory : theory -> unit |
1291 | 71 |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
72 |
val base_path : string ref |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
73 |
val gif_path : string ref |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
74 |
val index_path : string ref |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
75 |
val pure_subchart : string option ref |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
76 |
val make_html : bool ref |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
77 |
val init_html : unit -> unit |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
78 |
val make_chart : unit -> unit |
391 | 79 |
end; |
80 |
||
81 |
||
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
82 |
functor ReadthyFun(structure ThySyn: THY_SYN and ThmDB: THMDB): READTHY = |
391 | 83 |
struct |
1242 | 84 |
|
85 |
open ThmDB Simplifier; |
|
391 | 86 |
|
87 |
datatype basetype = Thy of string |
|
88 |
| File of string; |
|
89 |
||
1291 | 90 |
val loaded_thys = |
91 |
ref (Symtab.make [("ProtoPure", |
|
92 |
ThyInfo {path = "", |
|
93 |
children = ["Pure", "CPure"], parents = [], |
|
94 |
thy_time = Some "", ml_time = Some "", |
|
95 |
theory = Some proto_pure_thy, thms = Symtab.null, |
|
96 |
thy_ss = None, simpset = None}), |
|
97 |
("Pure", |
|
98 |
ThyInfo {path = "", children = [], |
|
99 |
parents = ["ProtoPure"], |
|
100 |
thy_time = Some "", ml_time = Some "", |
|
101 |
theory = Some pure_thy, thms = Symtab.null, |
|
102 |
thy_ss = None, simpset = None}), |
|
103 |
("CPure", |
|
104 |
ThyInfo {path = "", |
|
105 |
children = [], parents = ["ProtoPure"], |
|
106 |
thy_time = Some "", ml_time = Some "", |
|
107 |
theory = Some cpure_thy, |
|
108 |
thms = Symtab.null, |
|
109 |
thy_ss = None, simpset = None}) |
|
110 |
]); |
|
391 | 111 |
|
1291 | 112 |
val loadpath = ref ["."]; (*default search path for theory files*) |
113 |
||
114 |
val delete_tmpfiles = ref true; (*remove temporary files after use*) |
|
115 |
||
391 | 116 |
|
1291 | 117 |
(*Set location of graphics for HTML files |
118 |
(When this is executed for the first time we are in $ISABELLE/Pure/Thy. |
|
119 |
This path is converted to $ISABELLE/Tools by removing the last two |
|
120 |
directories and appending "Tools". All subsequently made ReadThy |
|
121 |
structures inherit this value.) |
|
122 |
*) |
|
123 |
val gif_path = ref (tack_on ("/" ^ |
|
124 |
space_implode "/" (rev (tl (tl (rev (space_explode "/" (pwd ()))))))) |
|
125 |
"Tools"); |
|
126 |
||
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
127 |
(*Path of Isabelle's main directory*) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
128 |
val base_path = ref ( |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
129 |
"/" ^ space_implode "/" (rev (tl (tl (rev (space_explode "/" (pwd ()))))))); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
130 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
131 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
132 |
(** HTML variables **) |
1291 | 133 |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
134 |
(*Location of .theory-list.txt and index.html (set by init_html)*) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
135 |
val index_path = ref ""; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
136 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
137 |
(*Location of .Pure_sub.html and .CPure_sub.html*) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
138 |
val pure_subchart = ref (None : string option); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
139 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
140 |
(*Controls whether HTML files should be generated*) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
141 |
val make_html = ref false; |
1291 | 142 |
|
143 |
(*HTML file of theory currently being read |
|
144 |
(Initialized by thyfile2html; used by use_thy and store_thm)*) |
|
145 |
val cur_htmlfile = ref None : outstream option ref; |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
146 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
147 |
(*Boolean variable which indicates if the title "Theorems proved in foo.ML" |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
148 |
has already been inserted into the current HTML file*) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
149 |
val cur_has_title = ref false; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
150 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
151 |
(*Name of theory currently being read*) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
152 |
val cur_name = ref ""; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
153 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
154 |
|
391 | 155 |
|
156 |
(*Make name of the output ML file for a theory *) |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
157 |
fun out_name tname = "." ^ tname ^ ".thy.ML"; |
391 | 158 |
|
159 |
(*Read a file specified by thy_file containing theory thy *) |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
160 |
fun read_thy tname thy_file = |
559 | 161 |
let |
391 | 162 |
val instream = open_in thy_file; |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
163 |
val outstream = open_out (out_name tname); |
559 | 164 |
in |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
165 |
output (outstream, ThySyn.parse tname (input (instream, 999999))); |
391 | 166 |
close_out outstream; |
167 |
close_in instream |
|
168 |
end; |
|
169 |
||
170 |
fun file_exists file = |
|
171 |
let val instream = open_in file in close_in instream; true end |
|
172 |
handle Io _ => false; |
|
173 |
||
174 |
(*Get thy_info for a loaded theory *) |
|
559 | 175 |
fun get_thyinfo tname = Symtab.lookup (!loaded_thys, tname); |
391 | 176 |
|
971
f4815812665b
fixed bug: parent theory wasn't loaded if .thy file was completly read before
clasohm
parents:
922
diff
changeset
|
177 |
(*Check if a theory was completly loaded *) |
391 | 178 |
fun already_loaded thy = |
179 |
let val t = get_thyinfo thy |
|
180 |
in if is_none t then false |
|
971
f4815812665b
fixed bug: parent theory wasn't loaded if .thy file was completly read before
clasohm
parents:
922
diff
changeset
|
181 |
else let val ThyInfo {thy_time, ml_time, ...} = the t |
f4815812665b
fixed bug: parent theory wasn't loaded if .thy file was completly read before
clasohm
parents:
922
diff
changeset
|
182 |
in is_some thy_time andalso is_some ml_time end |
391 | 183 |
end; |
184 |
||
185 |
(*Check if a theory file has changed since its last use. |
|
186 |
Return a pair of boolean values for .thy and for .ML *) |
|
559 | 187 |
fun thy_unchanged thy thy_file ml_file = |
1098
487089cb173e
fixed bug in thy_unchanged that occurred when the .thy file was changed
clasohm
parents:
971
diff
changeset
|
188 |
case get_thyinfo thy of |
487089cb173e
fixed bug in thy_unchanged that occurred when the .thy file was changed
clasohm
parents:
971
diff
changeset
|
189 |
Some (ThyInfo {thy_time, ml_time, ...}) => |
487089cb173e
fixed bug in thy_unchanged that occurred when the .thy file was changed
clasohm
parents:
971
diff
changeset
|
190 |
let val tn = is_none thy_time; |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
191 |
val mn = is_none ml_time |
391 | 192 |
in if not tn andalso not mn then |
1098
487089cb173e
fixed bug in thy_unchanged that occurred when the .thy file was changed
clasohm
parents:
971
diff
changeset
|
193 |
((file_info thy_file = the thy_time), |
487089cb173e
fixed bug in thy_unchanged that occurred when the .thy file was changed
clasohm
parents:
971
diff
changeset
|
194 |
(file_info ml_file = the ml_time)) |
487089cb173e
fixed bug in thy_unchanged that occurred when the .thy file was changed
clasohm
parents:
971
diff
changeset
|
195 |
else if not tn andalso mn then |
487089cb173e
fixed bug in thy_unchanged that occurred when the .thy file was changed
clasohm
parents:
971
diff
changeset
|
196 |
(file_info thy_file = the thy_time, false) |
487089cb173e
fixed bug in thy_unchanged that occurred when the .thy file was changed
clasohm
parents:
971
diff
changeset
|
197 |
else |
487089cb173e
fixed bug in thy_unchanged that occurred when the .thy file was changed
clasohm
parents:
971
diff
changeset
|
198 |
(false, false) |
391 | 199 |
end |
1098
487089cb173e
fixed bug in thy_unchanged that occurred when the .thy file was changed
clasohm
parents:
971
diff
changeset
|
200 |
| None => (false, false) |
391 | 201 |
|
1291 | 202 |
(*Get all direct descendants of a theory*) |
203 |
fun children_of t = |
|
204 |
case get_thyinfo t of Some (ThyInfo {children, ...}) => children |
|
205 |
| _ => []; |
|
206 |
||
1242 | 207 |
(*Get all direct ancestors of a theory*) |
1291 | 208 |
fun parents_of t = |
209 |
case get_thyinfo t of Some (ThyInfo {parents, ...}) => parents |
|
210 |
| _ => []; |
|
1242 | 211 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
212 |
(*Get all descendants of a theory list *) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
213 |
fun get_descendants [] = [] |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
214 |
| get_descendants (t :: ts) = |
1291 | 215 |
let val children = children_of t |
216 |
in children union (get_descendants (children union ts)) end; |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
217 |
|
1242 | 218 |
(*Get theory object for a loaded theory *) |
1291 | 219 |
fun theory_of name = |
1242 | 220 |
let val ThyInfo {theory, ...} = the (get_thyinfo name) |
221 |
in the theory end; |
|
222 |
||
1291 | 223 |
(*Get path where theory's files are located*) |
224 |
fun path_of tname = |
|
225 |
let val ThyInfo {path, ...} = the (get_thyinfo tname) |
|
226 |
in path end; |
|
227 |
||
391 | 228 |
exception FILE_NOT_FOUND; (*raised by find_file *) |
229 |
||
230 |
(*Find a file using a list of paths if no absolute or relative path is |
|
231 |
specified.*) |
|
232 |
fun find_file "" name = |
|
1291 | 233 |
let fun find_it (cur :: paths) = |
234 |
if file_exists (tack_on cur name) then |
|
235 |
(if cur = "." then name else tack_on cur name) |
|
559 | 236 |
else |
1291 | 237 |
find_it paths |
391 | 238 |
| find_it [] = "" |
239 |
in find_it (!loadpath) end |
|
240 |
| find_file path name = |
|
241 |
if file_exists (tack_on path name) then tack_on path name |
|
242 |
else ""; |
|
243 |
||
244 |
(*Get absolute pathnames for a new or already loaded theory *) |
|
245 |
fun get_filenames path name = |
|
246 |
let fun make_absolute file = |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
247 |
let fun rm_points [] result = rev result |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
248 |
| rm_points (".."::ds) result = rm_points ds (tl result) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
249 |
| rm_points ("."::ds) result = rm_points ds result |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
250 |
| rm_points (d::ds) result = rm_points ds (d::result); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
251 |
in if file = "" then "" |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
252 |
else if hd (explode file) = "/" then file |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
253 |
else "/" ^ space_implode "/" |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
254 |
(rm_points (space_explode "/" (tack_on (pwd ()) file)) []) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
255 |
end; |
391 | 256 |
|
257 |
fun new_filename () = |
|
258 |
let val found = find_file path (name ^ ".thy") |
|
259 |
handle FILE_NOT_FOUND => ""; |
|
260 |
val thy_file = make_absolute found; |
|
261 |
val (thy_path, _) = split_filename thy_file; |
|
262 |
val found = find_file path (name ^ ".ML"); |
|
263 |
val ml_file = if thy_file = "" then make_absolute found |
|
264 |
else if file_exists (tack_on thy_path (name ^ ".ML")) |
|
265 |
then tack_on thy_path (name ^ ".ML") |
|
266 |
else ""; |
|
267 |
val searched_dirs = if path = "" then (!loadpath) else [path] |
|
268 |
in if thy_file = "" andalso ml_file = "" then |
|
269 |
error ("Could not find file \"" ^ name ^ ".thy\" or \"" |
|
270 |
^ name ^ ".ML\" for theory \"" ^ name ^ "\"\n" |
|
271 |
^ "in the following directories: \"" ^ |
|
272 |
(space_implode "\", \"" searched_dirs) ^ "\"") |
|
273 |
else (); |
|
559 | 274 |
(thy_file, ml_file) |
391 | 275 |
end; |
276 |
||
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
277 |
val tinfo = get_thyinfo name; |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
278 |
in if is_some tinfo andalso path = "" then |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
279 |
let val ThyInfo {path = abs_path, ...} = the tinfo; |
391 | 280 |
val (thy_file, ml_file) = if abs_path = "" then new_filename () |
281 |
else (find_file abs_path (name ^ ".thy"), |
|
282 |
find_file abs_path (name ^ ".ML")) |
|
283 |
in if thy_file = "" andalso ml_file = "" then |
|
284 |
(writeln ("Warning: File \"" ^ (tack_on path name) |
|
285 |
^ ".thy\"\ncontaining theory \"" ^ name |
|
286 |
^ "\" no longer exists."); |
|
287 |
new_filename () |
|
288 |
) |
|
289 |
else (thy_file, ml_file) |
|
290 |
end |
|
291 |
else new_filename () |
|
292 |
end; |
|
293 |
||
294 |
(*Remove theory from all child lists in loaded_thys *) |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
295 |
fun unlink_thy tname = |
1291 | 296 |
let fun remove (ThyInfo {path, children, parents, thy_time, ml_time, |
297 |
theory, thms, thy_ss, simpset}) = |
|
298 |
ThyInfo {path = path, children = children \ tname, parents = parents, |
|
1242 | 299 |
thy_time = thy_time, ml_time = ml_time, theory = theory, |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
300 |
thms = thms, thy_ss = thy_ss, simpset = simpset} |
559 | 301 |
in loaded_thys := Symtab.map remove (!loaded_thys) end; |
391 | 302 |
|
303 |
(*Remove a theory from loaded_thys *) |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
304 |
fun remove_thy tname = |
559 | 305 |
loaded_thys := Symtab.make (filter_out (fn (id, _) => id = tname) |
306 |
(Symtab.dest (!loaded_thys))); |
|
391 | 307 |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
308 |
(*Change thy_time and ml_time for an existent item *) |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
309 |
fun set_info tname thy_time ml_time = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
310 |
let val tinfo = case Symtab.lookup (!loaded_thys, tname) of |
1291 | 311 |
Some (ThyInfo {path, children, parents, theory, thms, |
312 |
thy_ss, simpset,...}) => |
|
313 |
ThyInfo {path = path, children = children, parents = parents, |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
314 |
thy_time = thy_time, ml_time = ml_time, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
315 |
theory = theory, thms = thms, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
316 |
thy_ss = thy_ss, simpset = simpset} |
1291 | 317 |
| None => error ("set_info: theory " ^ tname ^ " not found"); |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
318 |
in loaded_thys := Symtab.update ((tname, tinfo), !loaded_thys) |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
319 |
end; |
391 | 320 |
|
321 |
(*Mark theory as changed since last read if it has been completly read *) |
|
559 | 322 |
fun mark_outdated tname = |
971
f4815812665b
fixed bug: parent theory wasn't loaded if .thy file was completly read before
clasohm
parents:
922
diff
changeset
|
323 |
let val t = get_thyinfo tname; |
f4815812665b
fixed bug: parent theory wasn't loaded if .thy file was completly read before
clasohm
parents:
922
diff
changeset
|
324 |
in if is_none t then () |
1291 | 325 |
else |
326 |
let val ThyInfo {thy_time, ml_time, ...} = the t |
|
327 |
in set_info tname (if is_none thy_time then None else Some "") |
|
328 |
(if is_none ml_time then None else Some "") |
|
329 |
end |
|
971
f4815812665b
fixed bug: parent theory wasn't loaded if .thy file was completly read before
clasohm
parents:
922
diff
changeset
|
330 |
end; |
391 | 331 |
|
1291 | 332 |
(*Make head of HTML dependency charts |
333 |
Parameters are: |
|
334 |
file: HTML file |
|
335 |
tname: theory name |
|
336 |
suffix: suffix of complementary chart |
|
337 |
(sup if this head is for a sub-chart, sub if it is for a sup-chart; |
|
338 |
empty for Pure and CPure sub-charts) |
|
339 |
gif_path: relative path to directory containing GIFs |
|
1313 | 340 |
index_path: relative path to directory containing main theory chart |
1291 | 341 |
*) |
1317 | 342 |
fun mk_charthead file tname title repeats gif_path index_path package = |
1291 | 343 |
output (file, |
344 |
"<HTML><HEAD><TITLE>" ^ title ^ " of " ^ tname ^ |
|
345 |
"</TITLE></HEAD>\n<H2>" ^ title ^ " of theory " ^ tname ^ |
|
346 |
"</H2>\nThe name of every theory is linked to its theory file<BR>\n" ^ |
|
347 |
"<IMG SRC = \"" ^ tack_on gif_path "red_arrow.gif\ |
|
348 |
\\" ALT = \\/></A> stands for subtheories (child theories)<BR>\n\ |
|
349 |
\<IMG SRC = \"" ^ tack_on gif_path "blue_arrow.gif\ |
|
350 |
\\" ALT = /\\></A> stands for supertheories (parent theories)\n" ^ |
|
1317 | 351 |
(if not repeats then "" else |
352 |
"<BR><TT>...</TT> stands for repeated subtrees") ^ |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
353 |
"<P>\n<A HREF = \"" ^ tack_on index_path "index.html\ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
354 |
\\">Back</A> to the index of " ^ package ^ "\n<HR>\n<PRE>"); |
1291 | 355 |
|
356 |
(*Convert .thy file to HTML and make chart of its super-theories*) |
|
357 |
fun thyfile2html tpath tname = |
|
358 |
let |
|
359 |
val gif_path = relative_path tpath (!gif_path); |
|
1317 | 360 |
val package = |
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
361 |
if (!index_path) = "" then |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
362 |
error "index_path is empty. Please use 'init_html()' instead of \ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
363 |
\'make_html := true'" |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
364 |
else relative_path (!base_path) (!index_path); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
365 |
val rel_index_path = relative_path tpath (!index_path); |
1291 | 366 |
|
367 |
(*Make list of all theories and all theories that own a .thy file*) |
|
368 |
fun list_theories [] theories thy_files = (theories, thy_files) |
|
369 |
| list_theories ((tname, ThyInfo {thy_time, ...}) :: ts) |
|
370 |
theories thy_files = |
|
371 |
list_theories ts (tname :: theories) |
|
372 |
(if is_some thy_time andalso the thy_time <> "" then |
|
373 |
tname :: thy_files |
|
374 |
else thy_files); |
|
375 |
||
376 |
val (theories, thy_files) = |
|
377 |
list_theories (Symtab.dest (!loaded_thys)) [] []; |
|
378 |
||
379 |
(*Do the conversion*) |
|
380 |
fun gettext thy_file = |
|
381 |
let |
|
382 |
(*Convert special HTML characters ('&', '>', and '<')*) |
|
383 |
val file = |
|
384 |
explode (execute ("sed -e 's/\\&/\\&/g' -e 's/>/\\>/g' \ |
|
385 |
\-e 's/</\\</g' " ^ thy_file)); |
|
386 |
||
387 |
(*Isolate first (possibly nested) comment; |
|
388 |
skip all leading whitespaces*) |
|
389 |
val (comment, file') = |
|
390 |
let fun first_comment ("*" :: ")" :: cs) co 1 = (co ^ "*)", cs) |
|
391 |
| first_comment ("*" :: ")" :: cs) co d = |
|
392 |
first_comment cs (co ^ "*)") (d-1) |
|
393 |
| first_comment ("(" :: "*" :: cs) co d = |
|
394 |
first_comment cs (co ^ "(*") (d+1) |
|
395 |
| first_comment (" " :: cs) "" 0 = first_comment cs "" 0 |
|
396 |
| first_comment ("\n" :: cs) "" 0 = first_comment cs "" 0 |
|
397 |
| first_comment ("\t" :: cs) "" 0 = first_comment cs "" 0 |
|
398 |
| first_comment cs "" 0 = ("", cs) |
|
399 |
| first_comment (c :: cs) co d = |
|
400 |
first_comment cs (co ^ implode [c]) d |
|
401 |
| first_comment [] co _ = |
|
402 |
error ("Unexpected end of file " ^ tname ^ ".thy."); |
|
403 |
in first_comment file "" 0 end; |
|
404 |
||
405 |
(*Process line defining theory's ancestors; |
|
406 |
convert valid theory names to links to their HTML file*) |
|
407 |
val (ancestors, body) = |
|
408 |
let |
|
409 |
fun make_links l result = |
|
410 |
let val (pre, letter) = take_prefix (not o is_letter) l; |
|
411 |
||
412 |
val (id, rest) = |
|
413 |
take_prefix (is_quasi_letter orf is_digit) letter; |
|
414 |
||
415 |
val id = implode id; |
|
416 |
||
417 |
(*Make a HTML link out of a theory name*) |
|
418 |
fun make_link t = |
|
419 |
let val path = path_of t; |
|
420 |
in "<A HREF = \"" ^ |
|
1323 | 421 |
tack_on (relative_path tpath path) ("." ^ t) ^ |
1291 | 422 |
".html\">" ^ t ^ "</A>" end; |
423 |
in if not (id mem theories) then (result, implode l) |
|
424 |
else if id mem thy_files then |
|
425 |
make_links rest (result ^ implode pre ^ make_link id) |
|
426 |
else make_links rest (result ^ implode pre ^ id) |
|
427 |
end; |
|
428 |
||
429 |
val (pre, rest) = take_prefix (fn c => c <> "=") file'; |
|
430 |
||
431 |
val (ancestors, body) = |
|
432 |
if null rest then |
|
433 |
error ("Missing \"=\" in file " ^ tname ^ ".thy.\n\ |
|
434 |
\(Make sure that the last line ends with a linebreak.)") |
|
435 |
else |
|
436 |
make_links rest ""; |
|
437 |
in (implode pre ^ ancestors, body) end; |
|
438 |
in "<HTML><HEAD><TITLE>" ^ tname ^ ".thy</TITLE></HEAD>\n\n<BODY>\n" ^ |
|
439 |
"<H2>" ^ tname ^ ".thy</H2>\n<A HREF = \"" ^ |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
440 |
tack_on rel_index_path "index.html\ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
441 |
\\">Back</A> to the index of " ^ package ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
442 |
"\n<HR>\n\n<PRE>\n" ^ comment ^ ancestors ^ body ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
443 |
"</PRE>\n" |
1291 | 444 |
end; |
445 |
||
446 |
(** Make chart of super-theories **) |
|
447 |
||
1323 | 448 |
val sup_out = open_out (tack_on tpath ("." ^ tname ^ "_sup.html")); |
449 |
val sub_out = open_out (tack_on tpath ("." ^ tname ^ "_sub.html")); |
|
1291 | 450 |
|
451 |
(*Theories that already have been listed in this chart*) |
|
452 |
val listed = ref []; |
|
453 |
||
454 |
val wanted_theories = |
|
455 |
filter (fn s => s mem thy_files orelse s = "Pure" orelse s = "CPure") |
|
456 |
theories; |
|
457 |
||
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
458 |
(*Make tree of theory dependencies*) |
1291 | 459 |
fun list_ancestors tname level continued = |
460 |
let |
|
461 |
fun mk_entry [] = () |
|
462 |
| mk_entry (t::ts) = |
|
463 |
let |
|
464 |
val is_pure = t = "Pure" orelse t = "CPure"; |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
465 |
val path = if is_pure then (the (!pure_subchart)) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
466 |
else path_of t; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
467 |
val rel_path = relative_path tpath path; |
1317 | 468 |
val repeated = t mem (!listed) andalso not (null (parents_of t)); |
1291 | 469 |
|
470 |
fun mk_offset [] cur = |
|
471 |
if level < cur then error "Error in mk_offset" |
|
472 |
else implode (replicate (level - cur) " ") |
|
473 |
| mk_offset (l::ls) cur = |
|
474 |
implode (replicate (l - cur) " ") ^ "| " ^ |
|
475 |
mk_offset ls (l+1); |
|
476 |
in output (sup_out, |
|
477 |
" " ^ mk_offset continued 0 ^ |
|
1323 | 478 |
"\\__" ^ (if is_pure then t else |
479 |
"<A HREF=\"" ^ tack_on rel_path ("." ^ t) ^ |
|
480 |
".html\">" ^ t ^ "</A>") ^ |
|
1317 | 481 |
(if repeated then "..." else " ") ^ |
1323 | 482 |
"<A HREF = \"" ^ tack_on rel_path ("." ^ t) ^ |
1317 | 483 |
"_sub.html\"><IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^ |
1291 | 484 |
tack_on gif_path "red_arrow.gif\" ALT = \\/></A>" ^ |
485 |
(if is_pure then "" |
|
1323 | 486 |
else "<A HREF = \"" ^ tack_on rel_path ("." ^ t) ^ |
1317 | 487 |
"_sup.html\"><IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^ |
1291 | 488 |
tack_on gif_path "blue_arrow.gif\ |
1317 | 489 |
\\" ALT = /\\></A>") ^ |
490 |
"\n"); |
|
491 |
if repeated then () |
|
492 |
else (listed := t :: (!listed); |
|
1291 | 493 |
list_ancestors t (level+1) (if null ts then continued |
494 |
else continued @ [level]); |
|
495 |
mk_entry ts) |
|
496 |
end; |
|
497 |
||
498 |
val relatives = |
|
499 |
filter (fn s => s mem wanted_theories) (parents_of tname); |
|
500 |
in mk_entry relatives end; |
|
501 |
in if is_some (!cur_htmlfile) then |
|
1323 | 502 |
error "thyfile2html: Last theory's HTML file has not been closed." |
1291 | 503 |
else (); |
1323 | 504 |
cur_htmlfile := Some (open_out (tack_on tpath ("." ^ tname ^ ".html"))); |
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
505 |
cur_has_title := false; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
506 |
cur_name := tname; |
1291 | 507 |
output (the (!cur_htmlfile), gettext (tack_on tpath tname ^ ".thy")); |
508 |
||
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
509 |
mk_charthead sup_out tname "Ancestors" true gif_path rel_index_path |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
510 |
package; |
1291 | 511 |
output(sup_out, |
1323 | 512 |
"<A HREF=\"." ^ tname ^ ".html\">" ^ tname ^ "</A> \ |
513 |
\<A HREF = \"." ^ tname ^ |
|
1317 | 514 |
"_sub.html\"><IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^ |
1291 | 515 |
tack_on gif_path "red_arrow.gif\" ALT = \\/></A>\n"); |
516 |
list_ancestors tname 0 []; |
|
517 |
output (sup_out, "</PRE><HR></BODY></HTML>"); |
|
518 |
close_out sup_out; |
|
519 |
||
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
520 |
mk_charthead sub_out tname "Children" false gif_path rel_index_path |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
521 |
package; |
1291 | 522 |
output(sub_out, |
1323 | 523 |
"<A HREF=\"." ^ tname ^ ".html\">" ^ tname ^ "</A> \ |
524 |
\<A HREF = \"." ^ tname ^ "_sup.html\"><IMG SRC = \"" ^ |
|
1317 | 525 |
tack_on gif_path "blue_arrow.gif\" BORDER=0 ALT = \\/></A>\n"); |
1291 | 526 |
close_out sub_out |
527 |
end; |
|
528 |
||
529 |
||
559 | 530 |
(*Read .thy and .ML files that haven't been read yet or have changed since |
391 | 531 |
they were last read; |
559 | 532 |
loaded_thys is a thy_info list ref containing all theories that have |
391 | 533 |
completly been read by this and preceeding use_thy calls. |
534 |
If a theory changed since its last use its children are marked as changed *) |
|
535 |
fun use_thy name = |
|
1242 | 536 |
let |
537 |
val (path, tname) = split_filename name; |
|
538 |
val (thy_file, ml_file) = get_filenames path tname; |
|
539 |
val (abs_path, _) = if thy_file = "" then split_filename ml_file |
|
540 |
else split_filename thy_file; |
|
541 |
val (thy_uptodate, ml_uptodate) = thy_unchanged tname thy_file ml_file; |
|
1291 | 542 |
val old_parents = parents_of tname; |
391 | 543 |
|
1242 | 544 |
(*Set absolute path for loaded theory *) |
545 |
fun set_path () = |
|
1291 | 546 |
let val ThyInfo {children, parents, thy_time, ml_time, theory, thms, |
547 |
thy_ss, simpset, ...} = |
|
1242 | 548 |
the (Symtab.lookup (!loaded_thys, tname)); |
549 |
in loaded_thys := Symtab.update ((tname, |
|
1291 | 550 |
ThyInfo {path = abs_path, |
551 |
children = children, parents = parents, |
|
1242 | 552 |
thy_time = thy_time, ml_time = ml_time, |
553 |
theory = theory, thms = thms, |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
554 |
thy_ss = thy_ss, simpset = simpset}), |
1242 | 555 |
!loaded_thys) |
556 |
end; |
|
557 |
||
558 |
(*Mark all direct descendants of a theory as changed *) |
|
559 |
fun mark_children thy = |
|
1291 | 560 |
let val children = children_of thy; |
1242 | 561 |
val present = filter (is_some o get_thyinfo) children; |
562 |
val loaded = filter already_loaded present; |
|
563 |
in if loaded <> [] then |
|
564 |
writeln ("The following children of theory " ^ (quote thy) |
|
565 |
^ " are now out-of-date: " |
|
566 |
^ (quote (space_implode "\",\"" loaded))) |
|
567 |
else (); |
|
568 |
seq mark_outdated present |
|
569 |
end; |
|
391 | 570 |
|
1242 | 571 |
(*Remove theorems associated with a theory*) |
572 |
fun delete_thms () = |
|
573 |
let |
|
574 |
val tinfo = case get_thyinfo tname of |
|
1291 | 575 |
Some (ThyInfo {path, children, parents, thy_time, ml_time, theory, |
576 |
thy_ss, simpset, ...}) => |
|
577 |
ThyInfo {path = path, children = children, parents = parents, |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
578 |
thy_time = thy_time, ml_time = ml_time, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
579 |
theory = theory, thms = Symtab.null, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
580 |
thy_ss = thy_ss, simpset = simpset} |
1291 | 581 |
| None => ThyInfo {path = "", children = [], parents = [], |
1242 | 582 |
thy_time = None, ml_time = None, |
583 |
theory = None, thms = Symtab.null, |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
584 |
thy_ss = None, simpset = None}; |
1242 | 585 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
586 |
val ThyInfo {theory, ...} = tinfo; |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
587 |
in loaded_thys := Symtab.update ((tname, tinfo), !loaded_thys); |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
588 |
case theory of |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
589 |
Some t => delete_thm_db t |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
590 |
| None => () |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
591 |
end; |
391 | 592 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
593 |
fun save_thy_ss () = |
1291 | 594 |
let val ThyInfo {path, children, parents, thy_time, ml_time, |
595 |
theory, thms, simpset, ...} = the (get_thyinfo tname); |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
596 |
in loaded_thys := Symtab.update |
1291 | 597 |
((tname, ThyInfo {path = path, |
598 |
children = children, parents = parents, |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
599 |
thy_time = thy_time, ml_time = ml_time, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
600 |
theory = theory, thms = thms, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
601 |
thy_ss = Some (!Simplifier.simpset), |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
602 |
simpset = simpset}), |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
603 |
!loaded_thys) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
604 |
end; |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
605 |
|
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
606 |
fun save_simpset () = |
1291 | 607 |
let val ThyInfo {path, children, parents, thy_time, ml_time, |
608 |
theory, thms, thy_ss, ...} = the (get_thyinfo tname); |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
609 |
in loaded_thys := Symtab.update |
1291 | 610 |
((tname, ThyInfo {path = path, |
611 |
children = children, parents = parents, |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
612 |
thy_time = thy_time, ml_time = ml_time, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
613 |
theory = theory, thms = thms, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
614 |
thy_ss = thy_ss, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
615 |
simpset = Some (!Simplifier.simpset)}), |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
616 |
!loaded_thys) |
1242 | 617 |
end; |
618 |
||
1313 | 619 |
(*Add theory to file listing all loaded theories (for index.html) |
1291 | 620 |
and to the sub-charts of its parents*) |
621 |
fun mk_html () = |
|
622 |
let val new_parents = parents_of tname \\ old_parents; |
|
623 |
||
624 |
(*Add child to parents' sub-theory charts*) |
|
625 |
fun add_to_parents t = |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
626 |
let val path = if t = "Pure" orelse t = "CPure" then |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
627 |
(the (!pure_subchart)) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
628 |
else path_of t; |
1291 | 629 |
|
630 |
val gif_path = relative_path path (!gif_path); |
|
631 |
val rel_path = relative_path path abs_path; |
|
1323 | 632 |
val tpath = tack_on rel_path ("." ^ tname); |
1291 | 633 |
|
1323 | 634 |
val out = open_append (tack_on path ("." ^ t ^ "_sub.html")); |
1291 | 635 |
in output (out, |
1323 | 636 |
" |\n \\__<A HREF=\"" ^ |
637 |
tack_on rel_path ("." ^ tname) ^ ".html\">" ^ tname ^ |
|
638 |
"</A> <A HREF = \"" ^ tpath ^ "_sub.html\">\ |
|
639 |
\<IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^ |
|
1291 | 640 |
tack_on gif_path "red_arrow.gif\" ALT = \\/></A>\ |
1323 | 641 |
\<A HREF = \"" ^ tpath ^ "_sup.html\">\ |
1317 | 642 |
\<IMG ALIGN=BOTTOM BORDER=0 SRC = \"" ^ |
643 |
tack_on gif_path "blue_arrow.gif\" ALT = /\\></A>\n"); |
|
1291 | 644 |
close_out out |
645 |
end; |
|
646 |
||
647 |
val theory_list = |
|
1323 | 648 |
open_append (tack_on (!index_path) ".theory_list.txt"); |
1291 | 649 |
in output (theory_list, tname ^ " " ^ abs_path ^ "\n"); |
650 |
close_out theory_list; |
|
651 |
||
652 |
seq add_to_parents new_parents |
|
653 |
end |
|
1242 | 654 |
in if thy_uptodate andalso ml_uptodate then () |
655 |
else |
|
1291 | 656 |
(if thy_file = "" then () |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
657 |
else if thy_uptodate then |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
658 |
simpset := let val ThyInfo {thy_ss, ...} = the (get_thyinfo tname); |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
659 |
in the thy_ss end |
391 | 660 |
else |
1242 | 661 |
(writeln ("Reading \"" ^ name ^ ".thy\""); |
1291 | 662 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
663 |
delete_thms (); |
1242 | 664 |
read_thy tname thy_file; |
665 |
use (out_name tname); |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
666 |
save_thy_ss (); |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
667 |
|
1308 | 668 |
(*Store axioms of theory |
669 |
(but only if it's not a copy of an older theory)*) |
|
670 |
let val parents = parents_of tname; |
|
671 |
val this_thy = theory_of tname; |
|
672 |
val axioms = |
|
673 |
if length parents = 1 |
|
674 |
andalso Sign.eq_sg (sign_of (theory_of (hd parents)), |
|
675 |
sign_of this_thy) then [] |
|
676 |
else axioms_of this_thy; |
|
677 |
in map store_thm_db axioms end; |
|
678 |
||
1242 | 679 |
if not (!delete_tmpfiles) then () |
1291 | 680 |
else delete_file (out_name tname); |
681 |
||
682 |
if not (!make_html) then () |
|
683 |
else thyfile2html abs_path tname |
|
1242 | 684 |
); |
685 |
||
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
686 |
set_info tname (Some (file_info thy_file)) None; |
783
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
687 |
(*mark thy_file as successfully loaded*) |
391 | 688 |
|
1242 | 689 |
if ml_file = "" then () |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
690 |
else (writeln ("Reading \"" ^ name ^ ".ML\""); |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
691 |
use ml_file); |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
692 |
save_simpset (); |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
693 |
|
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
694 |
(*Store theory again because it could have been redefined*) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
695 |
use_string |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
696 |
["val _ = store_theory (" ^ tname ^ ".thy, " ^ quote tname ^ ");"]; |
391 | 697 |
|
1313 | 698 |
(*Add theory to list of all loaded theories (for index.html) |
1291 | 699 |
and add it to its parents' sub-charts*) |
700 |
if !make_html then |
|
701 |
let val path = path_of tname; |
|
702 |
in if path = "" then mk_html () (*first time theory has been read*) |
|
703 |
else () |
|
704 |
end |
|
705 |
else (); |
|
706 |
||
1242 | 707 |
(*Now set the correct info*) |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
708 |
set_info tname (Some (file_info thy_file)) (Some (file_info ml_file)); |
1242 | 709 |
set_path (); |
710 |
||
711 |
(*Mark theories that have to be reloaded*) |
|
1291 | 712 |
mark_children tname; |
713 |
||
714 |
(*Close HTML file*) |
|
715 |
case !cur_htmlfile of |
|
716 |
Some out => (output (out, "<HR></BODY></HTML>\n"); |
|
717 |
close_out out; |
|
718 |
cur_htmlfile := None) |
|
719 |
| None => () |
|
1242 | 720 |
) |
721 |
end; |
|
391 | 722 |
|
723 |
fun time_use_thy tname = timeit(fn()=> |
|
559 | 724 |
(writeln("\n**** Starting Theory " ^ tname ^ " ****"); |
391 | 725 |
use_thy tname; |
726 |
writeln("\n**** Finished Theory " ^ tname ^ " ****")) |
|
727 |
); |
|
728 |
||
729 |
(*Load all thy or ML files that have been changed and also |
|
730 |
all theories that depend on them *) |
|
731 |
fun update () = |
|
732 |
let (*List theories in the order they have to be loaded *) |
|
733 |
fun load_order [] result = result |
|
734 |
| load_order thys result = |
|
1291 | 735 |
let fun next_level [] = [] |
736 |
| next_level (t :: ts) = |
|
737 |
let val children = children_of t |
|
738 |
in children union (next_level ts) end; |
|
559 | 739 |
|
1291 | 740 |
val descendants = next_level thys; |
741 |
in load_order descendants ((result \\ descendants) @ descendants) |
|
742 |
end; |
|
391 | 743 |
|
744 |
fun reload_changed (t :: ts) = |
|
1291 | 745 |
let fun abspath () = case get_thyinfo t of |
746 |
Some (ThyInfo {path, ...}) => path |
|
747 |
| None => ""; |
|
391 | 748 |
|
749 |
val (thy_file, ml_file) = get_filenames (abspath ()) t; |
|
750 |
val (thy_uptodate, ml_uptodate) = |
|
751 |
thy_unchanged t thy_file ml_file; |
|
752 |
in if thy_uptodate andalso ml_uptodate then () |
|
753 |
else use_thy t; |
|
754 |
reload_changed ts |
|
755 |
end |
|
756 |
| reload_changed [] = (); |
|
757 |
||
922
196ca0973a6d
added CPure (curried functions) and ProtoPure (ancestor of Pure and CPure)
clasohm
parents:
871
diff
changeset
|
758 |
(*Remove all theories that are no descendants of ProtoPure. |
391 | 759 |
If there are still children in the deleted theory's list |
760 |
schedule them for reloading *) |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
761 |
fun collect_garbage no_garbage = |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
762 |
let fun collect ((tname, ThyInfo {children, ...}) :: ts) = |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
763 |
if tname mem no_garbage then collect ts |
922
196ca0973a6d
added CPure (curried functions) and ProtoPure (ancestor of Pure and CPure)
clasohm
parents:
871
diff
changeset
|
764 |
else (writeln ("Theory \"" ^ tname ^ |
196ca0973a6d
added CPure (curried functions) and ProtoPure (ancestor of Pure and CPure)
clasohm
parents:
871
diff
changeset
|
765 |
"\" is no longer linked with ProtoPure - removing it."); |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
766 |
remove_thy tname; |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
767 |
seq mark_outdated children) |
391 | 768 |
| collect [] = () |
559 | 769 |
in collect (Symtab.dest (!loaded_thys)) end; |
922
196ca0973a6d
added CPure (curried functions) and ProtoPure (ancestor of Pure and CPure)
clasohm
parents:
871
diff
changeset
|
770 |
in collect_garbage ("ProtoPure" :: (load_order ["ProtoPure"] [])); |
196ca0973a6d
added CPure (curried functions) and ProtoPure (ancestor of Pure and CPure)
clasohm
parents:
871
diff
changeset
|
771 |
reload_changed (load_order ["Pure", "CPure"] []) |
391 | 772 |
end; |
773 |
||
774 |
(*Merge theories to build a base for a new theory. |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
775 |
Base members are only loaded if they are missing.*) |
586
201e115d8031
renamed base_on into mk_base and moved it to the beginning of the generated
clasohm
parents:
559
diff
changeset
|
776 |
fun mk_base bases child mk_draft = |
1291 | 777 |
let (*Show the cycle that would be created by add_child*) |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
778 |
fun show_cycle base = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
779 |
let fun find_it result curr = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
780 |
let val tinfo = get_thyinfo curr |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
781 |
in if base = curr then |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
782 |
error ("Cyclic dependency of theories: " |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
783 |
^ child ^ "->" ^ base ^ result) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
784 |
else if is_some tinfo then |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
785 |
let val ThyInfo {children, ...} = the tinfo |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
786 |
in seq (find_it ("->" ^ curr ^ result)) children |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
787 |
end |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
788 |
else () |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
789 |
end |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
790 |
in find_it "" child end; |
391 | 791 |
|
1291 | 792 |
(*Check if a cycle would be created by add_child*) |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
793 |
fun find_cycle base = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
794 |
if base mem (get_descendants [child]) then show_cycle base |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
795 |
else (); |
559 | 796 |
|
1291 | 797 |
(*Add child to child list of base*) |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
798 |
fun add_child base = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
799 |
let val tinfo = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
800 |
case Symtab.lookup (!loaded_thys, base) of |
1291 | 801 |
Some (ThyInfo {path, children, parents, thy_time, ml_time, |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
802 |
theory, thms, thy_ss, simpset}) => |
1291 | 803 |
ThyInfo {path = path, |
804 |
children = child ins children, parents = parents, |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
805 |
thy_time = thy_time, ml_time = ml_time, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
806 |
theory = theory, thms = thms, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
807 |
thy_ss = thy_ss, simpset = simpset} |
1291 | 808 |
| None => ThyInfo {path = "", children = [child], parents = [], |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
809 |
thy_time = None, ml_time = None, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
810 |
theory = None, thms = Symtab.null, |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
811 |
thy_ss = None, simpset = None}; |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
812 |
in loaded_thys := Symtab.update ((base, tinfo), !loaded_thys) end; |
559 | 813 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
814 |
(*Load a base theory if not already done |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
815 |
and no cycle would be created *) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
816 |
fun load base = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
817 |
let val thy_loaded = already_loaded base |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
818 |
(*test this before child is added *) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
819 |
in |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
820 |
if child = base then |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
821 |
error ("Cyclic dependency of theories: " ^ child |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
822 |
^ "->" ^ child) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
823 |
else |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
824 |
(find_cycle base; |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
825 |
add_child base; |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
826 |
if thy_loaded then () |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
827 |
else (writeln ("Autoloading theory " ^ (quote base) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
828 |
^ " (used by " ^ (quote child) ^ ")"); |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
829 |
use_thy base) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
830 |
) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
831 |
end; |
391 | 832 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
833 |
(*Get simpset for a theory*) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
834 |
fun get_simpset tname = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
835 |
let val ThyInfo {simpset, ...} = the (get_thyinfo tname); |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
836 |
in simpset end; |
391 | 837 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
838 |
(*Load all needed files and make a list of all real theories *) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
839 |
fun load_base (Thy b :: bs) = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
840 |
(load b; |
1291 | 841 |
b :: load_base bs) |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
842 |
| load_base (File b :: bs) = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
843 |
(load b; |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
844 |
load_base bs) (*don't add it to mergelist *) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
845 |
| load_base [] = []; |
391 | 846 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
847 |
val dummy = unlink_thy child; |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
848 |
val mergelist = load_base bases; |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
849 |
|
1291 | 850 |
val dummy = |
851 |
let val tinfo = case Symtab.lookup (!loaded_thys, child) of |
|
852 |
Some (ThyInfo {path, children, thy_time, ml_time, theory, thms, |
|
853 |
thy_ss, simpset, ...}) => |
|
854 |
ThyInfo {path = path, |
|
855 |
children = children, parents = mergelist, |
|
856 |
thy_time = thy_time, ml_time = ml_time, |
|
857 |
theory = theory, thms = thms, |
|
858 |
thy_ss = thy_ss, simpset = simpset} |
|
859 |
| None => error ("set_parents: theory " ^ child ^ " not found"); |
|
860 |
in loaded_thys := Symtab.update ((child, tinfo), !loaded_thys) end; |
|
861 |
||
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
862 |
val base_thy = (writeln ("Loading theory " ^ (quote child)); |
1291 | 863 |
merge_thy_list mk_draft (map theory_of mergelist)); |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
864 |
in simpset := foldr merge_ss (mapfilter get_simpset mergelist, empty_ss); |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
865 |
base_thy |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
866 |
end; |
391 | 867 |
|
1291 | 868 |
(*Change theory object for an existent item of loaded_thys*) |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
869 |
fun store_theory (thy, tname) = |
559 | 870 |
let val tinfo = case Symtab.lookup (!loaded_thys, tname) of |
1291 | 871 |
Some (ThyInfo {path, children, parents, thy_time, ml_time, thms, |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
872 |
thy_ss, simpset, ...}) => |
1291 | 873 |
ThyInfo {path = path, children = children, parents = parents, |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
874 |
thy_time = thy_time, ml_time = ml_time, |
1242 | 875 |
theory = Some thy, thms = thms, |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
876 |
thy_ss = thy_ss, simpset = simpset} |
1291 | 877 |
| None => error ("store_theory: theory " ^ tname ^ " not found"); |
1132
dfb29abcf3c2
added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
1098
diff
changeset
|
878 |
in loaded_thys := Symtab.update ((tname, tinfo), !loaded_thys) |
dfb29abcf3c2
added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
1098
diff
changeset
|
879 |
end; |
559 | 880 |
|
881 |
||
882 |
(** store and retrieve theorems **) |
|
883 |
||
715
f76ad10f5802
added call of store_theory after thy file has been read
clasohm
parents:
586
diff
changeset
|
884 |
(*Guess to which theory a signature belongs and return it's thy_info*) |
559 | 885 |
fun thyinfo_of_sign sg = |
886 |
let |
|
887 |
val ref xname = hd (#stamps (Sign.rep_sg sg)); |
|
888 |
val opt_info = get_thyinfo xname; |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
889 |
|
559 | 890 |
fun eq_sg (ThyInfo {theory = None, ...}) = false |
715
f76ad10f5802
added call of store_theory after thy file has been read
clasohm
parents:
586
diff
changeset
|
891 |
| eq_sg (ThyInfo {theory = Some thy, ...}) = Sign.eq_sg (sg,sign_of thy); |
559 | 892 |
|
893 |
val show_sg = Pretty.str_of o Sign.pretty_sg; |
|
894 |
in |
|
895 |
if is_some opt_info andalso eq_sg (the opt_info) then |
|
896 |
(xname, the opt_info) |
|
897 |
else |
|
783
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
898 |
(case Symtab.find_first (eq_sg o snd) (!loaded_thys) of |
559 | 899 |
Some name_info => name_info |
900 |
| None => error ("Theory " ^ show_sg sg ^ " not stored by loader")) |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
901 |
end; |
391 | 902 |
|
559 | 903 |
|
715
f76ad10f5802
added call of store_theory after thy file has been read
clasohm
parents:
586
diff
changeset
|
904 |
(*Try to get the theory object corresponding to a given signature*) |
559 | 905 |
fun theory_of_sign sg = |
906 |
(case thyinfo_of_sign sg of |
|
907 |
(_, ThyInfo {theory = Some thy, ...}) => thy |
|
908 |
| _ => sys_error "theory_of_sign"); |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
909 |
|
715
f76ad10f5802
added call of store_theory after thy file has been read
clasohm
parents:
586
diff
changeset
|
910 |
(*Try to get the theory object corresponding to a given theorem*) |
559 | 911 |
val theory_of_thm = theory_of_sign o #sign o rep_thm; |
912 |
||
913 |
||
715
f76ad10f5802
added call of store_theory after thy file has been read
clasohm
parents:
586
diff
changeset
|
914 |
(* Store theorems *) |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
915 |
|
1291 | 916 |
(*Store a theorem in the thy_info of its theory, |
917 |
and in the theory's HTML file*) |
|
559 | 918 |
fun store_thm (name, thm) = |
919 |
let |
|
1291 | 920 |
val (thy_name, ThyInfo {path, children, parents, thy_time, ml_time, |
921 |
theory, thms, thy_ss, simpset}) = |
|
559 | 922 |
thyinfo_of_sign (#sign (rep_thm thm)); |
1236
b54d51df9065
added check for duplicate theorems in theorem database;
clasohm
parents:
1223
diff
changeset
|
923 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
924 |
val (thms', duplicate) = (Symtab.update_new ((name, thm), thms), false) |
774
ea19f22ed23c
added warning for already stored theorem to store_thm
clasohm
parents:
759
diff
changeset
|
925 |
handle Symtab.DUPLICATE s => |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
926 |
(if eq_thm (the (Symtab.lookup (thms, name)), thm) then |
1236
b54d51df9065
added check for duplicate theorems in theorem database;
clasohm
parents:
1223
diff
changeset
|
927 |
(writeln ("Warning: Theory database already contains copy of\ |
774
ea19f22ed23c
added warning for already stored theorem to store_thm
clasohm
parents:
759
diff
changeset
|
928 |
\ theorem " ^ quote name); |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
929 |
(thms, true)) |
1236
b54d51df9065
added check for duplicate theorems in theorem database;
clasohm
parents:
1223
diff
changeset
|
930 |
else error ("Duplicate theorem name " ^ quote s |
b54d51df9065
added check for duplicate theorems in theorem database;
clasohm
parents:
1223
diff
changeset
|
931 |
^ " used in theory database")); |
1291 | 932 |
|
933 |
fun thm_to_html () = |
|
934 |
let fun escape [] = "" |
|
935 |
| escape ("<"::s) = "<" ^ escape s |
|
936 |
| escape (">"::s) = ">" ^ escape s |
|
937 |
| escape ("&"::s) = "&" ^ escape s |
|
938 |
| escape (c::s) = c ^ escape s; |
|
939 |
in case !cur_htmlfile of |
|
940 |
Some out => |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
941 |
(if not (!cur_has_title) then |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
942 |
(cur_has_title := true; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
943 |
output (out, "<HR><H2>Theorems proved in <A HREF = \"" ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
944 |
(!cur_name) ^ ".ML\">" ^ (!cur_name) ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
945 |
".ML</A>:</H2>\n")) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
946 |
else (); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
947 |
output (out, "<EM>" ^ name ^ "</EM>\n<PRE>" ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
948 |
escape (explode (string_of_thm (freeze thm))) ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
949 |
"</PRE><P>\n") |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
950 |
) |
1291 | 951 |
| None => () |
952 |
end; |
|
559 | 953 |
in |
954 |
loaded_thys := Symtab.update |
|
1291 | 955 |
((thy_name, ThyInfo {path = path, children = children, parents = parents, |
1242 | 956 |
thy_time = thy_time, ml_time = ml_time, |
957 |
theory = theory, thms = thms', |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
958 |
thy_ss = thy_ss, simpset = simpset}), |
1242 | 959 |
!loaded_thys); |
1291 | 960 |
thm_to_html (); |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
961 |
if duplicate then thm else store_thm_db (name, thm) |
559 | 962 |
end; |
963 |
||
715
f76ad10f5802
added call of store_theory after thy file has been read
clasohm
parents:
586
diff
changeset
|
964 |
(*Store result of proof in loaded_thys and as ML value*) |
758 | 965 |
|
966 |
val qed_thm = ref flexpair_def(*dummy*); |
|
967 |
||
968 |
fun bind_thm (name, thm) = |
|
1291 | 969 |
(qed_thm := standard thm; |
970 |
store_thm (name, standard thm); |
|
971 |
use_string ["val " ^ name ^ " = !qed_thm;"]); |
|
758 | 972 |
|
559 | 973 |
fun qed name = |
1291 | 974 |
(qed_thm := result (); |
975 |
store_thm (name, !qed_thm); |
|
976 |
use_string ["val " ^ name ^ " = !qed_thm;"]); |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
977 |
|
746 | 978 |
fun qed_goal name thy agoal tacsf = |
1291 | 979 |
(qed_thm := prove_goal thy agoal tacsf; |
980 |
store_thm (name, !qed_thm); |
|
981 |
use_string ["val " ^ name ^ " = !qed_thm;"]); |
|
746 | 982 |
|
983 |
fun qed_goalw name thy rths agoal tacsf = |
|
1291 | 984 |
(qed_thm := prove_goalw thy rths agoal tacsf; |
985 |
store_thm (name, !qed_thm); |
|
986 |
use_string ["val " ^ name ^ " = !qed_thm;"]); |
|
559 | 987 |
|
783
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
988 |
|
715
f76ad10f5802
added call of store_theory after thy file has been read
clasohm
parents:
586
diff
changeset
|
989 |
(* Retrieve theorems *) |
559 | 990 |
|
783
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
991 |
(*Get all theorems belonging to a given theory*) |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
992 |
fun thmtab_of_thy thy = |
783
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
993 |
let val (_, ThyInfo {thms, ...}) = thyinfo_of_sign (sign_of thy); |
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
994 |
in thms end; |
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
995 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
996 |
fun thmtab_of_name name = |
783
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
997 |
let val ThyInfo {thms, ...} = the (get_thyinfo name); |
559 | 998 |
in thms end; |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
426
diff
changeset
|
999 |
|
715
f76ad10f5802
added call of store_theory after thy file has been read
clasohm
parents:
586
diff
changeset
|
1000 |
(*Get a stored theorem specified by theory and name*) |
559 | 1001 |
fun get_thm thy name = |
783
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
1002 |
let fun get [] [] searched = |
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
1003 |
raise THEORY ("get_thm: no theorem " ^ quote name, [thy]) |
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
1004 |
| get [] ng searched = |
871 | 1005 |
get (ng \\ searched) [] searched |
783
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
1006 |
| get (t::ts) ng searched = |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
1007 |
(case Symtab.lookup (thmtab_of_name t, name) of |
783
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
1008 |
Some thm => thm |
1291 | 1009 |
| None => get ts (ng union (parents_of t)) (t::searched)); |
783
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
1010 |
|
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
1011 |
val (tname, _) = thyinfo_of_sign (sign_of thy); |
08f1785a4384
changed get_thm to search all parent theories if the theorem is not found
clasohm
parents:
778
diff
changeset
|
1012 |
in get [tname] [] [] end; |
559 | 1013 |
|
715
f76ad10f5802
added call of store_theory after thy file has been read
clasohm
parents:
586
diff
changeset
|
1014 |
(*Get stored theorems of a theory*) |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
1015 |
val thms_of = Symtab.dest o thmtab_of_thy; |
559 | 1016 |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
1017 |
(*Get simpset of a theory*) |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
1018 |
fun simpset_of tname = |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
1019 |
case get_thyinfo tname of |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
1020 |
Some (ThyInfo {simpset, ...}) => |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
1021 |
if is_some simpset then the simpset |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
1022 |
else error ("Simpset of theory " ^ tname ^ " has not been stored yet") |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1244
diff
changeset
|
1023 |
| None => error ("Theory " ^ tname ^ " not stored by loader"); |
559 | 1024 |
|
778 | 1025 |
(* print theory *) |
1026 |
||
1027 |
fun print_thms thy = |
|
1028 |
let |
|
1029 |
val thms = thms_of thy; |
|
1030 |
fun prt_thm (s, th) = Pretty.block [Pretty.str (s ^ ":"), Pretty.brk 1, |
|
1031 |
Pretty.quote (pretty_thm th)]; |
|
1032 |
in |
|
1033 |
Pretty.writeln (Pretty.big_list "stored theorems:" (map prt_thm thms)) |
|
1034 |
end; |
|
1035 |
||
1036 |
fun print_theory thy = (Drule.print_theory thy; print_thms thy); |
|
1037 |
||
1291 | 1038 |
|
1039 |
(* Misc HTML functions *) |
|
1040 |
||
1041 |
(*Init HTML generator by setting paths and creating new files*) |
|
1042 |
fun init_html () = |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1043 |
let val cwd = pwd(); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1044 |
|
1323 | 1045 |
val theory_list = close_out (open_out ".theory_list.txt"); |
1291 | 1046 |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1047 |
val rel_gif_path = relative_path cwd (!gif_path); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1048 |
val package = relative_path (!base_path) cwd; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1049 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1050 |
(*Make new HTML files for Pure and CPure*) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1051 |
fun init_pure_html () = |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1052 |
let val pure_out = open_out ".Pure_sub.html"; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1053 |
val cpure_out = open_out ".CPure_sub.html"; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1054 |
in mk_charthead pure_out "Pure" "Children" false rel_gif_path "" |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1055 |
package; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1056 |
mk_charthead cpure_out "CPure" "Children" false rel_gif_path "" |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1057 |
package; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1058 |
output (pure_out, "Pure\n"); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1059 |
output (cpure_out, "CPure\n"); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1060 |
close_out pure_out; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1061 |
close_out cpure_out; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1062 |
pure_subchart := Some cwd |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1063 |
end; |
1291 | 1064 |
in make_html := true; |
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1065 |
index_path := cwd; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1066 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1067 |
writeln ("Setting path for index.html to " ^ quote cwd ^ |
1291 | 1068 |
"\nGIF path has been set to " ^ quote (!gif_path)); |
1069 |
||
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1070 |
if is_none (!pure_subchart) then init_pure_html() |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1071 |
else () |
1291 | 1072 |
end; |
1073 |
||
1313 | 1074 |
(*Generate index.html*) |
1291 | 1075 |
fun make_chart () = if not (!make_html) then () else |
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1076 |
let val tlist_path = tack_on (!index_path) ".theory_list.txt"; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1077 |
val theory_list = open_in tlist_path; |
1291 | 1078 |
val theories = space_explode "\n" (input (theory_list, 999999)); |
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1079 |
val dummy = (close_in theory_list; delete_file tlist_path); |
1291 | 1080 |
|
1313 | 1081 |
val gif_path = relative_path (!index_path) (!gif_path); |
1291 | 1082 |
|
1083 |
(*Make entry for main chart of all theories.*) |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1084 |
fun main_entry t = |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1085 |
let |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1086 |
val (name, path) = take_prefix (not_equal " ") (explode t); |
1291 | 1087 |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1088 |
val tname = implode name |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1089 |
val tpath = tack_on (relative_path (!index_path) (implode (tl path))) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1090 |
("." ^ tname); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1091 |
in "<A HREF = \"" ^ tpath ^ "_sub.html\"><IMG SRC = \"" ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1092 |
tack_on gif_path "red_arrow.gif\" BORDER=0 ALT = \\/></A>" ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1093 |
"<A HREF = \"" ^ tpath ^ "_sup.html\"><IMG SRC = \"" ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1094 |
tack_on gif_path "blue_arrow.gif\ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1095 |
\\" BORDER=0 ALT = /\\></A> <A HREF = \"" ^ tpath ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1096 |
".html\">" ^ tname ^ "</A><BR>\n" |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1097 |
end; |
1291 | 1098 |
|
1313 | 1099 |
val out = open_out (tack_on (!index_path) "index.html"); |
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1100 |
val subdir = relative_path (!base_path) (!index_path); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1101 |
val subdirs = space_explode "/" subdir; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1102 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1103 |
(*Look for index.html in superdirectories*) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1104 |
fun find_super_index [] _ = |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1105 |
error "make_chart: Unable to find super index file." |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1106 |
| find_super_index (p::ps) n = |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1107 |
let val index_path = "/" ^ space_implode "/" (rev ps); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1108 |
in if file_exists (index_path ^ "/index.html") then (index_path, n) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1109 |
else find_super_index ps (n+1) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1110 |
end; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1111 |
val (super_index, level_diff) = |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1112 |
find_super_index (rev (space_explode "/" (!index_path))) 1; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1113 |
val level = length subdirs - level_diff; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1114 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1115 |
(*Add link to current directory to 'super' index.html*) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1116 |
fun link_directory () = |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1117 |
let val old_index = open_in (super_index ^ "/index.html"); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1118 |
val content = rev (explode (input (old_index, 999999))); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1119 |
val dummy = close_in old_index; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1120 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1121 |
val out = open_append (super_index ^ "/index.html"); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1122 |
val rel_path = space_implode "/" (drop (level, subdirs)); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1123 |
in |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1124 |
output (out, |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1125 |
(if nth_elem (3, content) <> "!" then "" |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1126 |
else "\n<HR><H3>Subdirectories:</H3>\n") ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1127 |
"<H3><A HREF = \"" ^ rel_path ^ "/index.html\">" ^ rel_path ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1128 |
"</A></H3>\n"); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1129 |
close_out out |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1130 |
end; |
1291 | 1131 |
in output (out, |
1132 |
"<HTML><HEAD><TITLE>Isabelle/" ^ subdir ^ "</TITLE></HEAD>\n\ |
|
1332 | 1133 |
\<BODY><H2>Isabelle/" ^ subdir ^ "</H2>\n\ |
1291 | 1134 |
\The name of every theory is linked to its theory file<BR>\n\ |
1135 |
\<IMG SRC = \"" ^ tack_on gif_path "red_arrow.gif\ |
|
1136 |
\\" ALT = \\/></A> stands for subtheories (child theories)<BR>\n\ |
|
1137 |
\<IMG SRC = \"" ^ tack_on gif_path "blue_arrow.gif\ |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1138 |
\\" ALT = /\\></A> stands for supertheories (parent theories)\ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1139 |
\<P>\n<A HREF = \"" ^ relative_path (!index_path) super_index ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1140 |
"/index.html\">Back</A> to the index of " ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1141 |
(if level = 0 then "Isabelle logics" |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1142 |
else space_implode "/" (take (level, subdirs))) ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1143 |
"\n" ^ |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1144 |
(if file_exists (tack_on (!index_path) "README.html") then |
1332 | 1145 |
"<BR>View the <A HREF = \"README.html\">ReadMe</A> file.\n" |
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1146 |
else if file_exists (tack_on (!index_path) "README") then |
1332 | 1147 |
"<BR>View the <A HREF = \"README\">ReadMe</A> file.\n" |
1148 |
else "") ^ |
|
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1149 |
"<HR>" ^ implode (map main_entry theories) ^ "<!-->"); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1150 |
close_out out; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1151 |
if level = 0 then () else link_directory () |
1291 | 1152 |
end; |
1348
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1153 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1154 |
(*CD to a directory and load its ROOT.ML file*) |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1155 |
fun use_dir dirname = |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1156 |
(cd dirname; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1157 |
if !make_html then init_html() else (); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1158 |
use "ROOT.ML"; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1159 |
make_chart()); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1160 |
|
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1161 |
fun exit_use_dir dirname = |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1162 |
(cd dirname; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1163 |
if !make_html then init_html() else (); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1164 |
exit_use "ROOT.ML"; |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1165 |
make_chart()); |
b9305143fa91
index.html files are now made separatly for each subdirectory
clasohm
parents:
1332
diff
changeset
|
1166 |
|
391 | 1167 |
end; |