X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=components%2Fcic%2FcicUtil.ml;h=496452a87bf75f02efaa3344a3742f4592d29406;hb=1f1e441c320c1ed94e648f5e126cf2298a1eda00;hp=7c6e3eabe28619cc14fdd0cb812f998566d38b52;hpb=7f2444c2670cadafddd8785b687ef312158376b0;p=helm.git diff --git a/components/cic/cicUtil.ml b/components/cic/cicUtil.ml index 7c6e3eabe..496452a87 100644 --- a/components/cic/cicUtil.ml +++ b/components/cic/cicUtil.ml @@ -61,7 +61,8 @@ let clean_up_local_context subst metasenv n l = None , _ -> None | _ , t -> t) cc l with - Invalid_argument _ -> assert false) + Invalid_argument _ -> + assert false) let is_closed = let module C = Cic in @@ -165,12 +166,12 @@ let term_of_uri uri = | Not_found -> raise (UriManager.IllFormedUri s) let uri_of_term = function - | Cic.Const (uri, []) - | Cic.Var (uri, []) -> uri - | Cic.MutInd (baseuri, tyno, []) -> + | Cic.Const (uri, _) + | Cic.Var (uri, _) -> uri + | Cic.MutInd (baseuri, tyno, _) -> UriManager.uri_of_string (sprintf "%s#xpointer(1/%d)" (UriManager.string_of_uri baseuri) (tyno+1)) - | Cic.MutConstruct (baseuri, tyno, consno, []) -> + | Cic.MutConstruct (baseuri, tyno, consno, _) -> UriManager.uri_of_string (sprintf "%s#xpointer(1/%d/%d)" (UriManager.string_of_uri baseuri) (tyno + 1) consno) @@ -207,6 +208,33 @@ let attributes_of_obj = function | Cic.CurrentProof (_, _, _, _, _, attributes) | Cic.InductiveDefinition (_, _, _, attributes) -> attributes + +let is_generated obj = List.exists ((=) `Generated) (attributes_of_obj obj) + +let arity_of_composed_coercion obj = + let attrs = attributes_of_obj obj in + try + let tag=List.find (function `Class (`Coercion _) -> true|_->false) attrs in + match tag with + | `Class (`Coercion n) -> n + | _-> assert false + with Not_found -> 0 +;; + +let projections_of_record obj uri = + let attrs = attributes_of_obj obj in + try + let tag=List.find (function `Class (`Record _) -> true|_->false) attrs in + match tag with + | `Class (`Record l) -> + List.map (fun (name,_,_) -> + let buri = UriManager.buri_of_uri uri in + let puri = UriManager.uri_of_string (buri ^ "/" ^ name ^ ".con") in + puri) l + | _-> assert false + with Not_found -> [] +;; + let rec mk_rels howmany from = match howmany with | 0 -> [] @@ -363,3 +391,77 @@ let rehash_obj = in C.InductiveDefinition (tl', params', paramsno, attrs) +let rec metas_of_term = function + | Cic.Meta (i, c) -> [i,c] + | Cic.Var (_, ens) + | Cic.Const (_, ens) + | Cic.MutInd (_, _, ens) + | Cic.MutConstruct (_, _, _, ens) -> + List.flatten (List.map (fun (u, t) -> metas_of_term t) ens) + | Cic.Cast (s, t) + | Cic.Prod (_, s, t) + | Cic.Lambda (_, s, t) + | Cic.LetIn (_, s, t) -> (metas_of_term s) @ (metas_of_term t) + | Cic.Appl l -> List.flatten (List.map metas_of_term l) + | Cic.MutCase (uri, i, s, t, l) -> + (metas_of_term s) @ (metas_of_term t) @ + (List.flatten (List.map metas_of_term l)) + | Cic.Fix (i, il) -> + List.flatten + (List.map (fun (s, i, t1, t2) -> + (metas_of_term t1) @ (metas_of_term t2)) il) + | Cic.CoFix (i, il) -> + List.flatten + (List.map (fun (s, t1, t2) -> + (metas_of_term t1) @ (metas_of_term t2)) il) + | _ -> [] +;; + +module MetaOT = struct + type t = int * Cic.term option list + let compare = Pervasives.compare +end + +module S = Set.Make(MetaOT) + +let rec metas_of_term_set = function + | Cic.Meta (i, c) -> S.singleton (i,c) + | Cic.Var (_, ens) + | Cic.Const (_, ens) + | Cic.MutInd (_, _, ens) + | Cic.MutConstruct (_, _, _, ens) -> + List.fold_left + (fun s (_,t) -> S.union s (metas_of_term_set t)) + S.empty ens + | Cic.Cast (s, t) + | Cic.Prod (_, s, t) + | Cic.Lambda (_, s, t) + | Cic.LetIn (_, s, t) -> S.union (metas_of_term_set s) (metas_of_term_set t) + | Cic.Appl l -> + List.fold_left + (fun s t -> S.union s (metas_of_term_set t)) + S.empty l + | Cic.MutCase (uri, i, s, t, l) -> + S.union + (S.union (metas_of_term_set s) (metas_of_term_set t)) + (List.fold_left + (fun s t -> S.union s (metas_of_term_set t)) + S.empty l) + | Cic.Fix (_, il) -> + (List.fold_left + (fun s (_,_,t1,t2) -> + S.union s (S.union (metas_of_term_set t1) (metas_of_term_set t2)))) + S.empty il + | Cic.CoFix (i, il) -> + (List.fold_left + (fun s (_,t1,t2) -> + S.union s (S.union (metas_of_term_set t1) (metas_of_term_set t2)))) + S.empty il + | _ -> S.empty +;; + +let metas_of_term_set t = + let s = metas_of_term_set t in + S.elements s +;; +