123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161open!Importclassmap=objectinheritPpxlib_traverse_builtins.mapinheritAst.mapendclassiter=objectinheritPpxlib_traverse_builtins.iterinheritAst.iterendclass['acc]fold=objectinherit['acc]Ppxlib_traverse_builtins.foldinherit['acc]Ast.foldendclass['acc]fold_map=objectinherit['acc]Ppxlib_traverse_builtins.fold_mapinherit['acc]Ast.fold_mapendclass['ctx]map_with_context=objectinherit['ctx]Ppxlib_traverse_builtins.map_with_contextinherit['ctx]Ast.map_with_contextendclassvirtual['res]lift=objectinherit['res]Ppxlib_traverse_builtins.liftinherit['res]Ast.liftendletmodule_name=function|None->"_"|Somename->nameletenternamepath=ifString.is_emptypaththennameelsepath^"."^nameletenter_optname_optpath=enter(module_namename_opt)pathclassmap_with_path=objectinherit[string]map_with_contextassuper(* WAS:
method! structure_item_desc path x =
match x with
| Pstr_module mb -> super#structure_item_desc (enter mb.pmb_name.txt path) x
| _ -> super#structure_item_desc path x
Overriding [module_binding] seems to be OK because it does not catch
local module bindings because at the moment the parsetree doesn't make
use of [module_binding] for local modules, but that might change in the
future, so this might be something to keep in mind.
The following:
module A = struct .. end
module A = struct .. end
is disallowed, but
let _ = .. let module A = struct .. end in ..
module A = struct .. end
let _ = .. let module A = struct .. end in ..
isn't, and the "path" constructed here would be able to differentiate
between them. *)method!module_bindingpathmb=super#module_binding(enter_optmb.pmb_name.txtpath)mbmethod!module_declarationpathmd=super#module_declaration(enter_optmd.pmd_name.txtpath)mdmethod!module_type_declarationpathmtd=super#module_type_declaration(entermtd.pmtd_name.txtpath)mtdendletvar_names_of=objectinherit[stringlist]foldassupermethod!patternpacc=letacc=super#patternpaccinmatchp.ppat_descwith|Ppat_var{txt;_}->txt::acc|_->accendletec_enter_module_opt~locname_optctxt=Expansion_context.Base.enter_module~loc(module_namename_opt)ctxtclassmap_with_expansion_context=object(self)inherit[Expansion_context.Base.t]map_with_contextassupermethod!expressionctxtexpr=super#expression(Expansion_context.Base.enter_exprctxt)exprmethod!module_bindingctxtmb=super#module_binding(ec_enter_module_opt~loc:mb.pmb_locmb.pmb_name.txtctxt)mbmethod!module_declarationctxtmd=super#module_declaration(ec_enter_module_opt~loc:md.pmd_locmd.pmd_name.txtctxt)mdmethod!module_type_declarationctxtmtd=super#module_type_declaration(Expansion_context.Base.enter_module~loc:mtd.pmtd_locmtd.pmtd_name.txtctxt)mtdmethod!value_descriptionctxtvd=super#value_description(Expansion_context.Base.enter_value~loc:vd.pval_locvd.pval_name.txtctxt)vdmethod!value_bindingctxt{pvb_pat;pvb_expr;pvb_attributes;pvb_loc}=letall_var_names=var_names_of#patternpvb_pat[]inletvar_name=Base.List.lastall_var_namesinletin_binding_ctxt=Base.Option.foldvar_name~init:ctxt~f:(functxtvar_name->Expansion_context.Base.enter_value~loc:pvb_locvar_namectxt)inletpvb_pat=self#patternctxtpvb_patinletpvb_expr=self#expressionin_binding_ctxtpvb_exprinletpvb_attributes=self#attributesin_binding_ctxtpvb_attributesinletpvb_loc=self#locationctxtpvb_locin{pvb_pat;pvb_expr;pvb_attributes;pvb_loc}endclasssexp_of=objectinherit[Sexp.t]Ast.liftmethodint=sexp_of_intmethodstring=sexp_of_stringmethodbool=sexp_of_boolmethodchar=sexp_of_charmethodfloat=sexp_of_floatmethodint32=sexp_of_int32methodint64=sexp_of_int64methodnativeint=sexp_of_nativeintmethodunit=sexp_of_unitmethodoption=sexp_of_optionmethodlist=sexp_of_listmethodarray:'a.('a->Sexp.t)->'aarray->Sexp.t=sexp_of_arraymethodother:'a.'a->Sexp.t=fun_->Sexp.Atom"_"methodrecordfields=List(List.mapfields~f:(fun(label,sexp)->Sexp.List[Atomlabel;sexp]))methodconstrtagargs=matchargswith|[]->Atomtag|_->List(Atomtag::args)methodtuplel=Listlendletsexp_of=newsexp_of