1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (*****************************************************************************)
30 (* Enrico Tassi <tassi@cs.unibo.it> *)
33 (* This module implements some useful function regarding univers graphs *)
35 (*****************************************************************************)
40 module H = UriManager.UriHashtbl
41 let eq = UriManager.eq
43 (* uri is the uri of the actual object that must be 'skipped' *)
44 let universes_of_obj uri t =
45 (* don't the same work twice *)
46 let visited_objs = H.create 31 in
47 let visited u = H.replace visited_objs u true in
48 let is_not_visited u = not (H.mem visited_objs u) in
51 let results = ref [] in
52 let add_result l = results := l :: !results in
54 let rec aux = function
55 | C.Const (u,exp_named_subst) when is_not_visited u ->
58 C.Const (u, List.map (fun (x,t) -> x,aux t) exp_named_subst)
59 | C.Var (u,exp_named_subst) when is_not_visited u ->
62 C.Var (u, List.map (fun (x,t) -> x,aux t) exp_named_subst)
63 | C.Const (u,exp_named_subst) ->
64 C.Const (u, List.map (fun (x,t) -> x,aux t) exp_named_subst)
65 | C.Var (u,exp_named_subst) ->
66 C.Var (u, List.map (fun (x,t) -> x,aux t) exp_named_subst)
67 | C.MutInd (u,x,exp_named_subst) when is_not_visited u ->
70 C.MutInd (u,x,List.map (fun (x,t) -> x,aux t) exp_named_subst)
71 | C.MutInd (u,x,exp_named_subst) ->
72 C.MutInd (u,x, List.map (fun (x,t) -> x,aux t) exp_named_subst)
73 | C.MutConstruct (u,x,y,exp_named_subst) when is_not_visited u ->
76 C.MutConstruct (u,x,y,List.map (fun (x,t) -> x,aux t) exp_named_subst)
77 | C.MutConstruct (x,y,z,exp_named_subst) ->
78 C.MutConstruct (x,y,z,List.map (fun (x,t) -> x,aux t) exp_named_subst)
79 | C.Meta (n,l1) -> C.Meta (n, List.map (HExtlib.map_option aux) l1)
80 | C.Sort (C.Type i) -> add_result [i];
81 C.Sort (C.Type (CicUniv.name_universe i uri))
82 | C.Sort (C.CProp i) -> add_result [i];
83 C.Sort (C.CProp (CicUniv.name_universe i uri))
86 | C.Implicit _ as x -> x
87 | C.Cast (v,t) -> C.Cast (aux v, aux t)
88 | C.Prod (b,s,t) -> C.Prod (b,aux s, aux t)
89 | C.Lambda (b,s,t) -> C.Lambda (b,aux s, aux t)
90 | C.LetIn (b,s,ty,t) -> C.LetIn (b,aux s, aux ty, aux t)
91 | C.Appl li -> C.Appl (List.map aux li)
92 | C.MutCase (uri,n1,ty,te,patterns) ->
93 C.MutCase (uri,n1,aux ty,aux te, List.map aux patterns)
95 C.Fix(no, List.map (fun (x,y,b,c) -> (x,y,aux b,aux c)) funs)
96 | C.CoFix (no,funs) ->
97 C.CoFix(no, List.map (fun (x,b,c) -> (x,aux b,aux c)) funs)
99 if is_not_visited u then
101 CicEnvironment.get_cooked_obj_with_univlist CicUniv.empty_ugraph u in
103 and aux_obj = function
104 | C.Constant (x,Some te,ty,v,y) ->
106 C.Constant (x,Some (aux te),aux ty,v,y)
107 | C.Variable (x,Some te,ty,v,y) ->
109 C.Variable (x,Some (aux te),aux ty,v,y)
110 | C.Constant (x,None, ty, v,y) ->
112 C.Constant (x,None, aux ty, v,y)
113 | C.Variable (x,None, ty, v,y) ->
115 C.Variable (x,None, aux ty, v,y)
116 | C.CurrentProof (_,conjs,te,ty,v,_) -> assert false
117 | C.InductiveDefinition (l,v,x,y) ->
119 C.InductiveDefinition (
122 (x,y,aux t, List.map (fun (x,t) -> x,aux t) l'))
126 List.flatten !results, o
129 HExtlib.list_uniq (List.fast_sort CicUniv.compare l)
131 let clean_and_fill uri obj ugraph =
132 (* universes of obj fills the universes of the obj with the right uri *)
133 let list_of_universes, obj = universes_of_obj uri obj in
134 let list_of_universes = list_uniq list_of_universes in
135 (* CicUniv.print_ugraph ugraph;*)
136 (* List.iter (fun u -> prerr_endline (CicUniv.string_of_universe u))*)
137 (* list_of_universes;*)
138 let ugraph = CicUniv.clean_ugraph ugraph list_of_universes in
139 (* CicUniv.print_ugraph ugraph;*)
140 let ugraph, list_of_universes =
141 CicUniv.fill_empty_nodes_with_uri ugraph list_of_universes uri
143 ugraph, list_of_universes, obj
146 let profiler = (HExtlib.profile "clean_and_fill").HExtlib.profile
147 let clean_and_fill u o g =
148 profiler (clean_and_fill u o) g