]> matita.cs.unibo.it Git - helm.git/blobdiff - components/cic_exportation/cicExportation.ml
Slightly nicer output.
[helm.git] / components / cic_exportation / cicExportation.ml
index 71de7716a11cd6f784b3cc94e5914d12c0c93b6a..dbb7194a998e69ade2bd60d166712e39754e449f 100644 (file)
@@ -62,7 +62,8 @@ let analyze_type context t =
 let ppid =
  let reserved =
   [ "to";
-    "mod"
+    "mod";
+    "val"
   ]
  in
   function n ->
@@ -85,16 +86,18 @@ let rec get_nth l n =
   | (_,_) -> raise NotEnoughElements
 ;;
 
-let qualified_name_of_uri current_module_name ?(capitalize=false) uri =
+let qualified_name_of_uri current_module_uri ?(capitalize=false) uri =
  let name =
   if capitalize then
    String.capitalize (UriManager.name_of_uri uri)
   else
    ppid (UriManager.name_of_uri uri) in
- let buri = UriManager.buri_of_uri uri in
- let index = String.rindex buri '/' in
- let filename = String.sub buri (index + 1) (String.length buri - index - 1) in
-  if current_module_name = filename then
+  let filename =
+   let suri = UriManager.buri_of_uri uri in
+   let s = String.sub suri 5 (String.length suri - 5) in
+   let s = Pcre.replace ~pat:"/" ~templ:"_" s in
+    String.uncapitalize s in
+  if current_module_uri = UriManager.buri_of_uri uri then
    name
   else
    String.capitalize filename ^ "." ^ name
@@ -104,7 +107,7 @@ let qualified_name_of_uri current_module_name ?(capitalize=false) uri =
 (* pretty-prints a term t of cic in an environment l where l is a list of  *)
 (* identifier names used to resolve DeBrujin indexes. The head of l is the *)
 (* name associated to the greatest DeBrujin index in t                     *)
-let pp current_module_name ?metasenv =
+let pp current_module_uri ?metasenv =
 let rec pp t context =
  let module C = Cic in
    match t with
@@ -120,7 +123,7 @@ let rec pp t context =
          NotEnoughElements -> string_of_int (List.length context - n)
        end
     | C.Var (uri,exp_named_subst) ->
