]> matita.cs.unibo.it Git - helm.git/blob - helm/interface/deannotate.ml
First very partial implementation of LetIn and bodyed Variables
[helm.git] / helm / interface / deannotate.ml
1 let expect_possible_parameters = ref false;;
2
3 exception NotExpectingPossibleParameters;;
4
5 let rec deannotate_term =
6  let module C = Cic in
7   function
8      C.ARel (_,_,n,_) -> C.Rel n
9    | C.AVar (_,_,uri) -> C.Var uri
10    | C.AMeta (_,_,n) -> C.Meta n
11    | C.ASort (_,_,s) -> C.Sort s
12    | C.AImplicit _ -> C.Implicit
13    | C.ACast (_,_,va,ty) -> C.Cast (deannotate_term va, deannotate_term ty)
14    | C.AProd (_,_,name,so,ta) ->
15       C.Prod (name, deannotate_term so, deannotate_term ta)
16    | C.ALambda (_,_,name,so,ta) ->
17       C.Lambda (name, deannotate_term so, deannotate_term ta)
18    | C.ALetIn (_,_,name,so,ta) ->
19       C.LetIn (name, deannotate_term so, deannotate_term ta)
20    | C.AAppl (_,_,l) -> C.Appl (List.map deannotate_term l)
21    | C.AConst (_,_,uri, cookingsno) -> C.Const (uri, cookingsno)
22    | C.AAbst (_,_,uri) -> C.Abst uri
23    | C.AMutInd (_,_,uri,cookingsno,i) -> C.MutInd (uri,cookingsno,i)
24    | C.AMutConstruct (_,_,uri,cookingsno,i,j) ->
25       C.MutConstruct (uri,cookingsno,i,j)
26    | C.AMutCase (_,_,uri,cookingsno,i,outtype,te,pl) ->
27       C.MutCase (uri,cookingsno,i,deannotate_term outtype,
28        deannotate_term te, List.map deannotate_term pl)
29    | C.AFix (_,_,funno,ifl) ->
30       C.Fix (funno, List.map deannotate_inductiveFun ifl)
31    | C.ACoFix (_,_,funno,ifl) ->
32       C.CoFix (funno, List.map deannotate_coinductiveFun ifl)
33
34 and deannotate_inductiveFun (name,index,ty,bo) =
35  (name, index, deannotate_term ty, deannotate_term bo)
36
37 and deannotate_coinductiveFun (name,ty,bo) =
38  (name, deannotate_term ty, deannotate_term bo)
39 ;;
40
41 let deannotate_inductiveType (name, isinductive, arity, cons) =
42  (name, isinductive, deannotate_term arity,
43   List.map (fun (id,ty,recs) -> (id,deannotate_term ty, recs)) cons)
44 ;;
45
46 let deannotate_obj =
47  let module C = Cic in
48   function
49      C.ADefinition (_, _, id, bo, ty, params) ->
50       (match params with
51           C.Possible params ->
52            if !expect_possible_parameters then
53             C.Definition (id, deannotate_term bo, deannotate_term ty, params)
54            else
55             raise NotExpectingPossibleParameters
56         | C.Actual params ->
57            C.Definition (id, deannotate_term bo, deannotate_term ty, params)
58       )
59    | C.AAxiom (_, _, id, ty, params) ->
60       C.Axiom (id, deannotate_term ty, params)
61    | C.AVariable (_, _, name, bo, ty) ->
62       C.Variable (name,
63        (match bo with None -> None | Some bo -> Some (deannotate_term bo)),
64        deannotate_term ty)
65    | C.ACurrentProof (_, _, name, conjs, bo, ty) ->
66       C.CurrentProof (
67        name, List.map (fun (id,con) -> (id,deannotate_term con)) conjs,
68        deannotate_term bo, deannotate_term ty
69       )
70    | C.AInductiveDefinition (_, _, tys, params, parno) ->
71       C.InductiveDefinition ( List.map deannotate_inductiveType tys,
72        params, parno)
73 ;;