]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic/deannotate.ml
New experimental commit: metavariables representation is changed again,
[helm.git] / helm / ocaml / cic / deannotate.ml
1 (* Copyright (C) 2000, 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://cs.unibo.it/helm/.
24  *)
25
26 let expect_possible_parameters = ref false;;
27
28 exception NotExpectingPossibleParameters;;
29
30 (* converts annotated terms into cic terms (forgetting ids and names) *)
31 let rec deannotate_term =
32  let module C = Cic in
33   function
34      C.ARel (_,n,_) -> C.Rel n
35    | C.AVar (_,uri) -> C.Var uri
36    | C.AMeta (_,n, l) ->
37       let l' =
38        List.map
39         (function
40             None -> None
41           | Some at -> Some (deannotate_term at)
42         ) l
43       in
44        C.Meta (n, l')
45    | C.ASort (_,s) -> C.Sort s
46    | C.AImplicit _ -> C.Implicit
47    | C.ACast (_,va,ty) -> C.Cast (deannotate_term va, deannotate_term ty)
48    | C.AProd (_,name,so,ta) ->
49       C.Prod (name, deannotate_term so, deannotate_term ta)
50    | C.ALambda (_,name,so,ta) ->
51       C.Lambda (name, deannotate_term so, deannotate_term ta)
52    | C.ALetIn (_,name,so,ta) ->
53       C.LetIn (name, deannotate_term so, deannotate_term ta)
54    | C.AAppl (_,l) -> C.Appl (List.map deannotate_term l)
55    | C.AConst (_,uri, cookingsno) -> C.Const (uri, cookingsno)
56    | C.AAbst (_,uri) -> C.Abst uri
57    | C.AMutInd (_,uri,cookingsno,i) -> C.MutInd (uri,cookingsno,i)
58    | C.AMutConstruct (_,uri,cookingsno,i,j) ->
59       C.MutConstruct (uri,cookingsno,i,j)
60    | C.AMutCase (_,uri,cookingsno,i,outtype,te,pl) ->
61       C.MutCase (uri,cookingsno,i,deannotate_term outtype,
62        deannotate_term te, List.map deannotate_term pl)
63    | C.AFix (_,funno,ifl) ->
64       C.Fix (funno, List.map deannotate_inductiveFun ifl)
65    | C.ACoFix (_,funno,ifl) ->
66       C.CoFix (funno, List.map deannotate_coinductiveFun ifl)
67
68 and deannotate_inductiveFun (name,index,ty,bo) =
69  (name, index, deannotate_term ty, deannotate_term bo)
70
71 and deannotate_coinductiveFun (name,ty,bo) =
72  (name, deannotate_term ty, deannotate_term bo)
73 ;;
74
75 let deannotate_inductiveType (name, isinductive, arity, cons) =
76  (name, isinductive, deannotate_term arity,
77   List.map (fun (id,ty,recs) -> (id,deannotate_term ty, recs)) cons)
78 ;;
79
80 let deannotate_obj =
81  let module C = Cic in
82   function
83      C.ADefinition (_, id, bo, ty, params) ->
84       (match params with
85           C.Possible params ->
86            if !expect_possible_parameters then
87             C.Definition (id, deannotate_term bo, deannotate_term ty, params)
88            else
89             raise NotExpectingPossibleParameters
90         | C.Actual params ->
91            C.Definition (id, deannotate_term bo, deannotate_term ty, params)
92       )
93    | C.AAxiom (_, id, ty, params) ->
94       C.Axiom (id, deannotate_term ty, params)
95    | C.AVariable (_, name, bo, ty) ->
96       C.Variable (name,
97        (match bo with None -> None | Some bo -> Some (deannotate_term bo)),
98        deannotate_term ty)
99    | C.ACurrentProof (_, name, conjs, bo, ty) ->
100       C.CurrentProof (
101        name,
102         List.map
103          (function 
104            (id,acontext,con) -> 
105             let context = 
106              List.map 
107               (function 
108                   Some (n,(C.ADef at)) -> Some (n,(C.Def (deannotate_term at)))
109                 | Some (n,(C.ADecl at)) ->Some (n,(C.Decl (deannotate_term at)))
110                 | None -> None) acontext  
111             in
112              (id,context, deannotate_term con) 
113          ) conjs,
114        deannotate_term bo, deannotate_term ty
115       )
116    | C.AInductiveDefinition (_, tys, params, parno) ->
117       C.InductiveDefinition ( List.map deannotate_inductiveType tys,
118        params, parno)
119 ;;