123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259openPpxlibopenAst_builder.Defaultletattr_name="ppx_module"letunknown_field_error~locfield=Location.raise_errorf~loc"unknown [@@ppx_module] field %S; supported fields are: name, cluster, \
parents"fieldtypeannotation={name:stringoption;cluster:stringoption;parents:bool;}letexpr_string=function|{pexp_desc=Pexp_constant(Pconst_string(s,_,_));_}->Somes|_->Noneletexpr_bool=function|{pexp_desc=Pexp_construct({txt=Lident"true";_},None);_}->Sometrue|{pexp_desc=Pexp_construct({txt=Lident"false";_},None);_}->Somefalse|_->Noneletparse_record_payloadfields=letname=refNoneinletcluster=refNoneinletparents=reftrueinletfield_name{txt;loc}=matchtxtwith|Lidentfield->field|_->Location.raise_errorf~loc"[@@ppx_module] fields must be unqualified"inletparse_string_field~locfieldexpr=matchexpr_stringexprwith|Somevalue->value|None->Location.raise_errorf~loc"[@@ppx_module] field %S must be a string literal"fieldinletparse_bool_field~locfieldexpr=matchexpr_boolexprwith|Somevalue->value|None->Location.raise_errorf~loc"[@@ppx_module] field %S must be a boolean literal"fieldinletparse_field(({loc;_}aslid),expr)=matchfield_namelidwith|"name"->name:=Some(parse_string_field~loc"name"expr)|"cluster"->cluster:=Some(parse_string_field~loc"cluster"expr)|"parents"->parents:=parse_bool_field~loc"parents"expr|field->unknown_field_error~locfieldinList.iterparse_fieldfields;{name=!name;cluster=!cluster;parents=!parents}letparse_annotationattr=matchattr.attr_payloadwith|PStr[]->{name=None;cluster=None;parents=true}|PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_record(fields,None);_},_);_;};]->parse_record_payloadfields|_->Location.raise_errorf~loc:attr.attr_loc"[@@ppx_module] expects no payload or a record payload, e.g. \
[@@ppx_module] or [@@ppx_module { name = \"Memory.Domain\"; cluster = \
\"memory\" }]"letannotationmb=mb.pmb_attributes|>List.find_opt(funa->a.attr_name.txt=attr_name)|>Option.mapparse_annotationletwithout_attrattrs=List.filter(funa->a.attr_name.txt<>attr_name)attrsletcollect_functor_paramsexpr=letrecgoacce=matche.pmod_descwith|Pmod_functor(Named({txt=Somen;_},_),body)->go(acc@[n])body|Pmod_functor(Named({txt=None;_},_),body)->goaccbody|Pmod_functor(Unit,body)->goaccbody|Pmod_constraint(me,_)->goaccme|_->accingo[]exprtypemetadata={loc:Location.t;source_file:string;source_line:int;source_item_name:string;name:string;cluster:stringoption;parents:bool;lexical_path:stringlist;context:stringlist;functor_params:stringlist;}letdefault_namesource_file=source_file|>Filename.basename|>Filename.remove_extension|>String.capitalize_asciiletmodule_metadata~(annotation:annotation)~context~lexical_stackitemmb=letsource_file=item.pstr_loc.loc_start.pos_fnameinletloc=mb.pmb_locinletsource_item_name=Option.value~default:"_"mb.pmb_name.txtinletname=Option.value~default:(default_namesource_file)annotation.namein{loc;source_file;source_line=loc.loc_start.pos_lnum;source_item_name;name;cluster=annotation.cluster;parents=annotation.parents;lexical_path=lexical_stack@[name];context;functor_params=collect_functor_paramsmb.pmb_expr;}letstring_list_expr~locxs=xs|>List.map(estring~loc)|>elist~locletoption_string_expr~loc=function|None->[%exprNone]|Somes->[%exprSome[%eestring~locs]]letmodule_value_expr~locmodule_namevalue_name=pexp_ident~loc{txt=Ldot(Lidentmodule_name,value_name);loc}typedependency_kind=Parent_dependency|Context_dependencyletdependency_kind_expr~loc=function|Parent_dependency->[%exprPpx_module.Parent]|Context_dependency->[%exprPpx_module.Context]letdependency_expr~lockindparam=letlabel=estring~locparaminletkind=dependency_kind_expr~lockindinletnode=module_value_expr~locparam"ppx_module_node"in[%expr[%elabel],[%ekind],[%enode]]letdependency_exprs~loc~parents~context=List.map(dependency_expr~locParent_dependency)parents@List.map(dependency_expr~locContext_dependency)context|>elist~locletgen_bindingsmeta~parent_params=letloc=meta.locinletparents=dependency_exprs~loc~parents:parent_params~context:meta.contextin[[%striletppx_module_name=lazy[%eestring~locmeta.name]];[%striletppx_module_node=Ppx_module.build_with_metadata~source_file:[%eestring~locmeta.source_file]~source_line:[%eeint~locmeta.source_line]~source_item_name:[%eestring~locmeta.source_item_name]~cluster:[%eoption_string_expr~locmeta.cluster]~lexical_path:[%estring_list_expr~locmeta.lexical_path]~functor_params:[%estring_list_expr~locmeta.functor_params]~name:ppx_module_name~parents:[%eparents]];]letadd_generated_bindingsmetaparams_accitems=letparent_params=ifmeta.parentsthenparams_accelse[]initems@gen_bindingsmeta~parent_paramsletinject_into_bodymetaexpr=letrecgoparams_acce=matche.pmod_descwith|Pmod_functor(Named(({txt=Somen;_}asnloc),mt),body)->{ewithpmod_desc=Pmod_functor(Named(nloc,mt),go(params_acc@[n])body);}|Pmod_functor(Named(({txt=None;_}asnloc),mt),body)->{ewithpmod_desc=Pmod_functor(Named(nloc,mt),goparams_accbody);}|Pmod_functor(Unit,body)->{ewithpmod_desc=Pmod_functor(Unit,goparams_accbody)}|Pmod_constraint(me,mt)->{ewithpmod_desc=Pmod_constraint(goparams_accme,mt)}|Pmod_structureitems->{ewithpmod_desc=Pmod_structure(add_generated_bindingsmetaparams_accitems);}|_->eingo[]exprletmapper=object(self)inheritAst_traverse.mapassupervalmutablecontext_params:stringlist=[]valmutablelexical_stack:stringlist=[]methodprivatemap_nested_modulesmetamb=letsaved_context=context_paramsinletsaved_lexical=lexical_stackincontext_params<-saved_context@meta.functor_params;lexical_stack<-meta.lexical_path;Fun.protect(fun()->super#module_bindingmb)~finally:(fun()->context_params<-saved_context;lexical_stack<-saved_lexical)methodprivaterewrite_module_bindingitemmb=matchannotationmbwith|None->super#module_bindingmb|Someannotation->letmeta=module_metadata~annotation~context:context_params~lexical_stackitemmbinletmb=self#map_nested_modulesmetambinletpmb_expr=inject_into_bodymetamb.pmb_exprinletpmb_attributes=without_attrmb.pmb_attributesin{mbwithpmb_expr;pmb_attributes}method!structure_itemitem=matchitem.pstr_descwith|Pstr_modulemb->{itemwithpstr_desc=Pstr_module(self#rewrite_module_bindingitemmb);}|Pstr_recmodulembs->{itemwithpstr_desc=Pstr_recmodule(List.map(self#rewrite_module_bindingitem)mbs);}|_->super#structure_itemitemendlet()=Driver.register_transformation"ppx_module"~impl:mapper#structure