X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fcic_proof_checking%2FcicPp.ml;h=d3f7f0f60b181f7ccdcc02de45176079e92300dc;hb=1c7fb836e2af4f2f3d18afd0396701f2094265ff;hp=97ae6a50f5b8f189f6bc11fe8f145e1a1f3fbe20;hpb=ae326f646ef4c01b43d6da04201b427d1e175400;p=helm.git diff --git a/helm/ocaml/cic_proof_checking/cicPp.ml b/helm/ocaml/cic_proof_checking/cicPp.ml index 97ae6a50f..d3f7f0f60 100644 --- a/helm/ocaml/cic_proof_checking/cicPp.ml +++ b/helm/ocaml/cic_proof_checking/cicPp.ml @@ -44,7 +44,7 @@ exception NotEnoughElements;; let string_of_name = function Cic.Name s -> s - | Cic.Anonimous -> "_" + | Cic.Anonymous -> "_" ;; (* get_nth l n returns the nth element of the list l if it exists or *) @@ -67,14 +67,20 @@ let rec pp t l = begin try (match get_nth l n with - C.Name s -> s - | _ -> raise CicPpInternalError + Some (C.Name s) -> s + | Some C.Anonymous -> "__" ^ string_of_int n + | _ -> raise CicPpInternalError ) with NotEnoughElements -> string_of_int (List.length l - n) end - | C.Var uri -> UriManager.name_of_uri uri - | C.Meta n -> "?" ^ (string_of_int n) + | C.Var (uri,exp_named_subst) -> + UriManager.string_of_uri (*UriManager.name_of_uri*) uri ^ pp_exp_named_subst exp_named_subst l + | C.Meta (n,l1) -> + "?" ^ (string_of_int n) ^ "[" ^ + String.concat " ; " + (List.map (function None -> "_" | Some t -> pp t l) l1) ^ + "]" | C.Sort s -> (match s with C.Prop -> "Prop" @@ -84,43 +90,51 @@ let rec pp t l = | C.Implicit -> "?" | C.Prod (b,s,t) -> (match b with - C.Name n -> "(" ^ n ^ ":" ^ pp s l ^ ")" ^ pp t (b::l) - | C.Anonimous -> "(" ^ pp s l ^ "->" ^ pp t (b::l) ^ ")" + C.Name n -> "(" ^ n ^ ":" ^ pp s l ^ ")" ^ pp t ((Some b)::l) + | C.Anonymous -> "(" ^ pp s l ^ "->" ^ pp t ((Some b)::l) ^ ")" ) | C.Cast (v,t) -> pp v l | C.Lambda (b,s,t) -> - "[" ^ string_of_name b ^ ":" ^ pp s l ^ "]" ^ pp t (b::l) + "[" ^ string_of_name b ^ ":" ^ pp s l ^ "]" ^ pp t ((Some b)::l) | C.LetIn (b,s,t) -> - "[" ^ string_of_name b ^ ":=" ^ pp s l ^ "]" ^ pp t (b::l) + "[" ^ string_of_name b ^ ":=" ^ pp s l ^ "]" ^ pp t ((Some b)::l) | C.Appl li -> "(" ^ (List.fold_right (fun x i -> pp x l ^ (match i with "" -> "" | _ -> " ") ^ i) li "" ) ^ ")" - | C.Const (uri,_) -> UriManager.name_of_uri uri - | C.Abst uri -> UriManager.name_of_uri uri - | C.MutInd (uri,_,n) -> - (match CicEnvironment.get_obj uri with - C.InductiveDefinition (dl,_,_) -> - let (name,_,_,_) = get_nth dl (n+1) in - name - | _ -> raise CicPpInternalError + | C.Const (uri,exp_named_subst) -> + UriManager.name_of_uri uri ^ pp_exp_named_subst exp_named_subst l + | C.MutInd (uri,n,exp_named_subst) -> + (try + match CicEnvironment.get_obj uri with + C.InductiveDefinition (dl,_,_) -> + let (name,_,_,_) = get_nth dl (n+1) in + name ^ pp_exp_named_subst exp_named_subst l + | _ -> raise CicPpInternalError + with + _ -> UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (n + 1) ) - | C.MutConstruct (uri,_,n1,n2) -> - (match CicEnvironment.get_obj uri with - C.InductiveDefinition (dl,_,_) -> - let (_,_,_,cons) = get_nth dl (n1+1) in - let (id,_,_) = get_nth cons n2 in - id - | _ -> raise CicPpInternalError + | C.MutConstruct (uri,n1,n2,exp_named_subst) -> + (try + match CicEnvironment.get_obj uri with + C.InductiveDefinition (dl,_,_) -> + let (_,_,_,cons) = get_nth dl (n1+1) in + let (id,_) = get_nth cons n2 in + id ^ pp_exp_named_subst exp_named_subst l + | _ -> raise CicPpInternalError + with + _ -> + UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (n1 + 1) ^ "/" ^ + string_of_int n2 ) - | C.MutCase (uri,_,n1,ty,te,patterns) -> + | C.MutCase (uri,n1,ty,te,patterns) -> let connames = (match CicEnvironment.get_obj uri with C.InductiveDefinition (dl,_,_) -> let (_,_,_,cons) = get_nth dl (n1+1) in - List.map (fun (id,_,_) -> id) cons + List.map (fun (id,_) -> id) cons | _ -> raise CicPpInternalError ) in @@ -130,7 +144,9 @@ let rec pp t l = "\nend" | C.Fix (no, funs) -> let snames = List.map (fun (name,_,_,_) -> name) funs in - let names = List.rev (List.map (function name -> C.Name name) snames) in + let names = + List.rev (List.map (function name -> Some (C.Name name)) snames) + in "\nFix " ^ get_nth snames (no + 1) ^ " {" ^ List.fold_right (fun (name,ind,ty,bo) i -> "\n" ^ name ^ " / " ^ string_of_int ind ^ @@ -140,7 +156,9 @@ let rec pp t l = "}\n" | C.CoFix (no,funs) -> let snames = List.map (fun (name,_,_) -> name) funs in - let names = List.rev (List.map (function name -> C.Name name) snames) in + let names = + List.rev (List.map (function name -> Some (C.Name name)) snames) + in "\nCoFix " ^ get_nth snames (no + 1) ^ " {" ^ List.fold_right (fun (name,ty,bo) i -> "\n" ^ name ^ @@ -148,20 +166,28 @@ let rec pp t l = pp bo (names@l) ^ i) funs "" ^ "}\n" +and pp_exp_named_subst exp_named_subst l = + if exp_named_subst = [] then "" else + "{" ^ + String.concat " ; " ( + List.map + (function (uri,t) -> UriManager.name_of_uri uri ^ ":=" ^ pp t l) + exp_named_subst + ) ^ "}" +;; + +let ppterm t = + pp t [] ;; -(* ppinductiveType (typename, inductive, arity, cons) names *) -(* pretty-prints a single inductive definition (typename, inductive, arity, *) -(* cons) where the cic terms in the inductive definition need to be *) -(* evaluated in the environment names that is the list of typenames of the *) -(* mutual inductive definitions defined in the block of mutual inductive *) -(* definitions to which this one belongs to *) -let ppinductiveType (typename, inductive, arity, cons) names = +(* ppinductiveType (typename, inductive, arity, cons) *) +(* pretty-prints a single inductive definition *) +(* (typename, inductive, arity, cons) *) +let ppinductiveType (typename, inductive, arity, cons) = (if inductive then "\nInductive " else "\nCoInductive ") ^ typename ^ ": " ^ - (*CSC: bug found: was pp arity names ^ " =\n " ^*) pp arity [] ^ " =\n " ^ List.fold_right - (fun (id,ty,_) i -> id ^ " : " ^ pp ty names ^ + (fun (id,ty) i -> id ^ " : " ^ pp ty [] ^ (if i = "" then "\n" else "\n | ") ^ i) cons "" ;; @@ -172,46 +198,50 @@ let ppobj obj = let module C = Cic in let module U = UriManager in match obj with - C.Definition (id, t1, t2, params) -> - "Definition of " ^ id ^ - "(" ^ - List.fold_right - (fun (_,x) i -> - List.fold_right - (fun x i -> - U.string_of_uri x ^ match i with "" -> "" | i' -> " " ^ i' - ) x "" ^ match i with "" -> "" | i' -> " " ^ i' - ) params "" ^ ")" ^ - ":\n" ^ pp t1 [] ^ " : " ^ pp t2 [] - | C.Axiom (id, ty, params) -> - "Axiom " ^ id ^ "(" ^ - List.fold_right - (fun (_,x) i -> - List.fold_right - (fun x i -> - U.string_of_uri x ^ match i with "" -> "" | i' -> " " ^ i' - ) x "" ^ match i with "" -> "" | i' -> " " ^ i' - ) params "" ^ - "):\n" ^ pp ty [] - | C.Variable (name, bo, ty) -> - "Variable " ^ name ^ ":\n" ^ pp ty [] ^ "\n" ^ - (match bo with None -> "" | Some bo -> ":= " ^ pp bo []) - | C.CurrentProof (name, conjectures, value, ty) -> - "Current Proof:\n" ^ - List.fold_right - (fun (n, t) i -> "?" ^ (string_of_int n) ^ ": " ^ pp t [] ^ "\n" ^ i) - conjectures "" ^ - "\n" ^ pp value [] ^ " : " ^ pp ty [] + C.Constant (name, Some t1, t2, params) -> + "Definition of " ^ name ^ + "(" ^ String.concat ";" (List.map UriManager.string_of_uri params) ^ + ")" ^ ":\n" ^ pp t1 [] ^ " : " ^ pp t2 [] + | C.Constant (name, None, ty, params) -> + "Axiom " ^ name ^ + "(" ^ String.concat ";" (List.map UriManager.string_of_uri params) ^ + "):\n" ^ pp ty [] + | C.Variable (name, bo, ty, params) -> + "Variable " ^ name ^ + "(" ^ String.concat ";" (List.map UriManager.string_of_uri params) ^ + ")" ^ ":\n" ^ + pp ty [] ^ "\n" ^ + (match bo with None -> "" | Some bo -> ":= " ^ pp bo []) + | C.CurrentProof (name, conjectures, value, ty, params) -> + "Current Proof of " ^ name ^ + "(" ^ String.concat ";" (List.map UriManager.string_of_uri params) ^ + ")" ^ ":\n" ^ + let separate s = if s = "" then "" else s ^ " ; " in + List.fold_right + (fun (n, context, t) i -> + let conjectures',name_context = + List.fold_right + (fun context_entry (i,name_context) -> + (match context_entry with + Some (n,C.Decl at) -> + (separate i) ^ + string_of_name n ^ ":" ^ pp at name_context ^ " ", + (Some n)::name_context + | Some (n,C.Def at) -> + (separate i) ^ + string_of_name n ^ ":= " ^ pp at name_context ^ " ", + (Some n)::name_context + | None -> + (separate i) ^ "_ :? _ ", None::name_context) + ) context ("",[]) + in + conjectures' ^ " |- " ^ "?" ^ (string_of_int n) ^ ": " ^ + pp t name_context ^ "\n" ^ i + ) conjectures "" ^ + "\n" ^ pp value [] ^ " : " ^ pp ty [] | C.InductiveDefinition (l, params, nparams) -> "Parameters = " ^ - List.fold_right - (fun (_,x) i -> - List.fold_right - (fun x i -> - U.string_of_uri x ^ match i with "" -> "" | i' -> " " ^ i' - ) x "" ^ match i with "" -> "" | i' -> " " ^ i' - ) params "" ^ "\n" ^ - "NParams = " ^ string_of_int nparams ^ "\n" ^ - let names = List.rev (List.map (fun (n,_,_,_) -> C.Name n) l) in - List.fold_right (fun x i -> ppinductiveType x names ^ i) l "" + String.concat ";" (List.map UriManager.string_of_uri params) ^ "\n" ^ + "NParams = " ^ string_of_int nparams ^ "\n" ^ + List.fold_right (fun x i -> ppinductiveType x ^ i) l "" ;;