aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar gareuselesinge <gareuselesinge@85f007b7-540e-0410-9357-904b9bb8a0f7>2013-08-09 06:09:52 +0000
committerGravatar gareuselesinge <gareuselesinge@85f007b7-540e-0410-9357-904b9bb8a0f7>2013-08-09 06:09:52 +0000
commit6410e8c242d50eb0571d0e6feea4526979c8b0b2 (patch)
tree2eac7acf7ba6008b45727742f33cc0ef60c65e99 /lib
parentdc6c9c950700a9707ff1f473ef687f0bda597eb3 (diff)
state_id data type
(this should have been the first commit of Paral-ITP) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@16688 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'lib')
-rw-r--r--lib/clib.mllib2
-rw-r--r--lib/stateid.ml37
-rw-r--r--lib/stateid.mli31
3 files changed, 70 insertions, 0 deletions
diff --git a/lib/clib.mllib b/lib/clib.mllib
index 01f112715..f8e92f4af 100644
--- a/lib/clib.mllib
+++ b/lib/clib.mllib
@@ -20,6 +20,8 @@ CString
CArray
Util
Loc
+Flags
+Stateid
Serialize
Xml_utils
CUnix
diff --git a/lib/stateid.ml b/lib/stateid.ml
new file mode 100644
index 000000000..3abd80cfb
--- /dev/null
+++ b/lib/stateid.ml
@@ -0,0 +1,37 @@
+(************************************************************************)
+(* v * The Coq Proof Assistant / The Coq Development Team *)
+(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2010 *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(************************************************************************)
+
+open Xml_datatype
+
+type state_id = int
+let initial_state_id = 1
+let dummy_state_id = 0
+let fresh_state_id, in_range =
+ let cur = ref initial_state_id in
+ (fun () -> incr cur; !cur), (fun id -> id >= 0 && id <= !cur)
+let string_of_state_id = string_of_int
+let state_id_of_int id = assert(in_range id); id
+let int_of_state_id id = id
+let newer_than id1 id2 = id1 > id2
+
+let to_state_id = function
+ | Element ("state_id",["val",i],[]) ->
+ let id = int_of_string i in
+ (* Coqide too to parse ids too, but cannot check if they are valid.
+ * Hence we check for validity only if we are an ide slave. *)
+ if !Flags.ide_slave then assert(in_range id);
+ id
+ | _ -> raise (Invalid_argument "to_state_id")
+let of_state_id i = Element ("state_id",["val",string_of_int i],[])
+
+let state_id_info : (state_id * state_id) Exninfo.t = Exninfo.make ()
+let add_state_id exn ?(valid = initial_state_id) id =
+ Exninfo.add exn state_id_info (valid, id)
+let get_state_id exn = Exninfo.get exn state_id_info
+
+module StateidOrderedType = struct type t = state_id let compare = compare end
diff --git a/lib/stateid.mli b/lib/stateid.mli
new file mode 100644
index 000000000..978f12691
--- /dev/null
+++ b/lib/stateid.mli
@@ -0,0 +1,31 @@
+(************************************************************************)
+(* v * The Coq Proof Assistant / The Coq Development Team *)
+(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2010 *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(************************************************************************)
+
+open Xml_datatype
+
+type state_id
+val initial_state_id : state_id
+val dummy_state_id : state_id
+val fresh_state_id : unit -> state_id
+val string_of_state_id : state_id -> string
+val state_id_of_int : int -> state_id
+val int_of_state_id : state_id -> int
+val newer_than : state_id -> state_id -> bool
+
+(* XML marshalling *)
+val of_state_id : state_id -> xml
+val to_state_id : xml -> state_id
+
+(* Attaches to an exception the concerned state id, plus an optional
+ * state id that is a valid state id before the error.
+ * Backtracking to the valid id is safe.
+ * The initial_state_id is assumed to be safe. *)
+val add_state_id : exn -> ?valid:state_id -> state_id -> exn
+val get_state_id : exn -> (state_id * state_id) option
+
+module StateidOrderedType : Map.OrderedType with type t = state_id