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 exception WrongUriToConstant;;
27 exception WrongUriToInductiveDefinition;;
28 exception CircularDependency of string;;
32 type t = UriManager.uri
33 let compare (s1 : t) (s2 : t) =
34 (* library function for = *)
36 (*if s1 = s2 then 0 else if s1 < s2 then (-1) else 1*)
40 let filename_of_uri uri =
41 let uri' = UriManager.string_of_uri uri in
42 let fn = Str.replace_first (Str.regexp "cic:") Configuration.helm_dir uri' in
46 (* quite inefficient coding of a set of strings: the only operations *)
47 (* performed are mem O(log n), and union O(n * log n?) *)
48 (* Perhaps a better implementation would be an array of bits or a map *)
49 (* from uri to booleans *)
50 module SetOfUris = Set.Make(OrderedUris);;
52 let (@@) = SetOfUris.union;;
54 let rec parameters_of te ty pparams=
55 let module S = SetOfUris in
60 | C.Var uri -> S.singleton uri
63 | C.Implicit -> S.empty
64 | C.Cast (te, ty) -> aux te @@ aux ty
65 | C.Prod (_, s, t) -> aux s @@ aux t
66 | C.Lambda (_, s, t) -> aux s @@ aux t
67 | C.LetIn (_, s, t) -> aux s @@ aux t
68 | C.Appl l -> List.fold_right (fun x i -> aux x @@ i) l S.empty
70 (* the parameters could be not exact but only possible *)
71 fix_params uri (Some (filename_of_uri uri)) ;
72 (* now the parameters are surely possible *)
73 (match CicCache.get_obj uri with
74 C.Definition (_, _, _, params) ->
78 (fun x i -> S.singleton x @@ i) l i
80 | C.Axiom (_, _, params) ->
84 (fun x i -> S.singleton x @@ i) l i
86 | C.CurrentProof _ -> S.empty (*CSC wrong *)
87 | _ -> raise WrongUriToConstant
89 | C.MutInd (uri,_,_) ->
90 (match CicCache.get_obj uri with
91 C.InductiveDefinition (_, params, _) ->
95 (fun x i -> S.singleton x @@ i) l i
97 | _ -> raise WrongUriToInductiveDefinition
99 | C.MutConstruct (uri,_,_,_) ->
100 (match CicCache.get_obj uri with
101 C.InductiveDefinition (_, params, _) ->
105 (fun x i -> S.singleton x @@ i) l i
107 | _ -> raise WrongUriToInductiveDefinition
109 | C.MutCase (uri,_,_,outtype,term,patterns) ->
110 (*CSC cosa basta? Ci vuole anche uri? *)
111 (match CicCache.get_obj uri with
112 C.InductiveDefinition (_, params, _) ->
116 (fun x i -> S.singleton x @@ i) l i
118 | _ -> raise WrongUriToInductiveDefinition
119 ) @@ aux outtype @@ aux term @@
120 List.fold_right (fun x i -> aux x @@ i) patterns S.empty
123 (fun (_,_,ty,bo) i -> aux ty @@ aux bo @@ i)
127 (fun (_,ty,bo) i -> aux ty @@ aux bo @@ i)
130 let actual_params = aux te @@ aux ty in
131 (* sort_actual_params wants in input the ordered list of possible params *)
132 let rec sort_actual_params2 =
135 | he::tl when S.mem he actual_params -> he::(sort_actual_params2 tl)
136 | _::tl -> sort_actual_params2 tl
138 let rec sort_actual_params =
141 | (n,l)::tl -> (n, sort_actual_params2 l)::(sort_actual_params tl)
143 sort_actual_params pparams
145 and fix_params uri filename =
146 let module C = Cic in
147 let ann = CicCache.get_annobj uri in
149 C.ADefinition (xid, id, te, ty, C.Possible pparams) ->
150 let te' = Deannotate.deannotate_term te in
151 let ty' = Deannotate.deannotate_term ty in
152 let real_params = parameters_of te' ty' pparams in
154 C.ADefinition (xid,id,te,ty,C.Actual real_params)
156 Xml.pp (Cic2Xml.pp fixed uri) filename ;