(* Copyright (C) 2000, HELM Team. * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://cs.unibo.it/helm/. *) exception NotImplemented;; let fresh_id ids_to_terms ids_to_father_ids = let id = ref 0 in fun father t -> let res = "i" ^ string_of_int !id in incr id ; Hashtbl.add ids_to_father_ids res father ; Hashtbl.add ids_to_terms res t ; res ;; exception NotEnoughElements;; exception NameExpected;; (*CSC: cut&paste da cicPp.ml *) (* get_nth l n returns the nth element of the list l if it exists or *) (* raises NotEnoughElements if l has less than n elements *) let rec get_nth l n = match (n,l) with (1, he::_) -> he | (n, he::tail) when n > 1 -> get_nth tail (n-1) | (_,_) -> raise NotEnoughElements ;; let acic_of_cic_env env t = let module C = Cic in let ids_to_terms = Hashtbl.create 503 in let ids_to_father_ids = Hashtbl.create 503 in let fresh_id' = fresh_id ids_to_terms ids_to_father_ids in let rec aux father bs tt = let fresh_id'' = fresh_id' father tt in let aux' = aux (Some fresh_id'') in match tt with C.Rel n -> let id = match get_nth bs n with C.Name s -> s | _ -> raise NameExpected in C.ARel (fresh_id'', n, id) | C.Var uri -> C.AVar (fresh_id'', uri) | C.Meta n -> C.AMeta (fresh_id'', n) | C.Sort s -> C.ASort (fresh_id'', s) | C.Implicit -> C.AImplicit (fresh_id'') | C.Cast (v,t) -> C.ACast (fresh_id'', aux' bs v, aux' bs t) | C.Prod (n,s,t) -> C.AProd (fresh_id'', n, aux' bs s, aux' (n::bs) t) | C.Lambda (n,s,t) -> C.ALambda (fresh_id'',n, aux' bs s, aux' (n::bs) t) | C.LetIn (n,s,t) -> C.ALetIn (fresh_id'', n, aux' bs s, aux' (n::bs) t) | C.Appl l -> C.AAppl (fresh_id'', List.map (aux' bs) l) | C.Const (uri,cn) -> C.AConst (fresh_id'', uri, cn) | C.Abst _ -> raise NotImplemented | C.MutInd (uri,cn,tyno) -> C.AMutInd (fresh_id'', uri, cn, tyno) | C.MutConstruct (uri,cn,tyno,consno) -> C.AMutConstruct (fresh_id'', uri, cn, tyno, consno) | C.MutCase (uri, cn, tyno, outty, term, patterns) -> C.AMutCase (fresh_id'', uri, cn, tyno, aux' bs outty, aux' bs term, List.map (aux' bs) patterns) | C.Fix (funno, funs) -> let names = List.map (fun (name,_,_,_) -> C.Name name) funs in C.AFix (fresh_id'', funno, List.map (fun (name, indidx, ty, bo) -> (name, indidx, aux' bs ty, aux' (names@bs) bo) ) funs ) | C.CoFix (funno, funs) -> let names = List.map (fun (name,_,_) -> C.Name name) funs in C.ACoFix (fresh_id'', funno, List.map (fun (name, ty, bo) -> (name, aux' bs ty, aux' (names@bs) bo) ) funs ) in aux None env t, ids_to_terms, ids_to_father_ids ;; let acic_of_cic = acic_of_cic_env [];;