]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaProof.ml
snapshot (notably: implemented "check")
[helm.git] / helm / matita / matitaProof.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   (** create a Cic.CurrentProof from a given proof *)
27 let currentProof (uri, metasenv, bo, ty) =
28   let uri = MatitaTypes.unopt_uri uri in
29     (* TODO CSC: Wrong: [] is just plainly wrong *)
30   Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, [])
31
32 let init_metadata status =
33   let ((_, metasenv, _, _) as proof, _) = status in
34   let proof_object_metadata = (* compute proof annotations *)
35     Cic2acic.acic_object_of_cic_object (currentProof proof)
36   in
37   let sequents_metadata = (* compute all sequent annotations from scratch *)
38     List.map
39       (fun ((metano, context, term) as sequent) ->
40         (metano, Cic2acic.asequent_of_sequent metasenv sequent))
41       metasenv
42   in
43   (proof_object_metadata, sequents_metadata)
44
45 let compute_metadata (old_status, old_metadata) new_status =
46   let ((_, new_metasenv, _, _) as new_proof, _) = new_status in
47   let proof_object_metadata = (* compute proof annotations *)
48     Cic2acic.acic_object_of_cic_object (currentProof new_proof)
49   in
50   let sequents_metadata = (* compute all sequent annotations from scratch *)
51     (** TODO Zack could we reuse some of the annotations from the previous
52     * status to avoid recomputing all of them? uhm ... we have to which
53     * sequents haven't been changed by last tactic applications ... doh! *)
54     List.map
55       (fun ((metano, context, term) as sequent) ->
56         (metano, Cic2acic.asequent_of_sequent new_metasenv sequent))
57       new_metasenv
58   in
59   (proof_object_metadata, sequents_metadata)
60
61 class proof ?uri ~typ ~metasenv ~body () =
62   object (self)
63
64     inherit [MatitaTypes.hist_metadata]
65       StatefulProofEngine.status
66         ~history_size:BuildTimeConf.undo_history_size ?uri ~typ ~body ~metasenv
67         init_metadata compute_metadata ()
68
69     method toXml =
70       let currentproof = currentProof self#proof in
71       let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
72         Cic2acic.acic_object_of_cic_object ~eta_fix:false currentproof
73       in
74       let uri = MatitaTypes.unopt_uri self#uri in
75       let xml, bodyxml =
76         match Cic2Xml.print_object uri ~ids_to_inner_sorts
77           ~ask_dtd_to_the_getter:true acurrentproof
78         with
79         | xml, Some bodyxml -> xml, bodyxml
80         | _, None -> assert false
81       in
82       (xml, bodyxml)
83
84     method toString =
85       let (xml, bodyxml) = self#toXml in
86       let buf = Buffer.create 10240 in
87       List.iter (Buffer.add_string buf)
88         [ "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
89           "<!DOCTYPE ConstantType SYSTEM \"http://mowgli.cs.unibo.it:58081/getdtd?uri=cic.dtd\">\n";
90           "<ProofStatus>\n";
91           (Misc.strip_xml_headings (Xml.pp_to_string xml));
92           (Misc.strip_xml_headings(Xml.pp_to_string bodyxml));
93           (if not (self#proof_completed) then
94             Printf.sprintf "<CurrentGoal>%d</CurrentGoal>" self#goal
95           else
96             "<CurrentGoal />");
97           "\n</ProofStatus>"
98         ];
99       Buffer.contents buf
100
101   end
102
103 let proof ?uri ~metasenv ~typ () =
104   let metasenv = (1, [], typ) :: metasenv in
105   let body = Cic.Meta (1,[]) in
106   let _  = CicTypeChecker.type_of_aux' metasenv [] typ in
107   new proof ~typ ~metasenv ~body ?uri ()
108