123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118(************************************************************************)(* * 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) *)(************************************************************************)(*i*)openNamesopenGlobnamesopenConstropenContextopenEnvironopenUtilopenLibobject(*i*)letname_table=Summary.ref(GlobRef.Map.empty:Name.tlistGlobRef.Map.t)~name:"rename-arguments"typereq=|ReqLocal|ReqGlobalofGlobRef.t*Name.tlistletload_rename_args_(_,(r,names))=name_table:=GlobRef.Map.addrnames!name_tableletcache_rename_argso=load_rename_args1oletclassify_rename_args=function|ReqLocal,_->Dispose|ReqGlobal_,_->Substituteletsubst_rename_args(subst,(_,(r,namesasorig)))=ReqLocal,letr'=fst(subst_globalsubstr)inifr==r'thenorigelse(r',names)letdischarge_rename_args=function|ReqGlobal(c,names),_asreqwhennot(isVarRefc&&Lib.is_in_sectionc)->(tryletvar_names=Array.map_to_list(func->Name(destVarc))(Lib.section_instancec)inletnames'=var_names@namesinSome(ReqGlobal(c,names),(c,names'))withNot_found->Somereq)|_->Noneletrebuild_rename_argsx=xletinRenameArgs=declare_object{(default_object"RENAME-ARGUMENTS")withload_function=load_rename_args;cache_function=cache_rename_args;classify_function=classify_rename_args;subst_function=subst_rename_args;discharge_function=discharge_rename_args;rebuild_function=rebuild_rename_args;}letrename_argumentslocalrnames=let()=matchrwith|GlobRef.VarRefid->CErrors.user_errPp.(str"Arguments of section variables such as "++Id.printid++str" may not be renamed.")|_->()inletreq=iflocalthenReqLocalelseReqGlobal(r,names)inLib.add_leaf(inRenameArgs(req,(r,names)))letarguments_namesr=GlobRef.Map.findr!name_tableletrename_typetyref=letname_overrideold_nameoverride=matchoverridewith|Name_asx->{old_namewithbinder_name=x}|Anonymous->old_nameinletrecrename_type_auxc=function|[]->c|rename::restasrenamings->matchConstr.kindcwith|Prod(old,s,t)->mkProd(name_overrideoldrename,s,rename_type_auxtrest)|LetIn(old,s,b,t)->mkLetIn(old,s,b,rename_type_auxtrenamings)|Cast(t,_,_)->rename_type_auxtrenamings|_->cintryrename_type_auxty(arguments_namesref)withNot_found->tyletrename_type_of_constantenvc=letty=Typeops.type_of_constant_inenvcinrename_typety(GlobRef.ConstRef(fstc))letrename_type_of_inductiveenvind=letty=Inductiveops.type_of_inductiveenvindinrename_typety(GlobRef.IndRef(fstind))letrename_type_of_constructorenvcstruct=letty=Inductiveops.type_of_constructorenvcstructinrename_typety(GlobRef.ConstructRef(fstcstruct))letrename_typingenvc=letj=Typeops.inferenvcinletj'=matchkindcwith|Const(c,u)->{jwithuj_type=rename_typej.uj_type(GlobRef.ConstRefc)}|Ind(i,u)->{jwithuj_type=rename_typej.uj_type(GlobRef.IndRefi)}|Construct(k,u)->{jwithuj_type=rename_typej.uj_type(GlobRef.ConstructRefk)}|_->jinj'