123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)(* Reserved names *)openCErrorsopenUtilopenPpopenNamesopenNameopsopenNotation_termopenNotation_opstypekey=|RefKeyofGlobRef.t|Oth(** TODO: share code from Notation *)letcanonize_keyenvk=matchkwith|Oth->Oth|RefKeygr->letgr'=Environ.QGlobRef.canonizeenvgrinifgr'==grthenkelseRefKeygr'letmkRefKeyenvgr=RefKey(Environ.QGlobRef.canonizeenvgr)letkey_comparek1k2=matchk1,k2with|RefKeygr1,RefKeygr2->GlobRef.UserOrd.comparegr1gr2|RefKey_,Oth->-1|Oth,RefKey_->1|Oth,Oth->0moduleKeyOrd=structtypet=keyletcompare=key_compareendmoduleKeyMap=Map.Make(KeyOrd)moduleReservedSet:sigtypetvalempty:tvaladd:(Id.t*notation_constr)->t->tvalfind:(Id.t->notation_constr->bool)->t->Id.t*notation_constrend=structtypet=(Id.t*notation_constr)listletempty=[]letrecmemidc=function|[]->false|(id',c')::l->ifc==c'&&Id.equalidid'thentrueelsememidclletaddpl=let(id,c)=pinifmemidclthenlelsep::lletrecfindf=function|[]->raiseNot_found|(id,c)asp::l->iffidcthenpelsefindflendletkeymap_addenvkeydatamap=letkey=canonize_keyenvkeyinletold=tryKeyMap.findkeymapwithNot_found->ReservedSet.emptyinKeyMap.addkey(ReservedSet.adddataold)mapletreserve_table=Summary.refId.Map.empty~name:"reserved-type"letreserve_revtable=Summary.refKeyMap.empty~name:"reserved-type-rev"letnotation_constr_keyenv=function(* Rem: NApp(NRef ref,[]) stands for @ref *)|NApp(NRef(ref,_),args)->mkRefKeyenvref,Some(List.lengthargs)|NList(_,_,NApp(NRef(ref,_),args),_,_)|NBinderList(_,_,NApp(NRef(ref,_),args),_,_)->mkRefKeyenvref,Some(List.lengthargs)|NRef(ref,_)->mkRefKeyenvref,None|_->Oth,Noneletadd_reserved_typeenv(id,t)=letkey=fst(notation_constr_keyenvt)inreserve_table:=Id.Map.addidt!reserve_table;reserve_revtable:=keymap_addenvkey(id,t)!reserve_revtableletdeclare_reserved_type_bindingenv{CAst.loc;v=id}t=ifnot(Id.equalid(root_of_idid))thenuser_err?loc((Id.printid++str" is not reservable: it must have no trailing digits, quote, or _."));begintrylet_=Id.Map.findid!reserve_tableinuser_err?loc((Id.printid++str" is already bound to a type."))withNot_found->()end;add_reserved_typeenv(id,t)letdeclare_reserved_typeidlt=letenv=Global.env()inList.iter(funid->declare_reserved_type_bindingenvidt)(List.revidl)letfind_reserved_typeid=Id.Map.find(root_of_idid)!reserve_tableletconstr_keyenvc=trymkRefKeyenv(fst@@Constr.destRef(fst(Constr.decompose_appc)))withConstr.DestKO->Othletrevert_reserved_typet=tryletenv=Global.env()inlett=EConstr.Unsafe.to_constrtinletreserved=KeyMap.find(constr_keyenvt)!reserve_revtableinlett=EConstr.of_constrtinletevd=Evd.from_envenvinlett=Detyping.detypeDetyping.NowId.Set.emptyenvevdtin(* pedrot: if [Notation_ops.match_notation_constr] may raise [Failure _]
then I've introduced a bug... *)letfilter_pat=trylet_=match_notation_constr~print_univ:falset~vars:Id.Set.empty([],pat)intruewithNo_match->falseinlet(id,_)=ReservedSet.findfilterreservedinNameidwithNot_found|Failure_->Anonymouslet_=Namegen.set_reserved_typed_namerevert_reserved_type