]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaCicMisc.ml
debian: rebuilt against ocaml 3.08.3
[helm.git] / helm / matita / matitaCicMisc.ml
1 (* Copyright (C) 2004, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 open Printf
27
28   (** create a Cic.CurrentProof from a given proof *)
29 let cicCurrentProof (uri, metasenv, bo, ty) =
30   let uri = MatitaTypes.unopt_uri uri in
31     (* TODO CSC: Wrong: [] is just plainly wrong *)
32   Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, [], [])
33
34   (** create a Cic.Constant from a given proof *)
35 let cicConstant (uri, metasenv, bo, ty) =
36   let uri = MatitaTypes.unopt_uri uri in
37     (* TODO CSC: Wrong: [] is just plainly wrong *)
38   Cic.Constant (UriManager.name_of_uri uri, Some bo, ty, [], [])
39
40 let canonical_context metano metasenv =
41   try
42     let (_, context, _) = List.find (fun (m, _, _) -> m = metano) metasenv in
43     context
44   with Not_found ->
45     failwith (sprintf "Can't find canonical context for %d" metano)
46
47   (** term AST -> Cic.term. Uses disambiguator and change imperatively the
48   * metasenv as needed *)
49 let disambiguate ~(disambiguator:MatitaTypes.disambiguator) ~currentProof ast =
50   if currentProof#onGoing () then begin
51     let proof = currentProof#proof in
52     let metasenv = proof#metasenv in
53     let goal = proof#goal in
54     let context = canonical_context goal metasenv in
55     let (_, metasenv, term,ugraph) as retval =
56       disambiguator#disambiguateTermAst ~context ~metasenv ast
57     in
58     proof#set_metasenv metasenv;
59     retval
60   end else
61     disambiguator#disambiguateTermAst ast
62
63 let get_context_and_metasenv ~(currentProof:#MatitaTypes.currentProof) =
64   if currentProof#onGoing () then
65     let proof = currentProof#proof in
66     let metasenv = proof#metasenv in
67     let goal = proof#goal in
68     (canonical_context goal metasenv, metasenv)
69   else
70     ([], [])
71