1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
16
let get_new_id locals id =
18
let dir = make_dirpath [id] in
19
if not (Nametab.exists_module dir) then
22
get_id (id::l) (Nameops.next_ident_away id l)
24
get_id (List.map snd locals) id
26
let rec print_local_modpath locals = function
27
| MPbound mbid -> pr_id (List.assoc mbid locals)
29
print_local_modpath locals mp ++ str "." ++ pr_lab l
30
| MPself _ | MPfile _ -> raise Not_found
32
let print_modpath locals mp =
33
try (* must be with let because streams are lazy! *)
34
let qid = Nametab.shortest_qualid_of_module mp in
37
| Not_found -> print_local_modpath locals mp
39
let print_kn locals kn =
41
let qid = Nametab.shortest_qualid_of_modtype kn in
46
print_local_modpath locals kn
48
Not_found -> print_modpath locals kn
50
let rec flatten_app mexpr l = match mexpr with
51
| SEBapply (mexpr,marg,_) -> flatten_app mexpr (marg::l)
54
let rec print_module name locals with_body mb =
55
let body = match with_body, mb.mod_expr with
59
spc () ++ str ":= " ++ print_modexpr locals mexpr
61
let modtype = match mb.mod_type with
63
| Some t -> spc () ++ str": " ++
64
print_modtype locals t
66
hv 2 (str "Module " ++ name ++ modtype ++ body)
68
and print_modtype locals mty =
70
| SEBident kn -> print_kn locals kn
71
| SEBfunctor (mbid,mtb1,mtb2) ->
72
(* let env' = Modops.add_module (MPbid mbid)
73
(Modops.body_of_type mtb) env
75
let locals' = (mbid, get_new_id locals (id_of_mbid mbid))
77
hov 2 (str "Funsig" ++ spc () ++ str "(" ++
78
pr_id (id_of_mbid mbid) ++ str " : " ++
79
print_modtype locals mtb1.typ_expr ++
80
str ")" ++ spc() ++ print_modtype locals' mtb2)
81
| SEBstruct (msid,sign) ->
82
hv 2 (str "Sig" ++ spc () ++ print_sig locals msid sign ++ brk (1,-2) ++ str "End")
83
| SEBapply (mexpr,marg,_) ->
84
let lapp = flatten_app mexpr [marg] in
85
let fapp = List.hd lapp in
86
let mapp = List.tl lapp in
87
hov 3 (str"(" ++ (print_modtype locals fapp) ++ spc () ++
88
prlist_with_sep spc (print_modexpr locals) mapp ++ str")")
89
| SEBwith(seb,With_definition_body(idl,cb))->
90
let s = (String.concat "." (List.map string_of_id idl)) in
91
hov 2 (print_modtype locals seb ++ spc() ++ str "with" ++ spc() ++
92
str "Definition"++ spc() ++ str s ++ spc() ++ str ":="++ spc())
93
| SEBwith(seb,With_module_body(idl,mp,_,_))->
94
let s =(String.concat "." (List.map string_of_id idl)) in
95
hov 2 (print_modtype locals seb ++ spc() ++ str "with" ++ spc() ++
96
str "Module"++ spc() ++ str s ++ spc() ++ str ":="++ spc())
98
and print_sig locals msid sign =
99
let print_spec (l,spec) = (match spec with
100
| SFBconst {const_body=Some _; const_opaque=false} -> str "Definition "
101
| SFBconst {const_body=None}
102
| SFBconst {const_opaque=true} -> str "Parameter "
103
| SFBmind _ -> str "Inductive "
104
| SFBmodule _ -> str "Module "
105
| SFBalias (mp,_,_) -> str "Module "
106
| SFBmodtype _ -> str "Module Type ") ++ str (string_of_label l)
108
prlist_with_sep spc print_spec sign
110
and print_struct locals msid struc =
111
let print_body (l,body) = (match body with
112
| SFBconst {const_body=Some _; const_opaque=false} -> str "Definition "
113
| SFBconst {const_body=Some _; const_opaque=true} -> str "Theorem "
114
| SFBconst {const_body=None} -> str "Parameter "
115
| SFBmind _ -> str "Inductive "
116
| SFBmodule _ -> str "Module "
117
| SFBalias (mp,_,_) -> str "Module "
118
| SFBmodtype _ -> str "Module Type ") ++ str (string_of_label l)
120
prlist_with_sep spc print_body struc
122
and print_modexpr locals mexpr = match mexpr with
123
| SEBident mp -> print_modpath locals mp
124
| SEBfunctor (mbid,mty,mexpr) ->
125
(* let env' = Modops.add_module (MPbid mbid) (Modops.body_of_type mtb) env
127
let locals' = (mbid, get_new_id locals (id_of_mbid mbid))::locals in
128
hov 2 (str "Functor" ++ spc() ++ str"(" ++ pr_id(id_of_mbid mbid) ++
129
str ":" ++ print_modtype locals mty.typ_expr ++
130
str ")" ++ spc () ++ print_modexpr locals' mexpr)
131
| SEBstruct (msid, struc) ->
132
hv 2 (str "Struct" ++ spc () ++ print_struct locals msid struc ++ brk (1,-2) ++ str "End")
133
| SEBapply (mexpr,marg,_) ->
134
let lapp = flatten_app mexpr [marg] in
135
hov 3 (str"(" ++ prlist_with_sep spc (print_modexpr locals) lapp ++ str")")
136
| SEBwith (_,_)-> anomaly "Not avaible yet"
139
let rec printable_body dir =
140
let dir = dirpath_prefix dir in
141
dir = empty_dirpath ||
143
match Nametab.locate_dir (qualid_of_dirpath dir) with
144
DirOpenModtype _ -> false
145
| DirModule _ | DirOpenModule _ -> printable_body dir
151
let print_module with_body mp =
152
let name = print_modpath [] mp in
153
print_module name [] with_body (Global.lookup_module mp) ++ fnl ()
155
let print_modtype kn =
156
let mtb = Global.lookup_modtype kn in
157
let name = print_kn [] kn in
158
str "Module Type " ++ name ++ str " = " ++
159
print_modtype [] mtb.typ_expr ++ fnl ()