123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170moduleB=Kernel.BasicmoduleS=Kernel.SignaturemoduleP=Parsers.ParsermoduleProcessor=Api.Processor(** path to a file *)typepath=stringtypecintypecout(** Gather out_channel and in_channel in a GADT for input and output files. In the case of an output file, we store also the formatter associated with. *)type_channel=|In:in_channel->cinchannel|Out:out_channel*Format.formatter->coutchanneltype'at={path:path;(** Path to the current file *)md:B.mident;(** Md of this file *)channel:'achannel;(** OCaml channel to this file *)}(** Output directory where output files are created *)letoutput_directory:stringoptionref=refNone(** Simplify directory where simplified files are created. *)letsimplify_directory:stringoptionref=refNone(** Suffix used for files containing universe declarations *)letelaboration_suffix="_univ"(** Suffix used for files containing universe constraints *)letchecking_suffix="_cstr"(** Suffix used for files containing universe solution *)letsolution_suffix="_sol"(** Suffix used for elaborated file where sorts are replaced by fresh variables *)letnormal_suffix=""(** The steps used to refer the files used by Universo *)typestep=[`Input(** Input module *)|`Output(** Output module *)|`Elaboration(** File with universe declarations *)|`Checking(** File with constraints *)|`Solution(** File containing the solution *)|`Simplify(** Output file where the variables are replaced by the solution *)](** [add_sufix file suffix] returns the string [file'] where suffix is_added at then end of [file] *)letadd_suffix:path->string->string=funfilesuffix->letext=Filename.extensionfileinletname=Filename.chop_extensionfileinname^suffix^ext(** [add_dir dir file] prefix the filename [file] with the directory [dir] *)letadd_dir:string->string->string=fundirfile->dir^Filename.dir_sep^Filename.basenamefileletmk_dir:stringoptionref->string->unit=funrfdir->(tryignore(Unix.statdir)with_->Unix.mkdirdir0o755);rf:=Somedir(** return the suffix according to the step [s] *)letsuffix_of_step:step->string=function|`Elaboration->elaboration_suffix|`Checking->checking_suffix|`Solution->solution_suffix|`Input|`Simplify|`Output->normal_suffixlettheory:stringoptionref=refNoneletmk_theory:path->unit=funpath->theory:=Somepathletget_theory:unit->string=fun()->match!theorywithNone->failwith"Theory not given"|Somet->t(** [get_out_path p s] returns the path that corresponds to the step [s] for path [p] *)letget_out_path:path->step->path=funpathstep->letfile_suffix=add_suffixpath(suffix_of_stepstep)inmatchstepwith|`Input->file_suffix|`Simplify->(match!simplify_directorywith|None->assertfalse|Somedir->add_dirdirfile_suffix)|_->(match!output_directorywith|None->failwith"Output_directory must be set. See --help for more information"|Somedir->add_dirdirfile_suffix)(** [from_string f s] returns the filename that corresponds to the step [s] for file [f] *)letout_from_string:path->step->coutt=funpathstep->letpath=get_out_pathpathstepinletmd=P.md_of_filepathinletoc=open_outpathinletfmt=Format.formatter_of_out_channelocin{path;md;channel=Out(oc,fmt)}(** [from_string f s] returns the filename that corresponds to the step [s] for file [f] *)letin_from_string:path->step->cint=funpathstep->letpath=get_out_pathpathstepinletmd=P.md_of_filepathinletic=open_inpathin{path;md;channel=Inic}(* (\** [signature_of_file f] returns a signature that contains all the declarations in [f]. *\) *)(* let signature_of_file : path -> S.t = *)(* fun file -> Api.Processor.handle_files [ file ] Api.Processor.SignatureBuilder *)(** [fmt_of_file out_file] returns the formatter associated to an [out_file] *)letfmt_of_file:coutt->Format.formatter=funfile->matchfile.channelwithOut(_,fmt)->fmt(** [in_channel_of_file in_file] returns the channel associated to an [in_file] *)letin_channel_of_file:cint->in_channel=funfile->matchfile.channelwithInic->ic(** [close file] closes [file] *)letclose:typea.at->unit=funfile->matchfile.channelwithOut(oc,_)->close_outoc|Inic->close_inic(** [md_of path step] returns the mident associated to the Universo file [file] for step [step]. *)letmd_of:path->step->B.mident=funin_pathstep->P.md_of_file(get_out_pathin_pathstep)letadd_requires:Format.formatter->B.midentlist->unit=funfmtmds->List.iter(funmd->Format.fprintffmt"#REQUIRE %a.@."Api.Pp.Default.print_midentmd)mdstype_Processor.t+=FilterSignature:Api.Env.tProcessor.tletexport:path->step->unit=funin_pathstep->letout_file=get_out_pathin_pathstepinletis_eq_ruler=letopenKernel.Ruleinmatchr.patwithPattern(_,_,[])->true|_->falseinlet(moduleSB)=Processor.get_processorProcessor.SignatureBuilderinletmoduleP=structtypet=Api.Env.tlethandle_entryenventry=let(moduleSB)=Processor.get_processorProcessor.SignatureBuilderinmatch(step,entry)with(* TODO: don't remember why only equality constraints are exported *)|`Checking,Parsers.Entry.Rules(_,r::_)whenis_eq_ruler->SB.handle_entryenventry|`Checking,_->()|_,_->SB.handle_entryenventryletget_dataenv=envendinletenv=Api.Processor.T.handle_files[out_file](moduleP)inApi.Env.exportenv