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
(************************************************************************)
9
(* $Id: dumpglob.ml 11582 2008-11-12 19:49:57Z notin $ *)
12
(* Dump of globalization (to be used by coqdoc) *)
14
let glob_file = ref Pervasives.stdout
16
let open_glob_file f =
17
glob_file := Pervasives.open_out f
19
let close_glob_file () =
20
Pervasives.close_out !glob_file
28
let glob_output = ref NoGlob
30
let dump () = !glob_output != NoGlob
32
let noglob () = glob_output := NoGlob
34
let dump_to_stdout () = glob_output := StdOut; glob_file := Pervasives.stdout
36
let multi_dump () = !glob_output = MultFiles
38
let dump_to_dotglob f = glob_output := MultFiles
40
let dump_into_file f = glob_output := File f; open_glob_file f
43
if dump () then Pervasives.output_string !glob_file s
46
let previous_state = ref MultFiles
47
let pause () = previous_state := !glob_output; glob_output := NoGlob
48
let continue () = glob_output := !previous_state
51
let token_number = ref 0
54
type coqdoc_state = Lexer.location_table * int * int
56
let coqdoc_freeze () =
57
let lt = Lexer.location_table() in
58
let state = (lt,!token_number,!last_pos) in
63
let coqdoc_unfreeze (lt,tn,lp) =
64
Lexer.restore_location_table lt;
70
let type_of_logical_kind = function
75
| SubClass -> "subclass"
76
| CanonicalStructure -> "canonstruc"
81
| StructureComponent -> "proj"
82
| IdentityCoercion -> "coe"
87
| Definitional -> "defax"
89
| Conjectural -> "prfax")
100
let type_of_global_ref gr =
101
if Typeclasses.is_class gr then
105
| Libnames.ConstRef cst ->
106
type_of_logical_kind (Decls.constant_kind cst)
107
| Libnames.VarRef v ->
108
"var" ^ type_of_logical_kind (Decls.variable_kind v)
109
| Libnames.IndRef ind ->
110
let (mib,oib) = Inductive.lookup_mind_specif (Global.env ()) ind in
111
if mib.Declarations.mind_record then
112
if mib.Declarations.mind_finite then "rec"
114
else if mib.Declarations.mind_finite then "ind"
116
| Libnames.ConstructRef _ -> "constr"
118
let remove_sections dir =
119
if Libnames.is_dirpath_prefix_of dir (Lib.cwd ()) then
120
(* Not yet (fully) discharged *)
121
Libnames.extract_dirpath_prefix (Lib.sections_depth ()) (Lib.cwd ())
123
(* Theorem/Lemma outside its outer section of definition *)
126
let dump_ref loc filepath modpath ident ty =
127
dump_string (Printf.sprintf "R%d %s %s %s %s\n"
128
(fst (Util.unloc loc)) filepath modpath ident ty)
130
let add_glob_gen loc sp lib_dp ty =
132
let mod_dp,id = Libnames.repr_path sp in
133
let mod_dp = remove_sections mod_dp in
134
let mod_dp_trunc = Libnames.drop_dirpath_prefix lib_dp mod_dp in
135
let filepath = Names.string_of_dirpath lib_dp in
136
let modpath = Names.string_of_dirpath mod_dp_trunc in
137
let ident = Names.string_of_id id in
138
dump_ref loc filepath modpath ident ty
140
let add_glob loc ref =
141
if dump () && loc <> Util.dummy_loc then
142
let sp = Nametab.sp_of_global ref in
143
let lib_dp = Lib.library_part ref in
144
let ty = type_of_global_ref ref in
145
add_glob_gen loc sp lib_dp ty
148
let mp,sec,l = Names.repr_kn kn in
151
let add_glob_kn loc kn =
152
if dump () && loc <> Util.dummy_loc then
153
let sp = Nametab.sp_of_syntactic_definition kn in
154
let lib_dp = Lib.dp_of_mp (mp_of_kn kn) in
155
add_glob_gen loc sp lib_dp "syndef"
157
let add_local loc id = ()
158
(* let mod_dp,id = repr_path sp in *)
159
(* let mod_dp = remove_sections mod_dp in *)
160
(* let mod_dp_trunc = drop_dirpath_prefix lib_dp mod_dp in *)
161
(* let filepath = string_of_dirpath lib_dp in *)
162
(* let modpath = string_of_dirpath mod_dp_trunc in *)
163
(* let ident = string_of_id id in *)
164
(* dump_string (Printf.sprintf "R%d %s %s %s %s\n" *)
165
(* (fst (unloc loc)) filepath modpath ident ty) *)
167
let dump_binding loc id = ()
169
let dump_definition (loc, id) sec s =
170
dump_string (Printf.sprintf "%s %d %s %s\n" s (fst (Util.unloc loc))
171
(Names.string_of_dirpath (Lib.current_dirpath sec)) (Names.string_of_id id))
173
let dump_reference loc modpath ident ty =
174
dump_string (Printf.sprintf "R%d %s %s %s %s\n"
175
(fst (Util.unloc loc)) (Names.string_of_dirpath (Lib.library_dp ())) modpath ident ty)
177
let dump_constraint ((loc, n), _, _) sec ty =
179
| Names.Name id -> dump_definition (loc, id) sec ty
180
| Names.Anonymous -> ()
182
let dump_name (loc, n) sec ty =
184
| Names.Name id -> dump_definition (loc, id) sec ty
185
| Names.Anonymous -> ()
187
let dump_local_binder b sec ty =
190
| Topconstr.LocalRawAssum (nl, _, _) ->
191
List.iter (fun x -> dump_name x sec ty) nl
192
| Topconstr.LocalRawDef _ -> ()
194
let dump_modref loc mp ty =
196
let (dp, l) = Lib.split_modpath mp in
197
let l = if l = [] then l else Util.list_drop_last l in
198
let fp = Names.string_of_dirpath dp in
199
let mp = Names.string_of_dirpath (Names.make_dirpath l) in
200
dump_string (Printf.sprintf "R%d %s %s %s %s\n"
201
(fst (Util.unloc loc)) fp mp "<>" ty)
203
let dump_moddef loc mp ty =
205
let (dp, l) = Lib.split_modpath mp in
206
let mp = Names.string_of_dirpath (Names.make_dirpath l) in
207
dump_string (Printf.sprintf "%s %d %s %s\n" ty (fst (Util.unloc loc)) "<>" mp)
209
let dump_libref loc dp ty =
210
dump_string (Printf.sprintf "R%d %s <> <> %s\n"
211
(fst (Util.unloc loc)) (Names.string_of_dirpath dp) ty)
213
let dump_notation_location pos ((path,df),sc) =
215
let rec next growing =
216
let loc = Lexer.location_function !token_number in
217
let (bp,_) = Util.unloc loc in
218
if growing then if bp >= pos then loc else (incr token_number; next true)
219
else if bp = pos then loc
220
else if bp > pos then (decr token_number;next false)
221
else (incr token_number;next true) in
222
let loc = next (pos >= !last_pos) in
224
let path = Names.string_of_dirpath path in
225
let _sc = match sc with Some sc -> " "^sc | _ -> "" in
226
dump_string (Printf.sprintf "R%d %s \"%s\" not\n" (fst (Util.unloc loc)) path df)