author | wenzelm |
Tue, 19 May 1998 17:15:30 +0200 | |
changeset 4945 | d8c809afafb8 |
parent 4111 | 93baba60ece2 |
child 4964 | bbe9065edf8a |
permissions | -rw-r--r-- |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
1 |
(* Title: Pure/Thy/thy_info.ML |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
2 |
ID: $Id$ |
3976 | 3 |
Author: Stefan Berghofer and Markus Wenzel, TU Muenchen |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
4 |
|
4111 | 5 |
Theory loader database. |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
6 |
*) |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
7 |
|
3976 | 8 |
type thy_info = |
9 |
{path: string, |
|
10 |
children: string list, parents: string list, |
|
11 |
thy_time: string option, ml_time: string option, |
|
4111 | 12 |
theory: theory option}; |
3976 | 13 |
|
14 |
(* |
|
4111 | 15 |
path: directory where theory's files are located |
16 |
(* FIXME do not store absolute path!!! *) |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
17 |
|
4111 | 18 |
thy_time, ml_time = None theory file has not been read yet |
19 |
= Some "" theory was read but has either been marked |
|
20 |
as outdated or there is no such file for |
|
21 |
this theory (see e.g. 'virtual' theories |
|
22 |
like Pure or theories without a ML file) |
|
23 |
theory = None theory has not been read yet |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
24 |
|
4111 | 25 |
parents: While 'children' contains all theories the theory depends |
26 |
on (i.e. also ones quoted in the .thy file), |
|
27 |
'parents' only contains the theories which were used to form |
|
28 |
the base of this theory. |
|
3976 | 29 |
*) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
30 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
31 |
signature THY_INFO = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
32 |
sig |
4111 | 33 |
val loaded_thys: thy_info Symtab.table ref |
34 |
val get_thyinfo: string -> thy_info option |
|
35 |
val store_theory: theory * string -> unit |
|
36 |
val path_of: string -> string |
|
37 |
val children_of: string -> string list |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
38 |
val parents_of_name: string -> string list |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
39 |
val thyinfo_of_sign: Sign.sg -> string * thy_info |
4111 | 40 |
val theory_of: string -> theory |
41 |
val theory_of_sign: Sign.sg -> theory |
|
42 |
val theory_of_thm: thm -> theory |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
43 |
end; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
44 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
45 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
46 |
structure ThyInfo: THY_INFO = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
47 |
struct |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
48 |
|
3976 | 49 |
(* loaded theories *) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
50 |
|
3976 | 51 |
fun mk_info (name, children, parents, theory) = |
4111 | 52 |
(name, {path = "", children = children, parents = parents, |
53 |
thy_time = Some "", ml_time = Some "", theory = Some theory}: thy_info); |
|
3976 | 54 |
|
55 |
(*preloaded theories*) |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
56 |
val loaded_thys = |
3976 | 57 |
ref (Symtab.make (map mk_info |
3997 | 58 |
[("ProtoPure", ["Pure", "CPure"], [], ProtoPure.thy), |
59 |
("Pure", [], ["ProtoPure"], Pure.thy), |
|
60 |
("CPure", [], ["ProtoPure"], CPure.thy)])); |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
61 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
62 |
|
3976 | 63 |
(* retrieve info *) |
64 |
||
65 |
fun err_not_stored name = |
|
66 |
error ("Theory " ^ name ^ " not stored by loader"); |
|
67 |
||
68 |
fun get_thyinfo name = Symtab.lookup (! loaded_thys, name); |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
69 |
|
3976 | 70 |
fun the_thyinfo name = |
71 |
(case get_thyinfo name of |
|
72 |
Some info => info |
|
73 |
| None => err_not_stored name); |
|
74 |
||
75 |
fun thyinfo_of_sign sg = |
|
76 |
let val name = Sign.name_of sg |
|
77 |
in (name, the_thyinfo name) end; |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
78 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
79 |
|
3976 | 80 |
(*path where theory's files are located*) |
81 |
val path_of = #path o the_thyinfo; |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
82 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
83 |
|
3976 | 84 |
(*try to get the theory object corresponding to a given signature*) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
85 |
fun theory_of_sign sg = |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
86 |
(case thyinfo_of_sign sg of |
3976 | 87 |
(_, {theory = Some thy, ...}) => thy |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
88 |
| _ => sys_error "theory_of_sign"); |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
89 |
|
3976 | 90 |
(*try to get the theory object corresponding to a given theorem*) |
91 |
val theory_of_thm = theory_of_sign o #sign o rep_thm; |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
92 |
|
3976 | 93 |
(*get all direct descendants of a theory*) |
94 |
fun children_of t = |
|
95 |
(case get_thyinfo t of |
|
4111 | 96 |
Some {children, ...} => children |
3976 | 97 |
| None => []); |
98 |
||
99 |
(*get all direct ancestors of a theory*) |
|
100 |
fun parents_of_name t = |
|
101 |
(case get_thyinfo t of |
|
4111 | 102 |
Some {parents, ...} => parents |
3976 | 103 |
| None => []); |
104 |
||
105 |
(*get theory object for a loaded theory*) |
|
106 |
fun theory_of name = |
|
107 |
(case get_thyinfo name of |
|
4111 | 108 |
Some {theory = Some t, ...} => t |
3976 | 109 |
| _ => err_not_stored name); |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
110 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
111 |
|
4111 | 112 |
(* store_theory *) |
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
113 |
|
4111 | 114 |
fun store_theory (thy, name) = |
115 |
let |
|
116 |
val {path, children, parents, thy_time, ml_time, theory = _} = |
|
117 |
the_thyinfo name; |
|
118 |
val info = {path = path, children = children, parents = parents, |
|
119 |
thy_time = thy_time, ml_time = ml_time, theory = Some thy}; |
|
120 |
in |
|
121 |
loaded_thys := Symtab.update ((name, info), ! loaded_thys) |
|
3604
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
122 |
end; |
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
123 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
124 |
|
6bf9f09f3d61
Moved functions for theory information storage / retrieval
berghofe
parents:
diff
changeset
|
125 |
end; |