src/Pure/Thy/thy_info.ML
author wenzelm
Tue, 19 May 1998 17:15:30 +0200
changeset 4945 d8c809afafb8
parent 4111 93baba60ece2
child 4964 bbe9065edf8a
permissions -rw-r--r--
fixed handle_error: cat_lines;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
wenzelm
parents: 3604
diff changeset
     3
    Author:     Stefan Berghofer and Markus Wenzel, TU Muenchen
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
     4
4111
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
     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
wenzelm
parents: 3604
diff changeset
     8
type thy_info =
wenzelm
parents: 3604
diff changeset
     9
  {path: string,
wenzelm
parents: 3604
diff changeset
    10
    children: string list, parents: string list,
wenzelm
parents: 3604
diff changeset
    11
    thy_time: string option, ml_time: string option,
4111
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    12
    theory: theory option};
3976
wenzelm
parents: 3604
diff changeset
    13
wenzelm
parents: 3604
diff changeset
    14
(*
4111
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    15
  path: directory where theory's files are located
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    16
	(* FIXME do not store absolute path!!! *)
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    17
4111
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    18
  thy_time, ml_time = None     theory file has not been read yet
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    19
                    = Some ""  theory was read but has either been marked
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    20
                               as outdated or there is no such file for
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    21
                               this theory (see e.g. 'virtual' theories
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    22
                               like Pure or theories without a ML file)
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    23
  theory = None  theory has not been read yet
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    24
4111
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    25
  parents: While 'children' contains all theories the theory depends
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    26
           on (i.e. also ones quoted in the .thy file),
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    27
           'parents' only contains the theories which were used to form
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    28
           the base of this theory.
3976
wenzelm
parents: 3604
diff changeset
    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
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    33
  val loaded_thys: thy_info Symtab.table ref
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    34
  val get_thyinfo: string -> thy_info option
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    35
  val store_theory: theory * string -> unit
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    36
  val path_of: string -> string
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    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
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    40
  val theory_of: string -> theory
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    41
  val theory_of_sign: Sign.sg -> theory
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    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
wenzelm
parents: 3604
diff changeset
    49
(* loaded theories *)
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    50
3976
wenzelm
parents: 3604
diff changeset
    51
fun mk_info (name, children, parents, theory) =
4111
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    52
  (name, {path = "", children = children, parents = parents,
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    53
    thy_time = Some "", ml_time = Some "", theory = Some theory}: thy_info);
3976
wenzelm
parents: 3604
diff changeset
    54
wenzelm
parents: 3604
diff changeset
    55
(*preloaded theories*)
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    56
val loaded_thys =
3976
wenzelm
parents: 3604
diff changeset
    57
  ref (Symtab.make (map mk_info
3997
42062f636bdf ProtoPure.thy etc.;
wenzelm
parents: 3976
diff changeset
    58
    [("ProtoPure", ["Pure", "CPure"], [], ProtoPure.thy),
42062f636bdf ProtoPure.thy etc.;
wenzelm
parents: 3976
diff changeset
    59
     ("Pure", [], ["ProtoPure"], Pure.thy),
42062f636bdf ProtoPure.thy etc.;
wenzelm
parents: 3976
diff changeset
    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
wenzelm
parents: 3604
diff changeset
    63
(* retrieve info *)
wenzelm
parents: 3604
diff changeset
    64
wenzelm
parents: 3604
diff changeset
    65
fun err_not_stored name =
wenzelm
parents: 3604
diff changeset
    66
  error ("Theory " ^ name ^ " not stored by loader");
wenzelm
parents: 3604
diff changeset
    67
wenzelm
parents: 3604
diff changeset
    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
wenzelm
parents: 3604
diff changeset
    70
fun the_thyinfo name =
wenzelm
parents: 3604
diff changeset
    71
  (case get_thyinfo name of
wenzelm
parents: 3604
diff changeset
    72
    Some info => info
wenzelm
parents: 3604
diff changeset
    73
  | None => err_not_stored name);
wenzelm
parents: 3604
diff changeset
    74
wenzelm
parents: 3604
diff changeset
    75
fun thyinfo_of_sign sg =
wenzelm
parents: 3604
diff changeset
    76
  let val name = Sign.name_of sg
wenzelm
parents: 3604
diff changeset
    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
wenzelm
parents: 3604
diff changeset
    80
(*path where theory's files are located*)
wenzelm
parents: 3604
diff changeset
    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
wenzelm
parents: 3604
diff changeset
    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
wenzelm
parents: 3604
diff changeset
    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
wenzelm
parents: 3604
diff changeset
    90
(*try to get the theory object corresponding to a given theorem*)
wenzelm
parents: 3604
diff changeset
    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
wenzelm
parents: 3604
diff changeset
    93
(*get all direct descendants of a theory*)
wenzelm
parents: 3604
diff changeset
    94
fun children_of t =
wenzelm
parents: 3604
diff changeset
    95
  (case get_thyinfo t of
4111
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
    96
    Some {children, ...} => children
3976
wenzelm
parents: 3604
diff changeset
    97
  | None => []);
wenzelm
parents: 3604
diff changeset
    98
wenzelm
parents: 3604
diff changeset
    99
(*get all direct ancestors of a theory*)
wenzelm
parents: 3604
diff changeset
   100
fun parents_of_name t =
wenzelm
parents: 3604
diff changeset
   101
  (case get_thyinfo t of
4111
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   102
    Some {parents, ...} => parents
3976
wenzelm
parents: 3604
diff changeset
   103
  | None => []);
wenzelm
parents: 3604
diff changeset
   104
wenzelm
parents: 3604
diff changeset
   105
(*get theory object for a loaded theory*)
wenzelm
parents: 3604
diff changeset
   106
fun theory_of name =
wenzelm
parents: 3604
diff changeset
   107
  (case get_thyinfo name of
4111
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   108
    Some {theory = Some t, ...} => t
3976
wenzelm
parents: 3604
diff changeset
   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
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   112
(* store_theory *)
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
   113
4111
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   114
fun store_theory (thy, name) =
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   115
  let
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   116
    val {path, children, parents, thy_time, ml_time, theory = _} =
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   117
      the_thyinfo name;
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   118
    val info = {path = path, children = children, parents = parents,
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   119
      thy_time = thy_time, ml_time = ml_time, theory = Some thy};
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   120
  in
93baba60ece2 removed old thy data stuff;
wenzelm
parents: 3997
diff changeset
   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;