src/Pure/Thy/thy_info.ML
author wenzelm
Wed, 03 Feb 1999 17:29:48 +0100
changeset 6211 43d0efafa025
parent 5211 c02b0c727780
child 6219 b360065c2b07
permissions -rw-r--r--
Theory loader database: theory and file dependencies, theory values and user data.
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$
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
     4
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
     5
Theory loader database: theory and file dependencies, theory values
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
     6
and user data.
3976
wenzelm
parents: 3604
diff changeset
     7
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
     8
TODO:
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
     9
  - check_thy: include ML stamp (!?!?);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    10
  - check all these versions of 'use' (!!);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    11
  - errors during require etc.: include initiators (!?);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    12
  - data: ThyInfoFun;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    13
  - remove operation (GC!?);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    14
  - update_all operation (!?);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    15
  - put_theory:
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    16
      . include data;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    17
      . allow for undef entry only;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    18
      . elim (via theory_ref);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    19
  - stronger handling of missing files (!?!?);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    20
  - register_theory: do not require finished parents (!?) (no?);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    21
  - observe verbose flag;
3976
wenzelm
parents: 3604
diff changeset
    22
*)
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    23
5209
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
    24
signature BASIC_THY_INFO =
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
    25
sig
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
    26
  val theory: string -> theory
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    27
  val theory_of_sign: Sign.sg -> theory
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    28
  val theory_of_thm: thm -> theory
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    29
  val touch_thy: string -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    30
  val use_thy: string -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    31
  val update_thy: string -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    32
  val time_use_thy: string -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    33
