123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173(************************************************************************)(* * 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) *)(************************************************************************)openUtilopenNamesletmake_dirl=DirPath.make(List.rev_mapId.of_stringl)(************************************************************************)(* Coq reference API *)(************************************************************************)letcoq=Libnames.coq_string(* "Coq" *)letinit_dir=[coq;"Init"]letjmeq_module_name=[coq;"Logic";"JMeq"]letfind_referencelocstrdirs=letdp=make_dirdirinletsp=Libnames.make_pathdp(Id.of_strings)inNametab.global_of_pathspletcoq_referencelocstrdirs=find_referencelocstr(coq::dir)slettable:GlobRef.tCString.Map.tref=Summary.ref~name:"coqlib_registered"CString.Map.emptyletget_lib_refs()=CString.Map.bindings!tablelethas_refs=CString.Map.mems!tableletcheck_refsgr=matchCString.Map.finds!tablewith|r->GlobRef.UserOrd.equalrgr|exceptionNot_found->falseletcheck_ind_refsind=check_refs(GlobRef.IndRefind)exceptionNotFoundRefofstringlet()=CErrors.register_handler(function|NotFoundRefs->SomePp.(str"not found in table: "++strs)|_->None)letlib_refs=tryCString.Map.finds!tablewithNot_found->raise(NotFoundRefs)letlib_ref_opts=CString.Map.find_opts!tableletadd_refsc=table:=CString.Map.addsc!tableletcache_ref(s,c)=add_refsclet(inCoqlibRef:string*GlobRef.t->Libobject.obj)=letopenLibobjectindeclare_object{(default_object"COQLIBREF")withcache_function=cache_ref;load_function=(fun_x->cache_refx);classify_function=(fun_->Substitute);subst_function=ident_subst_function;discharge_function=(funsc->Somesc);}(** Replaces a binding ! *)letregister_refsc=Lib.add_leaf@@inCoqlibRef(s,c)(************************************************************************)(* Generic functions to find Coq objects *)lethas_suffix_in_dirsdirsref=letdir=Libnames.dirpath(Nametab.path_of_globalref)inList.exists(fund->Libnames.is_dirpath_prefix_ofddir)dirsletgen_reference_in_moduleslocstrdirss=letdirs=List.mapmake_dirdirsinletqualid=Libnames.qualid_of_stringsinletall=Nametab.locate_allqualidinletall=List.sort_uniquizeGlobRef.UserOrd.compareallinletthese=List.filter(has_suffix_in_dirsdirs)allinmatchthesewith|[x]->x|[]->CErrors.anomaly~label:locstrPp.(str"cannot find "++strs++str" in module"++str(ifList.lengthdirs>1then"s "else" ")++prlist_with_seppr_commaDirPath.printdirs++str".")|l->CErrors.anomaly~label:locstrPp.(str"ambiguous name "++strs++str" can represent "++prlist_with_seppr_comma(funx->Libnames.pr_path(Nametab.path_of_globalx))l++str" in module"++str(ifList.lengthdirs>1then"s "else" ")++prlist_with_seppr_commaDirPath.printdirs++str".")(* For tactics/commands requiring vernacular libraries *)letcheck_required_libraryd=letdir=make_dirdintrylet_:Declarations.module_body=Global.lookup_module(ModPath.MPfiledir)in()withNot_found->letin_current_dir=matchLib.current_mp()with|MPfiledp->DirPath.equaldirdp|_->falseinifnotin_current_dirthenCErrors.user_errPp.(str"Library "++DirPath.printdir++str" has to be required first.")(************************************************************************)(* Specific Coq objects *)(************************************************************************)letlogic_module_name=init_dir@["Logic"]letdatatypes_module_name=init_dir@["Datatypes"](** Identity *)(* Sigma data *)typecoq_sigma_data={proj1:GlobRef.t;proj2:GlobRef.t;elim:GlobRef.t;intro:GlobRef.t;typ:GlobRef.t}letbuild_sigma_genstr={typ=lib_ref("core."^str^".type");elim=lib_ref("core."^str^".rect");intro=lib_ref("core."^str^".intro");proj1=lib_ref("core."^str^".proj1");proj2=lib_ref("core."^str^".proj2");}letbuild_prod()=build_sigma_gen"prod"letbuild_sigma()=build_sigma_gen"sig"letbuild_sigma_type()=build_sigma_gen"sigT"(* Equalities *)typecoq_eq_data={eq:GlobRef.t;ind:GlobRef.t;refl:GlobRef.t;sym:GlobRef.t;trans:GlobRef.t;congr:GlobRef.t}(* Leibniz equality on Type *)letbuild_eqdata_genstr={eq=lib_ref("core."^str^".type");ind=lib_ref("core."^str^".ind");refl=lib_ref("core."^str^".refl");sym=lib_ref("core."^str^".sym");trans=lib_ref("core."^str^".trans");congr=lib_ref("core."^str^".congr");}letbuild_coq_eq_data()=build_eqdata_gen"eq"letbuild_coq_jmeq_data()=build_eqdata_gen"JMeq"letbuild_coq_identity_data()=build_eqdata_gen"identity"