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