end;
5209
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
    34
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    35
signature THY_INFO =
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    36
sig
5209
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
    37
  include BASIC_THY_INFO
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    38
  val verbose: bool ref
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    39
  val names: unit -> string list
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    40
  val get_theory: string -> theory
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    41
  val put_theory: theory -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    42
  val load_file: Path.T -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    43
  val use_thy_only: string -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    44
  val begin_theory: string -> string list -> theory
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    45
  val end_theory: theory -> theory
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    46
  val finish_all: unit -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    47
  val register_theory: theory -> unit
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    48
end;
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    49
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    50
signature PRIVATE_THY_INFO =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    51
sig
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    52
  include THY_INFO
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    53
(* FIXME
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    54
  val init_data: Object.kind -> (Object.T * (Object.T -> Object.T) *
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    55
    (Object.T * Object.T -> Object.T) * (Sign.sg -> Object.T -> unit)) -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    56
  val print_data: Object.kind -> string -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    57
  val get_data: Object.kind -> (Object.T -> 'a) -> string -> 'a
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    58
  val put_data: Object.kind -> ('a -> Object.T) -> 'a -> unit
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    59
*)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    60
end;
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    61
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    62
structure ThyInfo: PRIVATE_THY_INFO =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    63
struct
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    64
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    65
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    66
(** thy database **)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    67
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    68
(* messages *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    69
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    70
val verbose = ref false;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    71
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    72
fun gen_msg txt [] = txt
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    73
  | gen_msg txt names = txt ^ " " ^ commas_quote names;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    74
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    75
fun loader_msg txt names = gen_msg ("Theory loader: " ^ txt) names;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    76
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    77
val show_path = space_implode " via " o map quote;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    78
fun cycle_msg name names = loader_msg ("cyclic dependency of " ^ show_path (name :: names)) [];
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    79
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    80
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    81
(* derived graph operations *)		(* FIXME more abstract (!?) *)
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    82
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    83
fun add_deps name parents G =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    84
  foldl (fn (H, parent) => Graph.add_edge_acyclic (parent, name) H) (G, parents)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    85
    handle Graph.CYCLES namess => error (cat_lines (map (cycle_msg name) namess));
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    86
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    87
fun del_deps name G =           (* FIXME GC (!?!?) *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    88
  foldl (fn (H, parent) => Graph.del_edge (parent, name) H) (G, Graph.imm_preds G name);
3976
wenzelm
parents: 3604
diff changeset
    89
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    90
fun update_node name parents entry G =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    91
  add_deps name parents
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    92
    (if can (Graph.get_node G) name then del_deps name G else Graph.new_node (name, entry) G);
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    93
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
    94
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    95
(* thy database *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    96
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    97
type deps =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    98
  {present: bool, outdated: bool,
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
    99
    master: File.info option, files: (Path.T * File.info option) list} option;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   100
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   101
fun make_depends present outdated master files =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   102
  Some {present = present, outdated = outdated, master = master, files = files}: deps;
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
   103
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   104
type thy = deps * (theory * Object.T Symtab.table) option;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   105
type kind = Object.kind * (Object.T * (Object.T -> unit));
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   106
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
   107
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   108
local
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   109
  val database = ref (Graph.empty: thy Graph.T, Symtab.empty: kind Symtab.table);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   110
in
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   111
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   112
fun get_thys () = #1 (! database);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   113
fun get_kinds () = #2 (! database);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   114
fun change_thys f = database := (f (get_thys ()), get_kinds ());
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   115
fun change_kinds f = database := (get_thys (), f (get_kinds ()));
3604
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
   116
6bf9f09f3d61 Moved functions for theory information storage / retrieval
berghofe
parents:
diff changeset
   117
end;
5209
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
   118
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
   119
6211
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   120
(* access thy graph *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   121
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   122
fun thy_graph f x = f (get_thys ()) x;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   123
fun get_names () = map #1 (Graph.get_nodes (get_thys ()));
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   124
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   125
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   126
(* access thy *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   127
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   128
fun lookup_thy name = Some (thy_graph Graph.get_node name) handle Graph.UNDEFINED _ => None;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   129
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   130
fun get_thy name =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   131
  (case lookup_thy name of
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   132
    Some thy => thy
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   133
  | None => error (loader_msg "nothing known about theory" [name]));
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   134
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   135
fun change_thy name f = (get_thy name; change_thys (Graph.map_node name f));
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   136
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   137
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   138
(* access deps *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   139
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   140
val lookup_deps = apsome #1 o lookup_thy;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   141
val get_deps = #1 o get_thy;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   142
fun change_deps name f = change_thy name (fn (deps, x) => (f deps, x));
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   143
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   144
fun get_files name = (case get_deps name of Some {files, ...} => files | _ => []);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   145
fun is_finished name = is_none (get_deps name);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   146
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   147
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   148
(* access theory *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   149
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   150
fun get_theory name =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   151
  (case get_thy name of
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   152
    (_, Some (theory, _)) => theory
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   153
  | _ => error (loader_msg "undefined theory entry for" [name]));
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   154
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   155
val theory_of_sign = get_theory o Sign.name_of;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   156
val theory_of_thm = theory_of_sign o Thm.sign_of_thm;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   157
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   158
fun put_theory theory =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   159
  change_thy (PureThy.get_name theory) (fn (deps, _) => (deps, (Some (theory, Symtab.empty))));
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   160
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   161
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   162
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   163
(** thy data **)  (* FIXME *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   164
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   165
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   166
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   167
(** thy operations **)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   168
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   169
fun FIXME msg = writeln ("DEBUG:\n" ^ msg);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   170
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   171
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   172
(* touch_thy -- mark as outdated *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   173
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   174
fun touch_thy name = change_deps name
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   175
  (fn None => (warning (loader_msg "tried to touch finished theory" [name]); None)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   176
    | Some {present, outdated = _, master, files} =>
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   177
        make_depends present true master files);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   178
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   179
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   180
(* load_thy *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   181
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   182
fun required_by [] = ""
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   183
  | required_by initiators = " (required by " ^ show_path (rev initiators) ^ ")";
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   184
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   185
fun load_thy ml time initiators name parents =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   186
  let
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   187
    val _ = if name mem_string initiators then error (cycle_msg name (rev initiators)) else ();
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   188
    val _ = writeln ("Loading theory " ^ quote name ^ required_by initiators);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   189
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   190
    val _ = seq touch_thy (thy_graph Graph.all_succs [name]);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   191
    val master = ThyLoad.load_thy name ml time;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   192
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   193
    val files = get_files name;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   194
    val missing_files = mapfilter (fn (path, None) => Some (Path.pack path) | _ => None) files;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   195
  in
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   196
    if null missing_files then ()
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   197
    else warning (loader_msg ("unresolved dependencies on file(s) " ^ commas_quote missing_files ^
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   198
      "\nfor theory") [name]);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   199
    change_deps name (fn _ => make_depends true false (Some master) files)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   200
  end;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   201
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   202
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   203
(* load_file *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   204
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   205
fun load_file path =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   206
  let
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   207
    fun provide name info (deps as Some {present, outdated, master, files}) =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   208
          if exists (equal path o #1) files then
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   209
            make_depends present outdated master (overwrite (files, (path, Some info)))
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   210
          else (warning (loader_msg ("undeclared dependency on file " ^ quote (Path.pack path) ^
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   211
            "\nfor theory") [name]); deps)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   212
      | provide _ _ None = None;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   213
  in
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   214
    (case apsome PureThy.get_name (Context.get_context ()) of
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   215
      None => (ThyLoad.load_file path; ())
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   216
    | Some name =>
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   217
        if is_some (lookup_thy name) then change_deps name (provide name (ThyLoad.load_file path))
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   218
        else (ThyLoad.load_file path; ()))
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   219
  end;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   220
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   221
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   222
(* require_thy *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   223
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   224
fun init_deps master files = make_depends false false master (map (rpair None) files);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   225
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   226
fun load_deps name ml =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   227
  let val (master, (parents, files)) = ThyLoad.deps_thy name ml
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   228
  in (Some (init_deps (Some master) files), parents) end;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   229
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   230
fun file_current (_, None) = false
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   231
  | file_current (path, info) = info = ThyLoad.check_file path;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   232
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   233
fun current_deps ml strict name =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   234
  (case lookup_deps name of
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   235
    None => (false, load_deps name ml)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   236
  | Some deps =>
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   237
      let val same_deps = (None, thy_graph Graph.imm_preds name) in
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   238
        (case deps of
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   239
          None => (true, same_deps)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   240
        | Some {present, outdated, master, files} =>
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   241
            if present andalso not strict then (true, same_deps)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   242
            else
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   243
              let val master' = Some (ThyLoad.check_thy name) in
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   244
                if master <> master' then (false, load_deps name ml)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   245
                else (not outdated andalso forall file_current files, same_deps)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   246
              end)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   247
      end);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   248
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   249
fun outdated name =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   250
  (case lookup_deps name of Some (Some {outdated, ...}) => outdated | _ => false);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   251
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   252
fun require_thy ml time strict keep_strict initiators name =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   253
  let
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   254
    val require_parent =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   255
      require_thy ml time (strict andalso keep_strict) keep_strict (name :: initiators);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   256
    val (current, (new_deps, parents)) = current_deps ml strict name handle ERROR =>
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   257
      error (loader_msg "The error(s) above occurred while examining theory" [name] ^ "\n" ^
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   258
        required_by initiators);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   259
    val pre_outdated = outdated name;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   260
  in
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   261
    seq require_parent parents;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   262
    if current andalso pre_outdated = outdated name then ()	(* FIXME ?? *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   263
    else
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   264
      ((case new_deps of
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   265
        Some deps => change_thys (update_node name parents (deps, None))
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   266
      | None => ()); load_thy ml time initiators name parents)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   267
  end;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   268
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   269
val weak_use_thy = require_thy true false false false [];
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   270
val use_thy      = require_thy true false true false [];
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   271
val update_thy   = require_thy true false true true [];
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   272
val time_use_thy = require_thy true true true false [];
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   273
val use_thy_only = require_thy false false true false [];
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   274
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   275
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   276
(* begin / end theory *)		(* FIXME tune *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   277
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   278
fun begin_theory name parents =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   279
  let
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   280
    val _ = seq weak_use_thy parents;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   281
    val theory = PureThy.begin_theory name (map get_theory parents);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   282
    val _ = change_thys (update_node name parents (init_deps None [], Some (theory, Symtab.empty)));
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   283
  in theory end;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   284
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   285
fun end_theory theory =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   286
  let val theory' = PureThy.end_theory theory
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   287
  in put_theory theory'; theory' end;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   288
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   289
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   290
(* finish entries *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   291
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   292
(* FIXME
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   293
fun finishs names =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   294
  let
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   295
    fun err txt bads =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   296
      error (loader_msg txt bads ^ "\n" ^ gen_msg "cannot mark" names ^ " as finished");
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   297
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   298
    val all_preds = thy_graph Graph.all_preds names;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   299
    val noncurrent = filter_out is_current all_preds;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   300
    val unfinished = filter_out is_finished (all_preds \\ names);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   301
  in
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   302
    if not (null noncurrent) then err "non-current theories" noncurrent
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   303
    else if not (null unfinished) then err "unfinished ancestor theories" unfinished
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   304
    else seq (fn name => change_thy name (apfst (K Finished)))
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   305
  end;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   306
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   307
fun finish name = finishs [name];
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   308
*)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   309
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   310
fun update_all () = ();         (* FIXME fake *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   311
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   312
fun finish_all () = (update_all (); change_thys (Graph.map_nodes (fn (_, entry) => (None, entry))));
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   313
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   314
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   315
(* register existing theories *)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   316
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   317
fun register_theory theory =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   318
  let
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   319
    val name = PureThy.get_name theory;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   320
    val parents = Theory.parents_of theory;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   321
    val parent_names = map PureThy.get_name parents;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   322
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   323
    fun err txt bads =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   324
      error (loader_msg txt bads ^ "\n" ^ gen_msg "cannot register theory" [name]);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   325
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   326
    val unfinished = filter_out is_finished parent_names;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   327
    fun get_variant (x, y_name) =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   328
      if Theory.eq_thy (x, get_theory y_name) then None
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   329
      else Some y_name;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   330
    val variants = mapfilter get_variant (parents ~~ parent_names);
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   331
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   332
    fun register G =
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   333
      (Graph.new_node (name, (None, Some (theory, Symtab.empty))) G
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   334
        handle Graph.DUPLICATE _ => err "duplicate theory entry" [])
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   335
      |> add_deps name parent_names;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   336
  in
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   337
    if not (null unfinished) then err "unfinished parent theories" unfinished
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   338
    else if not (null variants) then err "different versions of parent theories" variants
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   339
    else change_thys register
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   340
  end;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   341
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   342
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   343
(*final declarations of this structure*)
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   344
val theory = get_theory;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   345
val names = get_names;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   346
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   347
end;
43d0efafa025 Theory loader database: theory and file dependencies, theory values
wenzelm
parents: 5211
diff changeset
   348
5209
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
   349
structure BasicThyInfo: BASIC_THY_INFO = ThyInfo;
a69fe5a61b6c theory_of renamed to theory (and made public);
wenzelm
parents: 4975
diff changeset
   350
open BasicThyInfo;