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
90 | C.MutInd (uri,_,_) ->
91 (match CicCache.get_obj uri with
92 C.InductiveDefinition (_, params, _) ->
96 (fun x i -> S.singleton x @@ i) l i
98 | _ -> raise WrongUriToInductiveDefinition
100 | C.MutConstruct (uri,_,_,_) ->
101 (match CicCache.get_obj uri with
102 C.InductiveDefinition (_, params, _) ->
106 (fun x i -> S.singleton x @@ i) l i
108 | _ -> raise WrongUriToInductiveDefinition
110 | C.MutCase (uri,_,_,outtype,term,patterns) ->
111 (*CSC cosa basta? Ci vuole anche uri? *)
112 (match CicCache.get_obj uri with
113 C.InductiveDefinition (_, params, _) ->
117 (fun x i -> S.singleton x @@ i) l i
119 | _ -> raise WrongUriToInductiveDefinition
120 ) @@ aux outtype @@ aux term @@
121 List.fold_right (fun x i -> aux x @@ i) patterns S.empty
124 (fun (_,_,ty,bo) i -> aux ty @@ aux bo @@ i)
128 (fun (_,ty,bo) i -> aux ty @@ aux bo @@ i)
131 let actual_params = aux te @@ aux ty in
132 (* sort_actual_params wants in input the ordered list of possible params *)
133 let rec sort_actual_params2 =
136 | he::tl when S.mem he actual_params -> he::(sort_actual_params2 tl)
137 | _::tl -> sort_actual_params2 tl
139 let rec sort_actual_params =
142 | (n,l)::tl -> (n, sort_actual_params2 l)::(sort_actual_params tl)
144 sort_actual_params pparams
146 and fix_params uri filename =
147 let module C = Cic in
148 let ann = CicCache.get_annobj uri in
150 C.ADefinition (xid, id, te, ty, C.Possible pparams) ->
151 let te' = Deannotate.deannotate_term te in
152 let ty' = Deannotate.deannotate_term ty in
153 let real_params = parameters_of te' ty' pparams in
155 C.ADefinition (xid,id,te,ty,C.Actual real_params)
157 Xml.pp (Cic2Xml.pp fixed uri) filename ;