123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * INRIA, CNRS and contributors - Copyright 1999-2018 *)(* <O___,, * (see CREDITS file for the list of authors) *)(* \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) *)(************************************************************************)(************************************************************************)(* Coq serialization API/Plugin *)(* Copyright 2016-2018 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)(* Status: Very Experimental *)(************************************************************************)openSexplibopenSexplib.ConvopenSerlibtypeser_printer=|SP_Sertop(* sertop custom printer (UTF-8,stronger quoting) *)|SP_Mach(* sexplib mach printer *)|SP_Human(* sexplib human printer *)let select_printerpr=matchprwith|SP_Sertop ->Sertop_util.pp_sertop|SP_Mach->Sexp.pp|SP_Human->Sexp.pp_hummoduleSP=Serapi.Serapi_protocol(******************************************************************************)(* Exception Registration *)(******************************************************************************)(* We play slow for now *)let_=(* XXX Finish this *)letopenSexpinletsexp_of_std_ppcmdspp=Atom(Pp.string_of_ppcmdspp)inConv.Exn_converter.add[%extension_constructorSP.NoSuchState](function(* Own things *)|SP.NoSuchStatesid->List[Atom"NoSuchState";Ser_stateid.sexp_of_tsid]|_->assertfalse);Conv.Exn_converter.add[%extension_constructorCErrors.UserError](function(* Errors *)|CErrors.UserError(msg)->List[Atom"CErrors.UserError";List[sexp_of_std_ppcmdsmsg]]|_->assertfalse);Conv.Exn_converter.add[%extension_constructorDeclareUniv.AlreadyDeclared](function|DeclareUniv.AlreadyDeclared(msg,id)->List[Atom"Declare.AlreadyDeclared";List[sexp_of_optionsexp_of_stringmsg;Ser_names.Id.sexp_of_tid]]|_->assertfalse);Conv.Exn_converter.add[%extension_constructorPretype_errors.PretypeError](function(* Pretype Errors XXX what to do with _env, _envmap *)|Pretype_errors.PretypeError(_env,_evmap,pterr)->List[Atom"Pretype_errors.PretypeError";List[Ser_pretype_errors.sexp_of_pretype_errorpterr]]|_->assertfalse);(* Conv.Exn_converter.add [%extension_constructor Proof_global.NoCurrentProof] (function
* | Proof_global.NoCurrentProof ->
* Atom "NoCurrentProof"
* | _ -> assert false) *)(* Private... request Coq devs to make them public?
| Errors.Anomaly(msgo, pp) ->
Some (List [Atom "Anomaly"; sexp_of_option sexp_of_string msgo; sexp_of_std_ppcmds pp])
*)(******************************************************************************)(* Serialization of the Protocol *)(******************************************************************************)moduleLoc=Ser_locmoduleCAst=Ser_cAstmodulePp=Ser_ppmoduleNames=Ser_namesmoduleEnviron=Ser_environmoduleGoptions=Ser_goptionsmoduleCoqargs=Ser_coqargsmoduleStateid=Ser_stateidmoduleEvar=Ser_evarmoduleContext=Ser_contextmoduleFeedback=Ser_feedbackmoduleLibnames=Ser_libnamesmoduleGlobnames=Ser_globnamesmoduleImpargs=Ser_impargsmoduleConstr=Ser_constrmoduleConstrexpr=Ser_constrexprmoduleProof=Ser_proofmoduleGoal=Ser_goalmoduleTok=Ser_tokmodulePpextend=Ser_ppextendmoduleNotation_gram=Ser_notation_grammoduleGenarg=Ser_genargmoduleLoadpath=Ser_loadpathmodulePrinter=Ser_printer(* Alias fails due to the [@@default in protocol] *)(* module Stm = Ser_stm *)moduleSer_stm=Ser_stmmoduleLtac_plugin=structmoduleTacenv=Serlib_ltac.Ser_tacenvmoduleProfile_ltac=Serlib_ltac.Ser_profile_ltacmoduleTacexpr=Serlib_ltac.Ser_tacexprendmoduleNotation=Ser_notationmoduleXml_datatype=Ser_xml_datatypemoduleNotation_term=Ser_notation_termmoduleVernacexpr=Ser_vernacexprmoduleDeclarations=Ser_declarations(* module Richpp = Ser_richpp *)moduleSerapi=structmoduleSerapi_goals=structtype'ahyp=[%import:'aSerapi.Serapi_goals.hyp][@@derivingsexp]typeinfo=[%import:Serapi.Serapi_goals.info][@@derivingsexp]type'areified_goal=[%import:'aSerapi.Serapi_goals.reified_goal][@@derivingsexp]type'aser_goals=[%import:'aSerapi.Serapi_goals.ser_goals][@@derivingsexp]endmoduleSerapi_assumptions=structtypeax_ctx=[%import:Serapi.Serapi_assumptions.ax_ctx][@@derivingsexp]typet=[%import:Serapi.Serapi_assumptions.t][@@derivingsexp]endmoduleSerapi_protocol=Serapi.Serapi_protocolend(* Serialization to sexp *)typecoq_object=[%import:Serapi.Serapi_protocol.coq_object][@@derivingsexp]exceptionAnswerExnofSexp.tletexn_of_sexpsexp=AnswerExnsexptypeprint_format=[%import:Serapi.Serapi_protocol.print_format][@@derivingsexp]typeformat_opt=[%import:Serapi.Serapi_protocol.format_opt][@@derivingsexp]typeprint_opt=[%import:Serapi.Serapi_protocol.print_opt][@@derivingsexp]typequery_pred=[%import:Serapi.Serapi_protocol.query_pred][@@derivingsexp]typequery_opt=[%import:Serapi.Serapi_protocol.query_opt[@withSexplib.Conv.sexp_list:=sexp_list;Sexplib.Conv.sexp_option:=sexp_option;]][@@derivingsexp]typequery_cmd=[%import:Serapi.Serapi_protocol.query_cmd][@@derivingsexp]typecmd_tag=[%import:Serapi.Serapi_protocol.cmd_tag][@@derivingsexp]typelocation=[%import:Printexc.location][@@derivingsexp]typeraw_backtrace=Printexc.raw_backtraceletraw_backtrace_of_sexp_=Printexc.get_raw_backtrace()typeslot_rep={slot_loc:locationoption;slot_idx:int;slot_str:stringoption;}[@@derivingsexp]letto_slot_repidxbs={slot_loc=Printexc.Slot.locationbs;slot_idx=idx;slot_str=Printexc.Slot.formatidxbs;}letsexp_of_backtrace_slotidxbs=sexp_of_slot_rep(to_slot_repidxbs)letsexp_of_raw_backtrace(bt:Printexc.raw_backtrace):Sexp.t=letbt=Printexc.backtrace_slotsbtinletbt=Option.mapArray.(mapisexp_of_backtrace_slot)btinletbt=sexp_of_option(sexp_of_array(funx->x))btinSexp.(List[Atom"Backtrace";bt])moduleExnInfo=structtypet=[%import:Serapi.Serapi_protocol.ExnInfo.t[@withStm.focus:=Ser_stm.focus;Printexc.raw_backtrace:=raw_backtrace;Stdlib.Printexc.raw_backtrace:=raw_backtrace;]][@@derivingsexp]endtypeanswer_kind=[%import:Serapi.Serapi_protocol.answer_kind[@withExninfo.t:=Exninfo.t;Stm.add_focus:=Ser_stm.add_focus;]][@@derivingsexp]typefeedback_content=[%import:Serapi.Serapi_protocol.feedback_content][@@derivingsexp]typefeedback=[%import:Serapi.Serapi_protocol.feedback][@@derivingsexp]typeanswer=[%import:Serapi.Serapi_protocol.answer][@@derivingsexp]typeadd_opts=[%import:Serapi.Serapi_protocol.add_opts[@withSexplib.Conv.sexp_option:=sexp_option;]][@@derivingsexp]typenewdoc_opts=[%import:Serapi.Serapi_protocol.newdoc_opts[@with(* Stm.interactive_top := Ser_stm.interactive_top; *)Sexplib.Conv.sexp_list:=sexp_list;Sexplib.Conv.sexp_option:=sexp_option;]][@@derivingsexp]typesave_opts=[%import:Serapi.Serapi_protocol.save_opts][@@derivingsexp]typeparse_opt=[%import:Serapi.Serapi_protocol.parse_opt[@withSexplib.Conv.sexp_option :=sexp_option;]][@@derivingsexp]typecmd=[%import:Serapi.Serapi_protocol.cmd][@@derivingsexp]typetagged_cmd=[%import:Serapi.Serapi_protocol.tagged_cmd][@@derivingsexp]typesentence=SentenceofTok.tCAst.tlist[@@derivingsexp]