123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400(************************************************************************)(* * The Rocq Prover / The Rocq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)letmake_flagkeyv=letr=refvinlet()=Goptions.declare_bool_option{optstage=Summary.Stage.Interp;optdepr=None;optkey=key;optread=(fun()->!r);optwrite=(funb->r:=b);}inr(* detyping + extern + random stuff *)letraw_print=make_flag["Printing";"All"]false(* detyping + extern + a few extra things (eg About) *)(* XXX why does extern look at this flag? *)letprint_universes=make_flag["Printing";"Universes"]false(* detyping *)let{Goptions.get=print_sort_quality}=Goptions.declare_bool_option_and_ref~key:["Printing";"Sort";"Qualities"]~value:true()(* detyping *)letprint_evar_arguments=make_flag["Printing";"Existential";"Instances"]false(* detyping *)let{Goptions.get=print_wildcard}=Goptions.declare_bool_option_and_ref~key:["Printing";"Wildcard"]~value:true()(* detyping *)let{Goptions.get=fast_name_generation}=Goptions.declare_bool_option_and_ref~key:["Fast";"Name";"Printing"]~value:false()(* detyping *)let{Goptions.get=synthetize_type}=Goptions.declare_bool_option_and_ref~key:["Printing";"Synth"]~value:true()(* detyping *)let{Goptions.get=print_matching}=Goptions.declare_bool_option_and_ref~key:["Printing";"Matching"]~value:true()(* detyping *)let{Goptions.get=print_primproj_params}=Goptions.declare_bool_option_and_ref~key:["Printing";"Primitive";"Projection";"Parameters"]~value:false()(* detyping *)let{Goptions.get=print_unfolded_primproj_asmatch}=Goptions.declare_bool_option_and_ref~key:["Printing";"Unfolded";"Projection";"As";"Match"]~value:false()(* detyping *)let{Goptions.get=print_match_paramunivs}=Goptions.declare_bool_option_and_ref~key:["Printing";"Match";"All";"Subterms"]~value:false()(* detyping *)let{Goptions.get=print_relevances}=Goptions.declare_bool_option_and_ref~key:["Printing";"Relevance";"Marks"]~value:false()(* detyping.ml but extern time *)let{Goptions.get=print_factorize_match_patterns}=Goptions.declare_bool_option_and_ref~key:["Printing";"Factorizable";"Match";"Patterns"]~value:true()(* detyping.ml but extern time *)letprint_allow_match_default_clause=make_flag["Printing";"Allow";"Match";"Default";"Clause"]true(* extern *)letprint_coercions=make_flag["Printing";"Coercions"]false(* extern + ppconstr *)letprint_parentheses=make_flag["Printing";"Parentheses"]false(* constant for now, TODO expose as a new option *)(* extern *)letprint_implicits_explicit_args()=false(* extern *)letprint_implicits=make_flag["Printing";"Implicit"]false(* extern *)letprint_implicits_defensive=make_flag["Printing";"Implicit";"Defensive"]true(* extern *)letprint_projections=make_flag["Printing";"Projections"]false(* extern *)letprint_no_symbol=reffalselet()=(* Printing Notations uses a negated ref for convenience in Himsg.explicit_flags *)Goptions.declare_bool_option{optstage=Summary.Stage.Interp;optdepr=None;optkey=["Printing";"Notations"];optread=(fun()->not!print_no_symbol);optwrite=(funb->print_no_symbol:=notb);}(* extern *)letprint_raw_literal=make_flag["Printing";"Raw";"Literals"]false(* extern *)let{Goptions.get=print_use_implicit_types}=Goptions.declare_bool_option_and_ref~key:["Printing";"Use";"Implicit";"Types"]~value:true()(* extern *)let{Goptions.get=get_record_print}=Goptions.declare_bool_option_and_ref~key:["Printing";"Records"]~value:true()(* extern *)let{Goptions.get=print_float}=Goptions.declare_bool_option_and_ref~key:["Printing";"Float"]~value:true()(* extern (option handled by topfmt) *)letextern_depth=refNoneletset_extern_depthd=extern_depth:=dletextern_depth()=!extern_depthmodulePrintingInductiveMake(Test:sigvalencode:Environ.env->Libnames.qualid->Names.inductivevalmember_message:Pp.t->bool->Pp.tvalfield:stringvaltitle:stringend)=structtypet=Names.inductivemoduleSet=Names.Indset_envletencodeenvind=Environ.QInd.canonizeenv(Test.encodeenvind)letsubstsubstobj=Mod_subst.subst_indsubstobjletcheck_local__=()letdischarge(i:t)=iletprinterind=Nametab.pr_global_envNames.Id.Set.empty(IndRefind)letkey=["Printing";Test.field]lettitle=Test.titleletmember_messagex=Test.member_message(printerx)end(**********************************************************************)(* Control printing of records *)letencode_recordenvr=letindsp=Nametab.global_inductiverinifnot(Structures.Structure.memenvindsp)thenCErrors.user_err?loc:r.CAst.locPp.(str"This type is not a structure type.");indspmodulePrintingRecordRecord=PrintingInductiveMake(structletencode=encode_recordletfield="Record"lettitle="Types leading to pretty-printing using record notation: "letmember_messagesb=letopenPpinstr"Terms of "++s++str(ifbthen" are printed using record notation"else" are not printed using record notation")end)modulePrintingRecordConstructor=PrintingInductiveMake(structletencode=encode_recordletfield="Constructor"lettitle="Types leading to pretty-printing using constructor form: "letmember_messagesb=letopenPpinstr"Terms of "++s++str(ifbthen" are printed using constructor form"else" are not printed using constructor form")end)modulePrintingRecord=Goptions.MakeRefTable(PrintingRecordRecord)modulePrintingConstructor=Goptions.MakeRefTable(PrintingRecordConstructor)moduleDetype=structtypet={universes:bool;qualities:bool;relevances:bool;evar_instances:bool;wildcard:bool;fast_names:bool;synth_match_return:bool;matching:bool;primproj_params:bool;unfolded_primproj_as_match:bool;match_paramunivs:bool;always_regular_match_style:bool;(* XXX is there a better word than "nonpropositional"? *)nonpropositional_letin_types:bool;}letcurrent_ignore_raw()={universes=!print_universes;qualities=print_sort_quality();relevances=print_relevances();evar_instances=!print_evar_arguments;wildcard=print_wildcard();fast_names=fast_name_generation();synth_match_return=synthetize_type();matching=print_matching();primproj_params=print_primproj_params();unfolded_primproj_as_match=print_unfolded_primproj_asmatch();match_paramunivs=print_match_paramunivs();(* not yet exposed (except through Printing All) *)always_regular_match_style=false;nonpropositional_letin_types=false;}letmake_rawflags={flagswithsynth_match_return=false;always_regular_match_style=true;matching=false;nonpropositional_letin_types=true;}letcurrent()=letflags=current_ignore_raw()inif!raw_printthenmake_rawflagselseflagsendmoduleExtern=structmoduleFactorizeEqns=structtypet={factorize_match_patterns:bool;allow_match_default_clause:bool;}letcurrent_ignore_raw()={factorize_match_patterns=print_factorize_match_patterns();allow_match_default_clause=!print_allow_match_default_clause;}(* all flags are overridden, but for forwards compat we still take
the base flags *)letmake_raw_flags={factorize_match_patterns=false;allow_match_default_clause=false;}letcurrent()=letflags=current_ignore_raw()inif!raw_printthenmake_rawflagselseflagsendmoduleRecords=structopenNamestypet={default:bool;force_record:Indset_env.t;force_constructor:Indset_env.t;}letcurrent_ignore_raw()={default=get_record_print();force_record=PrintingRecord.v();force_constructor=PrintingConstructor.v();}letmake_raw_flags={default=false;force_record=Indset_env.empty;force_constructor=Indset_env.empty;}letcurrent()=letflags=current_ignore_raw()inif!raw_printthenmake_rawflagselseflagsletuse_record_syntaxflagsr=(flags.default&¬(Indset_env.memrflags.force_constructor))||Indset_env.memrflags.force_recordendtypet={use_implicit_types:bool;records:Records.t;implicits:bool;implicits_explicit_args:bool;implicits_defensive:bool;coercions:bool;parentheses:bool;notations:bool;raw_literals:bool;projections:bool;float:bool;factorize_eqns:FactorizeEqns.t;depth:intoption;}letcurrent_ignore_raw()={use_implicit_types=print_use_implicit_types();records=Records.current_ignore_raw();implicits=!print_implicits;implicits_explicit_args=print_implicits_explicit_args();implicits_defensive=!print_implicits_defensive;coercions=!print_coercions;parentheses=!print_parentheses;notations=not!print_no_symbol;raw_literals=!print_raw_literal;projections=!print_projections;float=print_float();factorize_eqns=FactorizeEqns.current_ignore_raw();depth=extern_depth();}letmake_rawflags={flagswithrecords=Records.make_rawflags.records;use_implicit_types=false;implicits=true;implicits_explicit_args=false;coercions=true;raw_literals=true;notations=false;projections=false;factorize_eqns=FactorizeEqns.make_rawflags.factorize_eqns;}letcurrent()=letflags=current_ignore_raw()inif!raw_printthenmake_rawflagselseflagsendtypet={detype:Detype.t;extern:Extern.t;}letmake_rawflags={detype=Detype.make_rawflags.detype;extern=Extern.make_rawflags.extern;}letcurrent()={detype=Detype.current();extern=Extern.current();}letcurrent_ignore_raw()={detype=Detype.current_ignore_raw();extern=Extern.current_ignore_raw();}