aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/stateid.ml
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/stateid.ml
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/stateid.ml')
-rw-r--r--lib/stateid.ml37
1 files changed, 37 insertions, 0 deletions
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