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