Debian Codegraph @

pretyping/printingFlags.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 let make_flag key v =
12 let r = ref v in
13 let () =
14 Goptions.declare_bool_option {
15 optstage = Summary.Stage.Interp;
16 optdepr = None;
17 optkey = key;
18 optread = (fun () -> !r);
19 optwrite = (fun b -> r := b);
20 }
21 in
22 r
23
24 (* detyping + extern + random stuff *)
25 let raw_print = make_flag ["Printing";"All"] false
26
27 (* detyping + extern + a few extra things (eg About) *)
28 (* XXX why does extern look at this flag? *)
29 let print_universes = make_flag ["Printing";"Universes"] false
30
31 (* detyping *)
32 let { Goptions.get = print_sort_quality } =
33 Goptions.declare_bool_option_and_ref
34 ~key:["Printing";"Sort";"Qualities"]
35 ~value:true
36 ()
37
38 (* detyping *)
39 let print_evar_arguments = make_flag ["Printing";"Existential";"Instances"] false
40
41 (* detyping *)
42 let { Goptions.get = print_wildcard } =
43 Goptions.declare_bool_option_and_ref
44 ~key:["Printing";"Wildcard"]
45 ~value:true
46 ()
47
48 (* detyping *)
49 let { Goptions.get = fast_name_generation } =
50 Goptions.declare_bool_option_and_ref
51 ~key:["Fast";"Name";"Printing"]
52 ~value:false
53 ()
54
55 (* detyping *)
56 let { Goptions.get = synthetize_type } =
57 Goptions.declare_bool_option_and_ref
58 ~key:["Printing";"Synth"]
59 ~value:true
60 ()
61
62 (* detyping *)
63 let { Goptions.get = print_matching } =
64 Goptions.declare_bool_option_and_ref
65 ~key:["Printing";"Matching"]
66 ~value:true
67 ()
68
69 (* detyping *)
70 let { Goptions.get = print_primproj_params } =
71 Goptions.declare_bool_option_and_ref
72 ~key:["Printing";"Primitive";"Projection";"Parameters"]
73 ~value:false
74 ()
75
76 (* detyping *)
77 let { Goptions.get = print_unfolded_primproj_asmatch } =
78 Goptions.declare_bool_option_and_ref
79 ~key:["Printing";"Unfolded";"Projection";"As";"Match"]
80 ~value:false
81 ()
82
83 (* detyping *)
84 let { Goptions.get = print_match_paramunivs } =
85 Goptions.declare_bool_option_and_ref
86 ~key:["Printing";"Match";"All";"Subterms"]
87 ~value:false
88 ()
89
90 (* detyping *)
91 let { Goptions.get = print_relevances } =
92 Goptions.declare_bool_option_and_ref
93 ~key:["Printing";"Relevance";"Marks"]
94 ~value:false
95 ()
96
97 (* detyping.ml but extern time *)
98 let { Goptions.get = print_factorize_match_patterns } =
99 Goptions.declare_bool_option_and_ref
100 ~key:["Printing";"Factorizable";"Match";"Patterns"]
101 ~value:true
102 ()
103
104 (* detyping.ml but extern time *)
105 let print_allow_match_default_clause = make_flag ["Printing";"Allow";"Match";"Default";"Clause"] true
106
107 (* extern *)
108 let print_coercions = make_flag ["Printing";"Coercions"] false
109
110 (* extern + ppconstr *)
111 let print_parentheses = make_flag ["Printing";"Parentheses"] false
112
113 (* constant for now, TODO expose as a new option *)
114 (* extern *)
115 let print_implicits_explicit_args () = false
116
117 (* extern *)
118 let print_implicits = make_flag ["Printing";"Implicit"] false
119
120 (* extern *)
121 let print_implicits_defensive = make_flag ["Printing";"Implicit";"Defensive"] true
122
123 (* extern *)
124 let print_projections = make_flag ["Printing";"Projections"] false
125
126 (* extern *)
127 let print_no_symbol = ref false
128
129 let () =
130 (* Printing Notations uses a negated ref for convenience in Himsg.explicit_flags *)
131 Goptions.declare_bool_option
132 { optstage = Summary.Stage.Interp;
133 optdepr = None;
134 optkey = ["Printing";"Notations"];
135 optread = (fun () -> not !print_no_symbol);
136 optwrite = (fun b -> print_no_symbol := not b);
137 }
138
139 (* extern *)
140 let print_raw_literal = make_flag ["Printing";"Raw";"Literals"] false
141
142 (* extern *)
143 let { Goptions.get = print_use_implicit_types } =
144 Goptions.declare_bool_option_and_ref
145 ~key:["Printing";"Use";"Implicit";"Types"]
146 ~value:true
147 ()
148
149 (* extern *)
150 let { Goptions.get = get_record_print } =
151 Goptions.declare_bool_option_and_ref
152 ~key:["Printing";"Records"]
153 ~value:true
154 ()
155
156 (* extern *)
157 let { Goptions.get = print_float } =
158 Goptions.declare_bool_option_and_ref
159 ~key:["Printing";"Float"]
160 ~value:true
161 ()
162
163 (* extern (option handled by topfmt) *)
164 let extern_depth = ref None
165 let set_extern_depth d = extern_depth := d
166 let extern_depth() = !extern_depth
167
168 module PrintingInductiveMake (Test : sig
169 val encode : Environ.env -> Libnames.qualid -> Names.inductive
170 val member_message : Pp.t -> bool -> Pp.t
171 val field : string
172 val title : string
173 end) =
174 struct
175 type t = Names.inductive
176 module Set = Names.Indset_env
177 let encode env ind = Environ.QInd.canonize env (Test.encode env ind)
178 let subst subst obj = Mod_subst.subst_ind subst obj
179 let check_local _ _ = ()
180 let discharge (i:t) = i
181 let printer ind = Nametab.pr_global_env Names.Id.Set.empty (IndRef ind)
182 let key = ["Printing";Test.field]
183 let title = Test.title
184 let member_message x = Test.member_message (printer x)
185 end
186
187 (**********************************************************************)
188 (* Control printing of records *)
189
190 let encode_record env r =
191 let indsp = Nametab.global_inductive r in
192 if not (Structures.Structure.mem env indsp) then
193 CErrors.user_err ?loc:r.CAst.loc
194 Pp.(str "This type is not a structure type.");
195 indsp
196
197 module PrintingRecordRecord =
198 PrintingInductiveMake (struct
199 let encode = encode_record
200 let field = "Record"
201 let title = "Types leading to pretty-printing using record notation: "
202 let member_message s b =
203 let open Pp in
204 str "Terms of " ++ s ++
205 str
206 (if b then " are printed using record notation"
207 else " are not printed using record notation")
208 end)
209
210 module PrintingRecordConstructor =
211 PrintingInductiveMake (struct
212 let encode = encode_record
213 let field = "Constructor"
214 let title = "Types leading to pretty-printing using constructor form: "
215 let member_message s b =
216 let open Pp in
217 str "Terms of " ++ s ++
218 str
219 (if b then " are printed using constructor form"
220 else " are not printed using constructor form")
221 end)
222
223 module PrintingRecord = Goptions.MakeRefTable(PrintingRecordRecord)
224 module PrintingConstructor = Goptions.MakeRefTable(PrintingRecordConstructor)
225
226 module Detype = struct
227 type t = {
228 universes : bool;
229 qualities : bool;
230 relevances : bool;
231 evar_instances : bool;
232 wildcard : bool;
233 fast_names : bool;
234 synth_match_return : bool;
235 matching : bool;
236 primproj_params : bool;
237 unfolded_primproj_as_match : bool;
238 match_paramunivs : bool;
239 always_regular_match_style : bool;
240 (* XXX is there a better word than "nonpropositional"? *)
241 nonpropositional_letin_types : bool;
242 }
243
244 let current_ignore_raw () = {
245 universes = !print_universes;
246 qualities = print_sort_quality();
247 relevances = print_relevances();
248 evar_instances = !print_evar_arguments;
249 wildcard = print_wildcard();
250 fast_names = fast_name_generation();
251 synth_match_return = synthetize_type();
252 matching = print_matching();
253 primproj_params = print_primproj_params();
254 unfolded_primproj_as_match = print_unfolded_primproj_asmatch();
255 match_paramunivs = print_match_paramunivs();
256
257 (* not yet exposed (except through Printing All) *)
258 always_regular_match_style = false;
259 nonpropositional_letin_types = false;
260 }
261
262 let make_raw flags = {
263 flags with
264 synth_match_return = false;
265 always_regular_match_style = true;
266 matching = false;
267 nonpropositional_letin_types = true;
268 }
269
270 let current () =
271 let flags = current_ignore_raw () in
272 if !raw_print then make_raw flags else flags
273
274 end
275
276 module Extern = struct
277 module FactorizeEqns = struct
278 type t = {
279 factorize_match_patterns : bool;
280 allow_match_default_clause : bool;
281 }
282
283 let current_ignore_raw () = {
284 factorize_match_patterns = print_factorize_match_patterns();
285 allow_match_default_clause = !print_allow_match_default_clause;
286 }
287
288 (* all flags are overridden, but for forwards compat we still take
289 the base flags *)
290 let make_raw _flags = {
291 factorize_match_patterns = false;
292 allow_match_default_clause = false;
293 }
294
295 let current () =
296 let flags = current_ignore_raw() in
297 if !raw_print then make_raw flags else flags
298 end
299
300 module Records = struct
301 open Names
302
303 type t = {
304 default : bool;
305 force_record : Indset_env.t;
306 force_constructor : Indset_env.t;
307 }
308
309 let current_ignore_raw () = {
310 default = get_record_print();
311 force_record = PrintingRecord.v();
312 force_constructor = PrintingConstructor.v();
313 }
314
315 let make_raw _flags = {
316 default = false;
317 force_record = Indset_env.empty;
318 force_constructor = Indset_env.empty;
319 }
320
321 let current () =
322 let flags = current_ignore_raw() in
323 if !raw_print then make_raw flags else flags
324
325 let use_record_syntax flags r =
326 (flags.default && not (Indset_env.mem r flags.force_constructor)) ||
327 Indset_env.mem r flags.force_record
328
329 end
330
331 type t = {
332 use_implicit_types : bool;
333 records : Records.t;
334 implicits : bool;
335 implicits_explicit_args : bool;
336 implicits_defensive : bool;
337 coercions : bool;
338 parentheses : bool;
339 notations : bool;
340 raw_literals : bool;
341 projections : bool;
342 float : bool;
343 factorize_eqns : FactorizeEqns.t;
344 depth : int option;
345 }
346
347 let current_ignore_raw () = {
348 use_implicit_types = print_use_implicit_types();
349 records = Records.current_ignore_raw();
350 implicits = !print_implicits;
351 implicits_explicit_args = print_implicits_explicit_args();
352 implicits_defensive = !print_implicits_defensive;
353 coercions = !print_coercions;
354 parentheses = !print_parentheses;
355 notations = not !print_no_symbol;
356 raw_literals = !print_raw_literal;
357 projections = !print_projections;
358 float = print_float();
359 factorize_eqns = FactorizeEqns.current_ignore_raw();
360 depth = extern_depth();
361 }
362
363 let make_raw flags = {
364 flags with
365 records = Records.make_raw flags.records;
366 use_implicit_types = false;
367 implicits = true;
368 implicits_explicit_args = false;
369 coercions = true;
370 raw_literals = true;
371 notations = false;
372 projections = false;
373 factorize_eqns = FactorizeEqns.make_raw flags.factorize_eqns;
374 }
375
376 let current () =
377 let flags = current_ignore_raw() in
378 if !raw_print then make_raw flags else flags
379 end
380
381
382 type t = {
383 detype : Detype.t;
384 extern : Extern.t;
385 }
386
387 let make_raw flags = {
388 detype = Detype.make_raw flags.detype;
389 extern = Extern.make_raw flags.extern;
390 }
391
392 let current () = {
393 detype = Detype.current();
394 extern = Extern.current();
395 }
396
397 let current_ignore_raw () = {
398 detype = Detype.current_ignore_raw();
399 extern = Extern.current_ignore_raw();
400 }