]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_kernel/nCicEnvironment.ml
New function get_relevance and new (not exported) function get_checked_decl.
[helm.git] / helm / software / components / ng_kernel / nCicEnvironment.ml
index 38982d799768183d7353f1d205cfe2236000a699..b491d4c8403f1d9d7daf25c8186335696b7ea57e 100644 (file)
@@ -9,6 +9,8 @@
      \ /   This software is distributed as is, NO WARRANTY.     
       V_______________________________________________________________ *)
 
+(* $Id$ *)
+
 exception CircularDependency of string Lazy.t;;
 exception ObjectNotFound of string Lazy.t;;
 exception BadDependency of string Lazy.t;;
@@ -57,8 +59,8 @@ let get_checked_obj u =
          raise e
       | Propagate (u',_) as e' ->
          frozen_list := saved_frozen_list;
-         let exn = `Exn (BadDependency (lazy (NUri.string_of_uri u' ^
-           " depends (recursively) on " ^ NUri.string_of_uri u ^
+         let exn = `Exn (BadDependency (lazy (NUri.string_of_uri u ^
+           " depends (recursively) on " ^ NUri.string_of_uri u' ^
            " which is not well-typed"))) in
          NUri.UriHash.add cache u exn;
          if saved_frozen_list = [] then
@@ -79,8 +81,19 @@ let get_checked_obj u =
     | `Exn e -> raise e
 ;;
 
+let get_checked_decl = function
+  | NReference.Ref (uri, NReference.Decl) ->
+      (match get_checked_obj uri with
+      | _,height,_,_, NCic.Constant (rlv,name,None,ty,att) ->
+          rlv,name,ty,att,height
+      | _,_,_,_, NCic.Constant (_,_,Some _,_,_) ->
+          prerr_endline "get_checked_decl on a definition"; assert false
+      | _ -> prerr_endline "get_checked_decl on a non decl 2"; assert false)
+  | _ -> prerr_endline "get_checked_decl on a non decl"; assert false
+;;
+
 let get_checked_def = function
-  | NReference.Ref (_, uri, NReference.Def) ->
+  | NReference.Ref (uri, NReference.Def _) ->
       (match get_checked_obj uri with
       | _,height,_,_, NCic.Constant (rlv,name,Some bo,ty,att) ->
           rlv,name,bo,ty,att,height
@@ -91,7 +104,7 @@ let get_checked_def = function
 ;;
 
 let get_checked_indtys = function
-  | NReference.Ref (_, uri, (NReference.Ind (_,n)|NReference.Con (n,_))) ->
+  | NReference.Ref (uri, (NReference.Ind (_,n)|NReference.Con (n,_))) ->
       (match get_checked_obj uri with
       | _,_,_,_, NCic.Inductive (inductive,leftno,tys,att) ->
         inductive,leftno,tys,att,n
@@ -100,7 +113,7 @@ let get_checked_indtys = function
 ;;
 
 let get_checked_fixes_or_cofixes = function
-  | NReference.Ref (_, uri, (NReference.Fix (fixno,_)|NReference.CoFix fixno))->
+  | NReference.Ref (uri, (NReference.Fix (fixno,_,_)|NReference.CoFix fixno))->
       (match get_checked_obj uri with
       | _,height,_,_, NCic.Fixpoint (_,funcs,att) ->
          funcs, att, height
@@ -109,14 +122,35 @@ let get_checked_fixes_or_cofixes = function
 ;;
 
 let get_indty_leftno = function 
-  | NReference.Ref (_, uri, NReference.Ind _) 
-  | NReference.Ref (_, uri, NReference.Con _) ->
+  | NReference.Ref (uri, NReference.Ind _) 
+  | NReference.Ref (uri, NReference.Con _) ->
       (match get_checked_obj uri with
       | _,_,_,_, NCic.Inductive (_,left,_,_) -> left
       | _ ->prerr_endline "get_indty_leftno called on a non ind 2";assert false)
   | _ -> prerr_endline "get_indty_leftno called on a non indty";assert false
 ;;
 
+let get_relevance (NReference.Ref (_, infos) as r) =
+  match infos with
+     NReference.Def _ -> let res,_,_,_,_,_ = get_checked_def r in res
+   | NReference.Decl -> let res,_,_,_,_ = get_checked_decl r in res
+   | NReference.Ind _ ->
+       let _,_,tl,_,n = get_checked_indtys r in
+       let res,_,_,_ = List.nth tl n in
+         res
+    | NReference.Con (_,i) ->
+       let _,_,tl,_,n = get_checked_indtys r in
+       let _,_,_,cl = List.nth tl n in
+       let res,_,_ = List.nth cl (i - 1) in
+         res
+    | NReference.Fix (fixno,_,_)
+    | NReference.CoFix fixno ->
+        let fl,_,_ = get_checked_fixes_or_cofixes r in
+        let res,_,_,_,_ = List.nth fl fixno in
+          res
+;;
+
+
 let invalidate _ = 
   assert (!frozen_list = []);
   NUri.UriHash.clear cache