1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586openOdoc_modeltypecontext={c_loc:Location_.spanoption;c_context:stringlist}(** Context added by {!with_location} and {!with_context}. *)letcontext_acc=ref{c_loc=None;c_context=[]}letacc=ref[]letwith_refrxf=letsaved=!rinr:=x;letv=f()inletx=!rinr:=saved;(v,x)letaddf=acc:=f::!acc(** Raise a single message for root errors. *)letraise_root_errors~filenamefailures=letroots=List.fold_left(funacc->function`Rootname->name::acc|`Warning_->acc)[]failures|>List.sort_uniqString.compareinmatchrootswith|[]->()|_::_->Error.raise_warning~non_fatal:true(Error.filename_only"Couldn't find the following modules:@;<1 2>@[%a@]"Format.(pp_print_list~pp_sep:pp_print_spacepp_print_string)rootsfilename)(** Raise the other warnings. *)letraise_warnings~filenamefailures=List.iter(function|`Root_->()|`Warning(msg,context,non_fatal)->letrecpp_contextfmt=function|hd::tl->pp_contextfmttl;Format.fprintffmt"%s@\n"hd|[]->()inletpp_failurefmt()=Format.fprintffmt"%a%s"pp_contextcontext.c_contextmsginleterr=matchcontext.c_locwith|Someloc->Error.make"%a"pp_failure()loc|None->Error.filename_only"%a"pp_failure()filenameinError.raise_warning~non_fatalerr)failuresletcatch_failures~filenamef=letr,failures=with_refacc[]finError.catch_warnings(fun()->raise_root_errors~filenamefailures;raise_warnings~filenamefailures;r)letkasprintfkfmt=Format.(kfprintf(fun_->k(flush_str_formatter()))str_formatterfmt)letreport~non_fatalfmt=kasprintf(funmsg->add(`Warning(msg,!context_acc,non_fatal)))fmtletreport_internalfmt=report~non_fatal:truefmtletreport_root~name=add(`Rootname)letreport_warningfmt=report~non_fatal:falsefmtletwith_locationlocf=fst(with_refcontext_acc{!context_accwithc_loc=Someloc}f)letwith_contextfmt=kasprintf(funmsgf->letc=!context_accinfst(with_refcontext_acc{cwithc_context=msg::c.c_context}f))fmt