1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 2002 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)(* Consistency tables: for checking consistency of module CRCs *)openMiscmoduleMake(Module_name:sigtypetmoduleSet:Set.Swithtypeelt=tmoduleMap:Map.Swithtypekey=tmoduleTbl:Hashtbl.Swithtypekey=tvalcompare:t->t->intend)(Data:sigtypetend)=structtypet=(Data.t*Digest.t*filepath)Module_name.Tbl.tletcreate()=Module_name.Tbl.create13letclear=Module_name.Tbl.clearexceptionInconsistencyof{unit_name:Module_name.t;inconsistent_source:string;original_source:string;inconsistent_data:Data.t;original_data:Data.t;}exceptionNot_availableofModule_name.tletcheck_tblnamedatacrcsource=let(old_data,old_crc,old_source)=Module_name.Tbl.findtblnameinifnot(Digest.equalcrcold_crc)thenraise(Inconsistency{unit_name=name;inconsistent_source=source;original_source=old_source;inconsistent_data=data;original_data=old_data;})letchecktblnamedatacrcsource=trycheck_tblnamedatacrcsourcewithNot_found->Module_name.Tbl.addtblname(data,crc,source)letcheck_noaddtblnamedatacrcsource=trycheck_tblnamedatacrcsourcewithNot_found->raise(Not_availablename)letsourcetblname=thd3(Module_name.Tbl.findtblname)letfindtname=matchModule_name.Tbl.findtnamewith|exceptionNot_found->None|(data,crc,_)->Some(data,crc)letextractltbl=letl=List.sort_uniqModule_name.comparelinList.fold_left(funasscname->(name,findtblname)::assc)[]lletextract_mapmod_namestbl=Module_name.Set.fold(funnameresult->Module_name.Map.addname(findtblname)result)mod_namesModule_name.Map.emptyletfilterptbl=letto_remove=ref[]inModule_name.Tbl.iter(funname_->ifnot(pname)thento_remove:=name::!to_remove)tbl;List.iter(funname->whileModule_name.Tbl.memtblnamedoModule_name.Tbl.removetblnamedone)!to_removeend