summaryrefslogtreecommitdiff
path: root/library/summary.ml
diff options
context:
space:
mode:
authorGravatar Samuel Mimram <samuel.mimram@ens-lyon.org>2004-07-28 21:54:47 +0000
committerGravatar Samuel Mimram <samuel.mimram@ens-lyon.org>2004-07-28 21:54:47 +0000
commit6b649aba925b6f7462da07599fe67ebb12a3460e (patch)
tree43656bcaa51164548f3fa14e5b10de5ef1088574 /library/summary.ml
Imported Upstream version 8.0pl1upstream/8.0pl1
Diffstat (limited to 'library/summary.ml')
-rw-r--r--library/summary.ml73
1 files changed, 73 insertions, 0 deletions
diff --git a/library/summary.ml b/library/summary.ml
new file mode 100644
index 00000000..fc88350a
--- /dev/null
+++ b/library/summary.ml
@@ -0,0 +1,73 @@
+(************************************************************************)
+(* v * The Coq Proof Assistant / The Coq Development Team *)
+(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(************************************************************************)
+
+(* $Id: summary.ml,v 1.7.2.1 2004/07/16 19:30:36 herbelin Exp $ *)
+
+open Pp
+open Util
+
+type 'a summary_declaration = {
+ freeze_function : unit -> 'a;
+ unfreeze_function : 'a -> unit;
+ init_function : unit -> unit;
+ survive_module : bool ;
+ survive_section : bool }
+
+let summaries =
+ (Hashtbl.create 17 : (string, Dyn.t summary_declaration) Hashtbl.t)
+
+let internal_declare_summary sumname sdecl =
+ let (infun,outfun) = Dyn.create sumname in
+ let dyn_freeze () = infun (sdecl.freeze_function())
+ and dyn_unfreeze sum = sdecl.unfreeze_function (outfun sum)
+ and dyn_init = sdecl.init_function in
+ let ddecl = {
+ freeze_function = dyn_freeze;
+ unfreeze_function = dyn_unfreeze;
+ init_function = dyn_init;
+ survive_module = sdecl.survive_module;
+ survive_section = sdecl.survive_section }
+ in
+ if Hashtbl.mem summaries sumname then
+ anomalylabstrm "Summary.declare_summary"
+ (str "Cannot declare a summary twice: " ++ str sumname);
+ Hashtbl.add summaries sumname ddecl
+
+let declare_summary sumname decl =
+ internal_declare_summary (sumname^"-SUMMARY") decl
+
+type frozen = Dyn.t Stringmap.t
+
+let freeze_summaries () =
+ let m = ref Stringmap.empty in
+ Hashtbl.iter
+ (fun id decl -> m := Stringmap.add id (decl.freeze_function()) !m)
+ summaries;
+ !m
+
+
+let unfreeze_some_summaries p fs =
+ Hashtbl.iter
+ (fun id decl ->
+ try
+ if p decl then
+ decl.unfreeze_function (Stringmap.find id fs)
+ with Not_found -> decl.init_function())
+ summaries
+
+let unfreeze_summaries =
+ unfreeze_some_summaries (fun _ -> true)
+
+let section_unfreeze_summaries =
+ unfreeze_some_summaries (fun decl -> not decl.survive_section)
+
+let module_unfreeze_summaries =
+ unfreeze_some_summaries (fun decl -> not decl.survive_module)
+
+let init_summaries () =
+ Hashtbl.iter (fun _ decl -> decl.init_function()) summaries