src/Pure/Thy/thy_info.ML
changeset 4111 93baba60ece2
parent 3997 42062f636bdf
child 4964 bbe9065edf8a
     1.1 --- a/src/Pure/Thy/thy_info.ML	Tue Nov 04 09:27:32 1997 +0100
     1.2 +++ b/src/Pure/Thy/thy_info.ML	Tue Nov 04 12:03:48 1997 +0100
     1.3 @@ -2,71 +2,44 @@
     1.4      ID:         $Id$
     1.5      Author:     Stefan Berghofer and Markus Wenzel, TU Muenchen
     1.6  
     1.7 -Theory loader info database.
     1.8 +Theory loader database.
     1.9  *)
    1.10  
    1.11 -(* FIXME wipe out! *)
    1.12 -(*Functions to handle arbitrary data added by the user; type "exn" is used
    1.13 -  to store data*)
    1.14 -datatype thy_methods =
    1.15 -  ThyMethods of {merge: exn list -> exn, put: exn -> unit, get: unit -> exn};
    1.16 -
    1.17 -
    1.18  type thy_info =
    1.19    {path: string,
    1.20      children: string list, parents: string list,
    1.21      thy_time: string option, ml_time: string option,
    1.22 -    theory: theory option, thms: thm Symtab.table,
    1.23 -    methods: thy_methods Symtab.table,
    1.24 -    data: exn Symtab.table * exn Symtab.table};
    1.25 +    theory: theory option};
    1.26  
    1.27  (*
    1.28 -        path: directory where theory's files are located
    1.29 -
    1.30 -        thy_time, ml_time = None     theory file has not been read yet
    1.31 -                          = Some ""  theory was read but has either been marked
    1.32 -                                     as outdated or there is no such file for
    1.33 -                                     this theory (see e.g. 'virtual' theories
    1.34 -                                     like Pure or theories without a ML file)
    1.35 -        theory = None  theory has not been read yet
    1.36 +  path: directory where theory's files are located
    1.37 +	(* FIXME do not store absolute path!!! *)
    1.38  
    1.39 -        parents: While 'children' contains all theories the theory depends
    1.40 -                 on (i.e. also ones quoted in the .thy file),
    1.41 -                 'parents' only contains the theories which were used to form
    1.42 -                 the base of this theory.
    1.43 +  thy_time, ml_time = None     theory file has not been read yet
    1.44 +                    = Some ""  theory was read but has either been marked
    1.45 +                               as outdated or there is no such file for
    1.46 +                               this theory (see e.g. 'virtual' theories
    1.47 +                               like Pure or theories without a ML file)
    1.48 +  theory = None  theory has not been read yet
    1.49  
    1.50 -        methods: three methods for each user defined data;
    1.51 -                 merge: merges data of ancestor theories
    1.52 -                 put: retrieves data from loaded_thys and stores it somewhere
    1.53 -                 get: retrieves data from somewhere and stores it
    1.54 -                      in loaded_thys
    1.55 -        data: user defined data; exn is used to allow arbitrary types;
    1.56 -              first element of pairs contains result that get returned after
    1.57 -              thy file was read, second element after ML file was read;
    1.58 -              if ML files has not been read, second element is identical to
    1.59 -              first one because get_thydata, which is meant to return the
    1.60 -              latest data, always accesses the 2nd element
    1.61 +  parents: While 'children' contains all theories the theory depends
    1.62 +           on (i.e. also ones quoted in the .thy file),
    1.63 +           'parents' only contains the theories which were used to form
    1.64 +           the base of this theory.
    1.65  *)
    1.66  
    1.67  signature THY_INFO =
    1.68  sig
    1.69 -  val loaded_thys    : thy_info Symtab.table ref
    1.70 -  val store_theory   : theory * string -> unit
    1.71 -
    1.72 -  val theory_of      : string -> theory
    1.73 -  val theory_of_sign : Sign.sg -> theory
    1.74 -  val theory_of_thm  : thm -> theory
    1.75 -  val children_of    : string -> string list
    1.76 +  val loaded_thys: thy_info Symtab.table ref
    1.77 +  val get_thyinfo: string -> thy_info option
    1.78 +  val store_theory: theory * string -> unit
    1.79 +  val path_of: string -> string
    1.80 +  val children_of: string -> string list
    1.81    val parents_of_name: string -> string list
    1.82    val thyinfo_of_sign: Sign.sg -> string * thy_info
    1.83 -
    1.84 -  val add_thydata    : string -> string * thy_methods -> unit
    1.85 -  val get_thydata    : string -> string -> exn option
    1.86 -  val put_thydata    : bool -> string -> unit
    1.87 -  val set_current_thy: string -> unit
    1.88 -  val get_thyinfo    : string -> thy_info option
    1.89 -
    1.90 -  val path_of        : string -> string
    1.91 +  val theory_of: string -> theory
    1.92 +  val theory_of_sign: Sign.sg -> theory
    1.93 +  val theory_of_thm: thm -> theory
    1.94  end;
    1.95  
    1.96  
    1.97 @@ -76,10 +49,8 @@
    1.98  (* loaded theories *)
    1.99  
   1.100  fun mk_info (name, children, parents, theory) =
   1.101 -  (name,
   1.102 -    {path = "", children = children, parents = parents, thy_time = Some "",
   1.103 -      ml_time = Some "", theory = Some theory, thms = Symtab.null,
   1.104 -      methods = Symtab.null, data = (Symtab.null, Symtab.null)}: thy_info);
   1.105 +  (name, {path = "", children = children, parents = parents,
   1.106 +    thy_time = Some "", ml_time = Some "", theory = Some theory}: thy_info);
   1.107  
   1.108  (*preloaded theories*)
   1.109  val loaded_thys =
   1.110 @@ -122,72 +93,33 @@
   1.111  (*get all direct descendants of a theory*)
   1.112  fun children_of t =
   1.113    (case get_thyinfo t of
   1.114 -    Some ({children, ...}) => children
   1.115 +    Some {children, ...} => children
   1.116    | None => []);
   1.117  
   1.118  (*get all direct ancestors of a theory*)
   1.119  fun parents_of_name t =
   1.120    (case get_thyinfo t of
   1.121 -    Some ({parents, ...}) => parents
   1.122 +    Some {parents, ...} => parents
   1.123    | None => []);
   1.124  
   1.125  (*get theory object for a loaded theory*)
   1.126  fun theory_of name =
   1.127    (case get_thyinfo name of
   1.128 -    Some ({theory = Some t, ...}) => t
   1.129 +    Some {theory = Some t, ...} => t
   1.130    | _ => err_not_stored name);
   1.131  
   1.132  
   1.133 -(*invoke every put method stored in a theory's methods table to initialize
   1.134 -  the state of user defined variables*)
   1.135 -fun put_thydata first tname =
   1.136 -  let val (methods, data) = 
   1.137 -        case get_thyinfo tname of
   1.138 -            Some ({methods, data, ...}) =>
   1.139 -              (methods, Symtab.dest ((if first then fst else snd) data))
   1.140 -          | None => err_not_stored tname;
   1.141 -
   1.142 -      fun put_data (id, date) =
   1.143 -            case Symtab.lookup (methods, id) of
   1.144 -                Some (ThyMethods {put, ...}) => put date
   1.145 -              | None => error ("No method defined for theory data \"" ^
   1.146 -                               id ^ "\"");
   1.147 -  in seq put_data data end;
   1.148 -
   1.149 -
   1.150 -val set_current_thy = put_thydata false;
   1.151 -
   1.152 +(* store_theory *)
   1.153  
   1.154 -(*Change theory object for an existent item of loaded_thys*)
   1.155 -fun store_theory (thy, tname) =
   1.156 -  let val tinfo = case Symtab.lookup (!loaded_thys, tname) of
   1.157 -               Some ({path, children, parents, thy_time, ml_time, thms,
   1.158 -                              methods, data, ...}) =>
   1.159 -                 {path = path, children = children, parents = parents,
   1.160 -                          thy_time = thy_time, ml_time = ml_time,
   1.161 -                          theory = Some thy, thms = thms,
   1.162 -                          methods = methods, data = data}
   1.163 -             | None => error ("store_theory: theory " ^ tname ^ " not found");
   1.164 -  in loaded_thys := Symtab.update ((tname, tinfo), !loaded_thys) end;
   1.165 -
   1.166 -
   1.167 -(*** Misc functions ***)
   1.168 -
   1.169 -(*Add data handling methods to theory*)
   1.170 -fun add_thydata tname (new_methods as (id, ThyMethods {get, ...})) =
   1.171 -  let val {path, children, parents, thy_time, ml_time, theory,
   1.172 -                   thms, methods, data} = the_thyinfo tname;
   1.173 -  in loaded_thys := Symtab.update ((tname, {path = path,
   1.174 -       children = children, parents = parents, thy_time = thy_time,
   1.175 -       ml_time = ml_time, theory = theory, thms = thms,
   1.176 -       methods = Symtab.update (new_methods, methods), data = data}),
   1.177 -       !loaded_thys)
   1.178 +fun store_theory (thy, name) =
   1.179 +  let
   1.180 +    val {path, children, parents, thy_time, ml_time, theory = _} =
   1.181 +      the_thyinfo name;
   1.182 +    val info = {path = path, children = children, parents = parents,
   1.183 +      thy_time = thy_time, ml_time = ml_time, theory = Some thy};
   1.184 +  in
   1.185 +    loaded_thys := Symtab.update ((name, info), ! loaded_thys)
   1.186    end;
   1.187  
   1.188  
   1.189 -(*retrieve data associated with theory*)
   1.190 -fun get_thydata name id =
   1.191 -  Symtab.lookup (snd (#data (the_thyinfo name)), id);
   1.192 -
   1.193 -
   1.194  end;