1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(**************************************************************************)(* This file is part of the Codex semantics library. *)(* *)(* Copyright (C) 2013-2025 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file LICENSE). *)(* *)(**************************************************************************)openWtomoduletypeNODE=sigtypetvalequal:t->t->boolvalhash:t->intvalpretty:Format.formatter->t->unitendmoduleMake(N:NODE)=structletrecmap_auxfacc=function|[]->acc|Noden::rest->map_auxf(Node(fnfalse)::acc)rest|Component(h,l)::rest->letnew_head=fhtrueinletnew_comp=map_auxf[]linmap_auxf(Component(new_head,new_comp)::acc)restletmapfpartition=map_auxf[]partitionletreciterf=function|[]->()|Noden::rest->fnfalse;iterfrest|Component(h,l)::rest->fhtrue;iterfl;iterfrestletrecflatten_auxaccpartition=letr_flattened=List.fold_left(funacc->function|Noden->n::acc|Component(h,l)->flatten_aux(h::acc)l)accpartitioninList.revr_flattenedletflattenpartition=flatten_aux[]partitionletrecis_head_ofpartitionhn=matchpartitionwith|[]->raise(Invalid_argument"Wto_utils.head_of")|Noden::rest->is_head_ofresthn|Component(h',l)asc::rest->ifN.equalhh'thenList.exists(N.equaln)@@flatten[c]elseis_head_oflhn||is_head_ofresthnletrecdepth_auxacc=function|[]->acc|Node_::rest->depth_auxaccrest|Component(_,body)::rest->depth_aux(maxacc(depth_auxaccbody))restletdepthpartition=depth_aux0partitionend