]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic/deannotate.ml
ocaml 3.09 transition
[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 (* converts annotated terms into cic terms (forgetting ids and names) *)
27 let rec deannotate_term =
28  let module C = Cic in
29   function
30      C.ARel (_,_,n,_) -> C.Rel n
31    | C.AVar (_,uri,exp_named_subst) ->
32       let deann_exp_named_subst =
33        List.map (function (uri,t) -> uri,deannotate_term t) exp_named_subst
34       in
35        C.Var (uri, deann_exp_named_subst)
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 (_, annotation) -> C.Implicit annotation
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,exp_named_subst) ->
56       let deann_exp_named_subst =
57        List.map (function (uri,t) -> uri,deannotate_term t) exp_named_subst
58       in
59        C.Const (uri, deann_exp_named_subst)
60    | C.AMutInd (_,uri,i,exp_named_subst) ->
61       let deann_exp_named_subst =
62        List.map (function (uri,t) -> uri,deannotate_term t) exp_named_subst
63       in
64        C.MutInd (uri,i,deann_exp_named_subst)
65    | C.AMutConstruct (_,uri,i,j,exp_named_subst) ->
66       let deann_exp_named_subst =
67        List.map (function (uri,t) -> uri,deannotate_term t) exp_named_subst
68       in
69        C.MutConstruct (uri,i,j,deann_exp_named_subst)
70    | C.AMutCase (_,uri,i,outtype,te,pl) ->
71       C.MutCase (uri,i,deannotate_term outtype,
72        deannotate_term te, List.map deannotate_term pl)
73    | C.AFix (_,funno,ifl) ->
74       C.Fix (funno, List.map deannotate_inductiveFun ifl)
75    | C.ACoFix (_,funno,ifl) ->
76       C.CoFix (funno, List.map deannotate_coinductiveFun ifl)
77
78 and deannotate_inductiveFun (_,name,index,ty,bo) =
79  (name, index, deannotate_term ty, deannotate_term bo)
80
81 and deannotate_coinductiveFun (_,name,ty,bo) =
82  (name, deannotate_term ty, deannotate_term bo)
83 ;;
84
85 let deannotate_inductiveType (_, name, isinductive, arity, cons) =
86  (name, isinductive, deannotate_term arity,
87   List.map (fun (id,ty) -> (id,deannotate_term ty)) cons)
88 ;;
89
90 let deannotate_obj =
91  let module C = Cic in
92   function
93      C.AConstant (_, _, id, bo, ty, params, attrs) ->
94       C.Constant (id,
95        (match bo with None -> None | Some bo -> Some (deannotate_term bo)),
96        deannotate_term ty, params, attrs)
97    | C.AVariable (_, name, bo, ty, params, attrs) ->
98       C.Variable (name,
99        (match bo with None -> None | Some bo -> Some (deannotate_term bo)),
100        deannotate_term ty, params, attrs)
101    | C.ACurrentProof (_, _, name, conjs, bo, ty, params, attrs) ->
102       C.CurrentProof (
103        name,
104         List.map
105          (function 
106            (_,id,acontext,con) -> 
107             let context = 
108              List.map 
109               (function 
110                   _,Some (n,(C.ADef at)) ->
111                    Some (n,(C.Def ((deannotate_term at),None)))
112                 | _,Some (n,(C.ADecl at)) ->
113                    Some (n,(C.Decl (deannotate_term at)))
114                 | _,None -> None
115               ) acontext  
116             in
117              (id,context,deannotate_term con) 
118          ) conjs,
119        deannotate_term bo,deannotate_term ty, params, attrs
120       )
121    | C.AInductiveDefinition (_, tys, params, parno, attrs) ->
122       C.InductiveDefinition (List.map deannotate_inductiveType tys,
123        params, parno, attrs)
124 ;;