(* Copyright (C) 2000, HELM Team. * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://cs.unibo.it/helm/. *) (*****************************************************************************) (* *) (* PROJECT HELM *) (* *) (* Enrico Tassi *) (* 23/04/2004 *) (* *) (* This module implements some useful function regarding univers graphs *) (* *) (*****************************************************************************) module C = Cic module H = UriManager.UriHashtbl let eq = UriManager.eq (* uri is the uri of the actual object that must be 'skipped' *) let universes_of_obj uri t = (* don't the same work twice *) let visited_objs = H.create 31 in let visited u = H.replace visited_objs u true in let is_not_visited u = not (H.mem visited_objs u) in visited uri; (* the result *) let results = ref [] in let add_result l = results := l :: !results in (* the iterators *) let rec aux = function | C.Const (u,exp_named_subst) | C.Var (u,exp_named_subst) when is_not_visited u -> aux_uri u; visited u; List.iter (fun (_,t) -> aux t) exp_named_subst | C.Const (u,exp_named_subst) | C.Var (u,exp_named_subst) -> List.iter (fun (_,t) -> aux t) exp_named_subst | C.MutInd (u,_,exp_named_subst) when is_not_visited u -> visited u; (match fst(CicEnvironment.get_obj CicUniv.empty_ugraph u) with | C.InductiveDefinition (l,_,_,_) -> List.iter (fun (_,_,t,l') -> aux t; List.iter (fun (_,t) -> aux t) l') l | _ -> assert false); List.iter (fun (_,t) -> aux t) exp_named_subst | C.MutInd (_,_,exp_named_subst) -> List.iter (fun (_,t) -> aux t) exp_named_subst | C.MutConstruct (u,_,_,exp_named_subst) when is_not_visited u -> visited u; (match fst(CicEnvironment.get_obj CicUniv.empty_ugraph u) with | C.InductiveDefinition (l,_,_,_) -> List.iter (fun (_,_,t,l') -> aux t; List.iter (fun (_,t) -> aux t) l') l | _ -> assert false); List.iter (fun (_,t) -> aux t) exp_named_subst | C.MutConstruct (_,_,_,exp_named_subst) -> List.iter (fun (_,t) -> aux t) exp_named_subst | C.Meta (n,l1) -> List.iter (fun t -> match t with Some t' -> aux t' | _ -> ()) l1 | C.Sort ( C.Type i) -> add_result [i] | C.Rel _ | C.Sort _ | C.Implicit _ -> () | C.Cast (v,t) -> aux v; aux t | C.Prod (b,s,t) | C.Lambda (b,s,t) | C.LetIn (b,s,t) -> aux s; aux t | C.Appl li -> List.iter (fun t -> aux t) li | C.MutCase (uri,n1,ty,te,patterns) -> aux ty; aux te; (List.iter (fun t -> aux t) patterns) | C.Fix (no, funs) -> List.iter (fun (_,_,b,c) -> aux b; aux c) funs | C.CoFix (no,funs) -> List.iter (fun (_,b,c) -> aux b; aux c) funs and aux_uri u = if is_not_visited u then let _, _, l = CicEnvironment.get_cooked_obj_with_univlist CicUniv.empty_ugraph u in add_result l and aux_obj = function | C.Constant (_,Some te,ty,v,_) | C.Variable (_,Some te,ty,v,_) -> aux te; aux ty; List.iter aux_uri v | C.Constant (_,None, ty, v,_) | C.Variable (_,None, ty, v,_) -> aux ty; List.iter aux_uri v | C.CurrentProof (_,conjs,te,ty,v,_) -> assert false | C.InductiveDefinition (l,v,_,_) -> List.iter (fun (_,_,t,l') -> aux t; List.iter (fun (_,t) -> aux t) l') l; List.iter aux_uri v in aux_obj t; List.flatten !results let rec list_uniq = function | [] -> [] | h::[] -> [h] | h1::h2::tl when CicUniv.eq h1 h2 -> list_uniq (h2 :: tl) | h1::tl (* when h1 <> h2 *) -> h1 :: list_uniq tl let list_uniq l = list_uniq (List.fast_sort CicUniv.compare l) let clean_and_fill uri obj ugraph = let list_of_universes = universes_of_obj uri obj in let list_of_universes = list_uniq list_of_universes in let ugraph = CicUniv.clean_ugraph ugraph list_of_universes in let ugraph, list_of_universes = CicUniv.fill_empty_nodes_with_uri ugraph list_of_universes uri in ugraph, list_of_universes