Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ast_traverse.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303open!ImportopenCommon.With_errorsincludeAst_traverse0classvirtual['ctx,'res]lift_map_with_context=objectinherit['ctx,'res]Ppxlib_traverse_builtins.lift_map_with_contextinherit['ctx,'res]Ast.lift_map_with_contextendletmodule_name=functionNone->"_"|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_descwithPpat_var{txt;_}->txt::acc|_->accendletec_enter_module_opt~locname_optctxt=Expansion_context.Base.enter_module~loc(module_namename_opt)ctxtletenter_value=Attribute.declare"ppxlib.enter_value"ExpressionAst_pattern.(single_expr_payload(pexp_ident(lident__')))Fn.idletenter_module=Attribute.declare"ppxlib.enter_module"Module_exprAst_pattern.(single_expr_payload(pexp_construct(lident__')none))Fn.idletdo_not_enter_value_binding=Attribute.declare"ppxlib.do_not_enter_value"Value_bindingAst_pattern.(pstrnil)()letdo_not_enter_value_description=Attribute.declare"ppxlib.do_not_enter_value"Value_descriptionAst_pattern.(pstrnil)()letdo_not_enter_module_binding=Attribute.declare"ppxlib.do_not_enter_module"Module_bindingAst_pattern.(pstrnil)()letdo_not_enter_module_declaration=Attribute.declare"ppxlib.do_not_enter_module"Module_declarationAst_pattern.(pstrnil)()letdo_not_enter_module_type_declaration=Attribute.declare"ppxlib.do_not_enter_module"Module_type_declarationAst_pattern.(pstrnil)()letdo_not_enter_let_module=Attribute.declare"ppxlib.do_not_enter_module"ExpressionAst_pattern.(pstrnil)()classmap_with_expansion_context_and_errors=letreturn_ctxx=(x,[])inobject(self)inherit[Expansion_context.Base.t,Location.Error.tlist]lift_map_with_contextassupermethodint=returnmethodstring=returnmethodbool=returnmethodchar=returnmethodfloat=returnmethodint32=returnmethodint64=returnmethodnativeint=returnmethodunit=returnmethodarray:'a.(Expansion_context.Base.t->'a->'a*Location.Error.tlist)->Expansion_context.Base.t->'aarray->'aarray*Location.Error.tlist=funfctxa->letlist,errors=self#listfctx(Array.to_lista)in(Array.of_listlist,errors)methodother:'a.Expansion_context.Base.t->'a->Location.Error.tlist=fun__->[]methodrecord_ctxfields=List.concat_mapfields~f:sndmethodconstr_ctx_tagargs=List.concatargsmethodtuple_ctxl=List.concatlmethod!expressionctxt({pexp_desc;pexp_loc;pexp_loc_stack;pexp_attributes}asexpr)=letwith_value=Attribute.get_resenter_valueexpr|>of_result~default:None>>|function|None->ctxt|Some{loc;txt}->Expansion_context.Base.enter_value~loctxtctxtinwith_value>>=functxt->letctxt=Expansion_context.Base.enter_exprctxtinletpexp_desc,desc_errors=matchpexp_descwith|Pexp_letmodule(name,module_expr,body)->letname,name_errors=self#loc(self#optionself#string)ctxtnameinletmodule_expr,module_expr_errors=letwith_let_module=Attribute.get_resdo_not_enter_let_moduleexpr|>of_result~default:None>>|function|Some()->ctxt|None->ec_enter_module_opt~loc:module_expr.pmod_locname.txtctxtinwith_let_module>>=functxt->self#module_exprctxtmodule_exprinletbody,body_errors=self#expressionctxtbodyinleterrors=self#constrctxt"Pexp_letmodule"[name_errors;module_expr_errors;body_errors]in(Pexp_letmodule(name,module_expr,body),errors)|_->self#expression_descctxtpexp_descinletpexp_loc,loc_errors=self#locationctxtpexp_locinletpexp_loc_stack,loc_stack_errors=self#listself#locationctxtpexp_loc_stackinletpexp_attributes,attributes_errors=self#attributesctxtpexp_attributesin({pexp_desc;pexp_loc;pexp_loc_stack;pexp_attributes},self#recordctxt[("pexp_desc",desc_errors);("pexp_loc",loc_errors);("pexp_loc_stack",loc_stack_errors);("attributes",attributes_errors);])method!module_exprctxtme=letwith_module_expr=Attribute.get_resenter_moduleme|>of_result~default:None>>|function|None->ctxt|Some{loc;txt}->Expansion_context.Base.enter_module~loctxtctxtinwith_module_expr>>=functxt->super#module_exprctxtmemethod!module_bindingctxtmb=letwith_module_binding=Attribute.get_resdo_not_enter_module_bindingmb|>of_result~default:None>>|function|Some()->ctxt|None->ec_enter_module_opt~loc:mb.pmb_locmb.pmb_name.txtctxtinwith_module_binding>>=functxt->super#module_bindingctxtmbmethod!module_declarationctxtmd=letwith_module_declaration=Attribute.get_resdo_not_enter_module_declarationmd|>of_result~default:None>>|function|Some()->ctxt|None->ec_enter_module_opt~loc:md.pmd_locmd.pmd_name.txtctxtinwith_module_declaration>>=functxt->super#module_declarationctxtmdmethod!module_type_declarationctxtmtd=letwith_module_type_declaration=Attribute.get_resdo_not_enter_module_type_declarationmtd|>of_result~default:None>>|function|Some()->ctxt|None->Expansion_context.Base.enter_module~loc:mtd.pmtd_locmtd.pmtd_name.txtctxtinwith_module_type_declaration>>=functxt->super#module_type_declarationctxtmtdmethod!value_descriptionctxtvd=letwith_value_description=Attribute.get_resdo_not_enter_value_descriptionvd|>of_result~default:None>>|function|Some()->ctxt|None->Expansion_context.Base.enter_value~loc:vd.pval_locvd.pval_name.txtctxtinwith_value_description>>=functxt->super#value_descriptionctxtvdmethod!value_bindingctxt({pvb_pat;pvb_expr;pvb_attributes;pvb_loc}asvb)=Attribute.get_resdo_not_enter_value_bindingvb|>of_result~default:None>>=function|Some()->super#value_bindingctxtvb|None->letin_binding_ctxt=matchvar_names_of#patternpvb_pat[]with|[]|_::_::_->ctxt|[var_name]->Expansion_context.Base.enter_value~loc:pvb_locvar_namectxtinletpvb_pat,pat_errors=self#patternctxtpvb_patinletpvb_expr,expr_errors=self#expressionin_binding_ctxtpvb_exprinletpvb_attributes,attributes_errors=self#attributesin_binding_ctxtpvb_attributesinletpvb_loc,loc_errors=self#locationctxtpvb_locinleterrors=self#recordctxt[("pvb_pat",pat_errors);("pvb_expr",expr_errors);("pvb_attributes",attributes_errors);("pvb_loc",loc_errors);]in({pvb_pat;pvb_expr;pvb_attributes;pvb_loc},errors)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