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/.
30 type coercion_search_result =
31 | SomeCoercion of Cic.term
34 | NotHandled of string Lazy.t
37 let debug_print s = if debug then prerr_endline (Lazy.force s) else ()
39 (* searches a coercion fron src to tgt in the !coercions list *)
40 let look_for_coercion src tgt =
43 let ty,_ = CicTypeChecker.type_of_aux' [] [] con CicUniv.empty_ugraph in
44 let rec count_pi = function
45 | Cic.Prod (_,_,t) -> 1 + count_pi t
49 with Invalid_argument _ -> assert false (* all coercions have an uri *)
51 let rec mk_implicits = function
53 | n -> Cic.Implicit None :: mk_implicits (n-1)
58 (fun (s,t) -> CoercDb.eq_carr s src && CoercDb.eq_carr t tgt) in
64 (sprintf ":-( coercion non trovata da %s a %s"
65 (CoercDb.name_of_carr src)
66 (CoercDb.name_of_carr tgt)));
70 sprintf ":-) TROVATA 1 coercion da %s a %s: %s"
71 (CoercDb.name_of_carr src)
72 (CoercDb.name_of_carr tgt)
73 (UriManager.name_of_uri u)));
77 sprintf ":-/ TROVATE %d coercion(s) da %s a %s, prendo la prima: %s"
79 (CoercDb.name_of_carr src)
80 (CoercDb.name_of_carr tgt)
81 (UriManager.name_of_uri u)));
87 let c = CicUtil.term_of_uri u in
88 let arity = arity_of c in
89 let args = mk_implicits (arity - 1) in
93 | _ -> Cic.Appl (c::args)
97 | CoercDb.EqCarrNotImplemented s -> NotHandled s
98 | CoercDb.EqCarrOnNonMetaClosed -> NotMetaClosed
101 let look_for_coercion src tgt =
102 let src_uri = CoercDb.coerc_carr_of_term src in
103 let tgt_uri = CoercDb.coerc_carr_of_term tgt in
104 look_for_coercion src_uri tgt_uri
106 let is_a_coercion t =
108 let uri = CicUtil.uri_of_term t in
109 CoercDb.is_a_coercion uri
110 with Invalid_argument _ -> false
114 let uri = CicUtil.uri_of_term t in
115 CoercDb.term_of_carr (fst (CoercDb.get_carr uri))
116 with Invalid_argument _ -> assert false (* t must be a coercion *)
120 let uri = CicUtil.uri_of_term t in
121 CoercDb.term_of_carr (snd (CoercDb.get_carr uri))
122 with Invalid_argument _ -> assert false (* t must be a coercion *)
124 let generate_dot_file () =
125 let l = CoercDb.to_list () in
128 node [fontsize=9, width=.4, height=.4];
132 let conclusion = " } \n" in
133 let data = List.fold_left
134 (fun acc (src,tgt,c) ->
135 acc ^ CoercDb.name_of_carr src ^ " -> " ^
136 CoercDb.name_of_carr tgt ^ "[label=\"" ^ UriManager.name_of_uri c ^
139 preamble ^ data ^ conclusion