-        qualified_name_of_uri current_module_name uri ^
+        qualified_name_of_uri current_module_uri uri ^
          pp_exp_named_subst exp_named_subst context
     | C.Meta (n,l1) ->
        (match metasenv with
@@ -163,8 +166,10 @@ let rec pp t context =
     | C.Implicit _ -> "?"
     | C.Prod (b,s,t) ->
        (match b with
-          C.Name n -> "(\\forall " ^ n ^ ":" ^ pp s context ^ "." ^ pp t ((Some (b,Cic.Decl s))::context) ^ ")"
-        | C.Anonymous -> "(" ^ pp s context ^ "\\to " ^ pp t ((Some (b,Cic.Decl s))::context) ^ ")"
+          C.Name n ->
+           let n = "'" ^ String.uncapitalize n in
+            "(" ^ pp s context ^ " -> " ^ pp t ((Some (Cic.Name n,Cic.Decl s))::context) ^ ")"
+        | C.Anonymous -> "(" ^ pp s context ^ " -> " ^ pp t ((Some (b,Cic.Decl s))::context) ^ ")"
        )
     | C.Cast (v,t) -> pp v context
     | C.Lambda (b,s,t) ->
@@ -175,6 +180,10 @@ let rec pp t context =
     | C.LetIn (b,s,t) ->
        let ty,_ = CicTypeChecker.type_of_aux' [] context t CicUniv.oblivion_ugraph in
        "(let " ^ ppname b ^ " = " ^ pp s context ^ " in " ^ pp t ((Some (b,Cic.Def (s,Some ty)))::context) ^ ")"
+    | C.Appl (C.MutInd _ as he::tl) ->
+       let hes = pp he context in
+       let stl = String.concat "," (clean_args_for_ty context tl) in
+        (if stl = "" then "" else "(" ^ stl ^ ") ") ^ hes
     | C.Appl (C.MutConstruct _ as he::tl) ->
        let hes = pp he context in
        let stl = String.concat "," (clean_args context tl) in
@@ -182,14 +191,14 @@ let rec pp t context =
     | C.Appl li ->
        "(" ^ String.concat " " (clean_args context li) ^ ")"
     | C.Const (uri,exp_named_subst) ->
-       qualified_name_of_uri current_module_name uri ^
+       qualified_name_of_uri current_module_uri uri ^
         pp_exp_named_subst exp_named_subst context
     | C.MutInd (uri,n,exp_named_subst) ->
        (try
          match fst(CicEnvironment.get_obj CicUniv.empty_ugraph uri) with
             C.InductiveDefinition (dl,_,_,_) ->
              let (name,_,_,_) = get_nth dl (n+1) in
-              qualified_name_of_uri current_module_name
+              qualified_name_of_uri current_module_uri
                (UriManager.uri_of_string
                  (UriManager.buri_of_uri uri ^ "/" ^ name ^ ".con")) ^
               pp_exp_named_subst exp_named_subst context
@@ -204,7 +213,7 @@ let rec pp t context =
             C.InductiveDefinition (dl,_,_,_) ->
              let _,_,_,cons = get_nth dl (n1+1) in
               let id,_ = get_nth cons n2 in
-               qualified_name_of_uri current_module_name ~capitalize:true
+               qualified_name_of_uri current_module_uri ~capitalize:true
                 (UriManager.uri_of_string
                   (UriManager.buri_of_uri uri ^ "/" ^ id ^ ".con")) ^
                pp_exp_named_subst exp_named_subst context
@@ -241,7 +250,7 @@ let rec pp t context =
                           | C.Prod (_,_,bo) -> 1 + count_prods 0 bo
                           | _ -> 0
                         in
-                         qualified_name_of_uri current_module_name
+                         qualified_name_of_uri current_module_uri
                           ~capitalize:true
                           (UriManager.uri_of_string
                             (UriManager.buri_of_uri uri ^ "/" ^ id ^ ".con")),
@@ -260,7 +269,7 @@ let rec pp t context =
                 in
                  combine (connames_and_argsno,patterns)
                in
-                "\n(match " ^ pp te context ^ " with \n" ^
+                "\n(match " ^ pp te context ^ " with \n   " ^
                  (String.concat "\n | "
                   (List.map
                    (fun (x,argsno,y) ->
@@ -299,7 +308,7 @@ let rec pp t context =
            (function (name,_,ty,_) ->
              Some (C.Name name,Cic.Decl ty)) funs)
        in
-         "\nlet rec " ^
+         "let rec " ^
          List.fold_right
           (fun (name,ind,ty,bo) i -> name ^ " = \n" ^
             pp bo (names@context) ^ i)
@@ -307,7 +316,7 @@ let rec pp t context =
          " in " ^
          (match get_nth names (no + 1) with
              Some (Cic.Name n,_) -> n
-           | _ -> assert false) ^ "\n"
+           | _ -> assert false)
     | C.CoFix (no,funs) ->
        let names =
         List.rev
@@ -337,11 +346,18 @@ and clean_args context =
        `Type -> None
      | `Proof -> None
      | `Term -> Some pp t context)
+and clean_args_for_ty context =
+ HExtlib.filter_map
+  (function t ->
+    match analyze_term context t with
+       `Type -> Some pp t context
+     | `Proof -> None
+     | `Term -> None)
 in
  pp
 ;;
 
-let ppty current_module_name =
+let ppty current_module_uri =
  let rec args context =
   function
      Cic.Prod (n,s,t) ->
@@ -365,7 +381,7 @@ let ppty current_module_name =
               args
          | `Type ->
              let abstr,args = args ((Some (n,Cic.Decl s))::context) t in
-              abstr,pp current_module_name s context::args)
+              abstr,pp current_module_uri s context::args)
    | _ -> [],[]
  in
   args
@@ -374,7 +390,7 @@ let ppty current_module_name =
 (* ppinductiveType (typename, inductive, arity, cons)                       *)
 (* pretty-prints a single inductive definition                              *)
 (* (typename, inductive, arity, cons)                                       *)
-let ppinductiveType current_module_name nparams (typename, inductive, arity, cons)
+let ppinductiveType current_module_uri nparams (typename, inductive, arity, cons)
 =
  match analyze_type [] arity with
     `Sort Cic.Prop -> ""
@@ -387,7 +403,7 @@ let ppinductiveType current_module_name nparams (typename, inductive, arity, con
      let abstr,scons =
       List.fold_right
        (fun (id,ty) (_abstr,i) -> (* we should verify _abstr = abstr' *)
-          let abstr',sargs = ppty current_module_name [] ty in
+          let abstr',sargs = ppty current_module_uri [] ty in
           let sargs = String.concat " * " sargs in
            abstr',
            String.capitalize id ^
@@ -402,10 +418,10 @@ let ppinductiveType current_module_name nparams (typename, inductive, arity, con
        "type " ^ abstr ^ String.uncapitalize typename ^ " =\n" ^ scons ^ "\n")
 ;;
 
-let ppobj current_module_name obj =
+let ppobj current_module_uri obj =
  let module C = Cic in
  let module U = UriManager in
-  let pp = pp current_module_name in
+  let pp = pp current_module_uri in
   match obj with
     C.Constant (name, Some t1, t2, params, _) ->
       (match analyze_type [] t2 with
@@ -416,7 +432,7 @@ let ppobj current_module_name obj =
             match analyze_type [] t1 with
                `Sort Cic.Prop -> ""
              | _ ->
-               let abstr,args = ppty current_module_name [] t1 in
+               let abstr,args = ppty current_module_uri [] t1 in
                let abstr =
                 let s = String.concat "," abstr in
                 if s = "" then "" else "(" ^ s ^ ") "
@@ -468,10 +484,10 @@ let ppobj current_module_name obj =
           pp ~metasenv:conjectures ty [] 
    | C.InductiveDefinition (l, params, nparams, _) ->
       List.fold_right
-       (fun x i -> ppinductiveType current_module_name nparams x ^ i) l ""
+       (fun x i -> ppinductiveType current_module_uri nparams x ^ i) l ""
 ;;
 
-let ppobj current_module_name obj =
- let res = ppobj current_module_name obj in
+let ppobj current_module_uri obj =
+ let res = ppobj current_module_uri obj in
   if res = "" then "" else res ^ ";;\n\n"
 ;;