1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(*i $Id: reserve.ml 10727 2008-03-28 20:22:43Z msozeau $ i*)
21
let reserve_table = ref Idmap.empty
23
let cache_reserved_type (_,(id,t)) =
24
reserve_table := Idmap.add id t !reserve_table
26
let (in_reserved, _) =
27
declare_object {(default_object "RESERVED-TYPE") with
28
cache_function = cache_reserved_type }
31
Summary.declare_summary "reserved-type"
32
{ Summary.freeze_function = (fun () -> !reserve_table);
33
Summary.unfreeze_function = (fun r -> reserve_table := r);
34
Summary.init_function = (fun () -> reserve_table := Idmap.empty);
35
Summary.survive_module = false;
36
Summary.survive_section = false }
38
let declare_reserved_type (loc,id) t =
39
if id <> root_of_id id then
40
user_err_loc(loc,"declare_reserved_type",
42
" is not reservable: it must have no trailing digits, quote, or _"));
44
let _ = Idmap.find id !reserve_table in
45
user_err_loc(loc,"declare_reserved_type",
46
(pr_id id++str" is already bound to a type"))
47
with Not_found -> () end;
48
add_anonymous_leaf (in_reserved (id,t))
50
let find_reserved_type id = Idmap.find (root_of_id id) !reserve_table
54
let rec unloc = function
55
| RVar (_,id) -> RVar (dummy_loc,id)
56
| RApp (_,g,args) -> RApp (dummy_loc,unloc g, List.map unloc args)
57
| RLambda (_,na,bk,ty,c) -> RLambda (dummy_loc,na,bk,unloc ty,unloc c)
58
| RProd (_,na,bk,ty,c) -> RProd (dummy_loc,na,bk,unloc ty,unloc c)
59
| RLetIn (_,na,b,c) -> RLetIn (dummy_loc,na,unloc b,unloc c)
60
| RCases (_,sty,rtntypopt,tml,pl) ->
61
RCases (dummy_loc,sty,
62
(Option.map unloc rtntypopt),
63
List.map (fun (tm,x) -> (unloc tm,x)) tml,
64
List.map (fun (_,idl,p,c) -> (dummy_loc,idl,p,unloc c)) pl)
65
| RLetTuple (_,nal,(na,po),b,c) ->
66
RLetTuple (dummy_loc,nal,(na,Option.map unloc po),unloc b,unloc c)
67
| RIf (_,c,(na,po),b1,b2) ->
68
RIf (dummy_loc,unloc c,(na,Option.map unloc po),unloc b1,unloc b2)
69
| RRec (_,fk,idl,bl,tyl,bv) ->
70
RRec (dummy_loc,fk,idl,
72
(fun (na,k,obd,ty) -> (na,k,Option.map unloc obd, unloc ty)))
76
| RCast (_,c, CastConv (k,t)) -> RCast (dummy_loc,unloc c, CastConv (k,unloc t))
77
| RCast (_,c, CastCoerce) -> RCast (dummy_loc,unloc c, CastCoerce)
78
| RSort (_,x) -> RSort (dummy_loc,x)
79
| RHole (_,x) -> RHole (dummy_loc,x)
80
| RRef (_,x) -> RRef (dummy_loc,x)
81
| REvar (_,x,l) -> REvar (dummy_loc,x,l)
82
| RPatVar (_,x) -> RPatVar (dummy_loc,x)
83
| RDynamic (_,x) -> RDynamic (dummy_loc,x)
85
let anonymize_if_reserved na t = match na with
88
if not !Flags.raw_print & unloc t = find_reserved_type id
89
then RHole (dummy_loc,Evd.BinderType na)