123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822# 1 "ppx_deriving.cppo.ml"openPpxlibopenAsttypesopenAst_helpermoduleAst_convenience=struct(* Formerly defined in Ppx_tools.Ast_convenience.
Ppx_tools is not compatible with Ppxlib. *)letmkloctxtloc={txt;loc}letmknoloctxt=mkloctxt!Ast_helper.default_locletstr_of_strings=mknolocsletlid_of_strings=mknoloc(Longident.parses)letunit()=letloc=!Ast_helper.default_locin[%expr()]letpunit()=letloc=!Ast_helper.default_locin[%pat?()]letstrs=Ast_helper.Exp.constant(Ast_helper.Const.strings)letinti=Ast_helper.Exp.constant(Ast_helper.Const.inti)letpinti=Ast_helper.Pat.constant(Ast_helper.Const.inti)letevarname=Ast_helper.Exp.ident(lid_of_stringname)letpvarname=Ast_helper.Pat.var(str_of_stringname)letappfargs=matchargswith|[]->f|_->letargs=List.map(fune->(Nolabel,e))argsinAst_helper.Exp.applyfargsletconstrnameargs=letargs=matchargswith|[]->None|[arg]->Somearg|_->Some(Ast_helper.Exp.tupleargs)inAst_helper.Exp.construct(lid_of_stringname)argsletpconstrnameargs=letargs=matchargswith|[]->None|[arg]->Somearg|_->Some(Ast_helper.Pat.tupleargs)inAst_helper.Pat.construct(lid_of_stringname)argslettconstrnameargs=Ast_helper.Typ.constr(lid_of_stringname)argsletrecordfields=letfields=List.map(fun(name,value)->(lid_of_stringname,value))fieldsinAst_helper.Exp.recordfieldsNoneletprecord~closedfields=letfields=List.map(fun(name,value)->(lid_of_stringname,value))fieldsinAst_helper.Pat.recordfieldsclosedlettupleitems=matchitemswith|[]->unit()|[item]->item|_->Ast_helper.Exp.tupleitemsletptupleitems=matchitemswith|[]->punit()|[item]->item|_->Ast_helper.Pat.tupleitemsletattribute_has_namenameattribute=attribute.attr_name.txt=namelethas_attrnameattributes=List.exists(attribute_has_namename)attributesletfind_attrnameattributes=matchList.find(attribute_has_namename)attributeswith|exceptionNot_found->None|attribute->Someattribute.attr_payloadmoduleLabel=structletnolabel=Nolabelletlabelleds=Labelledsletoptionals=OptionalsendendopenAst_conveniencetypetyvar=stringLocation.loctypederiver={name:string;core_type:(core_type->expression)option;type_decl_str:options:(string*expression)list->path:stringlist->type_declarationlist->structure;type_ext_str:options:(string*expression)list->path:stringlist->type_extension->structure;module_type_decl_str:options:(string*expression)list->path:stringlist->module_type_declaration->structure;type_decl_sig:options:(string*expression)list->path:stringlist->type_declarationlist->signature;type_ext_sig:options:(string*expression)list->path:stringlist->type_extension->signature;module_type_decl_sig:options:(string*expression)list->path:stringlist->module_type_declaration->signature;}typePpx_derivers.deriver+=Tofderivertypeinternal_or_external=|Internalofderiver|Externalofstringlethooks=Queue.create()letadd_register_hookf=Queue.addfhooksletregisterd=Ppx_derivers.registerd.name(Td);Queue.iter(funf->fd)hooksletderivers()=List.fold_left(funacc(_name,drv)->matchdrvwith|Td->d::acc|_->acc)[](Ppx_derivers.derivers())letlookup_internal_or_externalname=matchPpx_derivers.lookupnamewith|Some(Td)->Some(Internald)|Some_->Some(Externalname)|None->Noneletlookupname=matchlookup_internal_or_externalnamewith|Some(Internald)->Somed|Some(External_)|None->Noneletraise_errorf?sub?locfmt=letmoduleLocation=Ocaml_common.Locationinletraise_msgstr=# 175 "ppx_deriving.cppo.ml"letsub=letmsg_of_errorerr=# 185 "ppx_deriving.cppo.ml"{txt=(funfmt->Location.print_reportfmterr);loc=err.Location.main.loc}# 188 "ppx_deriving.cppo.ml"inOption.map(List.mapmsg_of_error)subin# 191 "ppx_deriving.cppo.ml"leterr=Location.error?sub?locstrinraise(Location.Errorerr)inPrintf.ksprintfraise_msgfmtletcreate=letdef_ext_strname~options~pathtyp_ext=raise_errorf"Extensible types in structures not supported by deriver %s"nameinletdef_ext_signame~options~pathtyp_ext=raise_errorf"Extensible types in signatures not supported by deriver %s"nameinletdef_decl_strname~options~pathtyp_decl=raise_errorf"Type declarations in structures not supported by deriver %s"nameinletdef_decl_signame~options~pathtyp_decl=raise_errorf"Type declarations in signatures not supported by deriver %s"nameinletdef_module_type_decl_strname~options~pathmodule_type_decl=raise_errorf"Module type declarations in structures not supported by \
deriver %s"nameinletdef_module_type_decl_signame~options~pathmodule_type_decl=raise_errorf"Module type declarations in signatures not supported by \
deriver %s"nameinfunname?core_type?(type_ext_str=def_ext_strname)?(type_ext_sig=def_ext_signame)?(type_decl_str=def_decl_strname)?(type_decl_sig=def_decl_signame)?(module_type_decl_str=def_module_type_decl_strname)?(module_type_decl_sig=def_module_type_decl_signame)()->{name;core_type;type_decl_str;type_ext_str;module_type_decl_str;type_decl_sig;type_ext_sig;module_type_decl_sig;}letstring_of_core_typetyp=Format.asprintf"%a"Pprintast.core_type{typwithptyp_attributes=[]}letstring_of_constant_opt(constant:Parsetree.constant):stringoption=matchconstantwith|Pconst_string(s,_,_)->Somes|_->Noneletstring_of_expression_opt(e:Parsetree.expression):stringoption=matchewith|{pexp_desc=Pexp_constantconstant}->string_of_constant_optconstant|_->NonemoduleArg=structtype'aconv=expression->('a,string)resultletexprexpr=Okexprletintexpr=matchexprwith|{pexp_desc=Pexp_constant(Pconst_integer(sn,_))}->Ok(int_of_stringsn)|_->Error"integer"letboolexpr=matchexprwith|[%exprtrue]->Oktrue|[%exprfalse]->Okfalse|_->Error"boolean"letstringexpr=matchexprwith|{pexp_desc=Pexp_constant(Pconst_string(n,_,None))}->Okn|_->Error"string"letchar=function|{pexp_desc=Pexp_constant(Pconst_charc)}->Okc|_->Error"char"letenumvaluesexpr=matchexprwith|{pexp_desc=Pexp_variant(name,None)}whenList.memnamevalues->Okname|_->Error(Printf.sprintf"one of: %s"(String.concat", "(List.map(funs->"`"^s)values)))letlistexpr=letrecloopacc=function|[%expr[]]->Ok(List.revacc)|[%expr[%e?x]::[%e?xs]]->beginmatchexprxwith|Okv->loop(v::acc)xs|Errore->Error("list:"^e)end|_->Error"list"inloop[]letget_attr~deriverconvattr=matchattrwith|None->None|Some{attr_name={txt=name;loc=_};attr_payload=PStr[{pstr_desc=Pstr_eval(expr,[])}];attr_loc=_}->beginmatchconvexprwith|Okv->Somev|Errordesc->raise_errorf~loc:expr.pexp_loc"%s: invalid [@%s]: %s expected"derivernamedescend|Some{attr_name={txt=name;loc};attr_payload=_;attr_loc=_}->raise_errorf~loc"%s: invalid [@%s]: value expected"derivernameletget_flag~deriverattr=matchattrwith|None->false|Some{attr_name=_;attr_payload=PStr[];attr_loc=_}->true|Some{attr_name={txt=name;loc};attr_payload=_;attr_loc=_}->raise_errorf~loc"%s: invalid [@%s]: empty structure expected"derivernameletget_expr~deriverconvexpr=matchconvexprwith|Errordesc->raise_errorf~loc:expr.pexp_loc"%s: %s expected"deriverdesc|Okv->vendletattr_warningexpr=letloc=!default_locinletstructure={pstr_desc=Pstr_eval(expr,[]);pstr_loc=loc}in{attr_name={txt="ocaml.warning";loc;};attr_payload=PStr[structure];attr_loc=loc;}typequoter=Expansion_helpers.Quoter.tletcreate_quoter()=Expansion_helpers.Quoter.create()letquote~quoterexpr=Expansion_helpers.Quoter.quotequoterexprletsanitize?(module_=Lident"Ppx_deriving_runtime")?(quoter=create_quoter())expr=letloc=!Ast_helper.default_locinletbody=letattrs=[attr_warning[%expr"-A"]]inletmodname={txt=module_;loc}inExp.open_~loc~attrs(Opn.mk~loc~attrs~override:Override(Mod.ident~loc~attrsmodname))exprinletsanitized=Expansion_helpers.Quoter.sanitizequoterbodyin(* ppxlib quoter uses Recursive, ppx_deriving's used Nonrecursive - silence warning *){sanitizedwithpexp_attributes=attr_warning[%expr"-39"]::sanitized.pexp_attributes}letwith_quoterfna=letquoter=create_quoter()insanitize~quoter(fnquotera)letexpand_path~pathident=String.concat"."(path@[ident])letpath_of_type_decl~pathtype_decl=matchtype_decl.ptype_manifestwith|Some{ptyp_desc=Ptyp_constr({txt=lid},_)}->beginmatchlidwith|Lident_->[]|Ldot(lid,_)->Ocaml_common.Longident.flattenlid|Lapply_->assertfalseend|_->pathletmangle?(fixpoint="t")affixname=matchname=fixpoint,affixwith|true,(`Prefixx|`Suffixx)->x|true,`PrefixSuffix(p,s)->p^"_"^s|false,`PrefixSuffix(p,s)->p^"_"^name^"_"^s|false,`Prefixx->x^"_"^name|false,`Suffixx->name^"_"^xletmangle_type_decl?fixpointaffix{ptype_name={txt=name}}=mangle?fixpointaffixnameletmangle_lid?fixpointaffixlid=matchlidwith|Lidents->Lident(mangle?fixpointaffixs)|Ldot(p,s)->Ldot(p,mangle?fixpointaffixs)|Lapply_->assertfalseletattr~derivernameattrs=letstartsprefixstr=String.lengthstr>=String.lengthprefix&&String.substr0(String.lengthprefix)=prefixinletattr_startsprefixattr=startsprefixattr.attr_name.txtinletattr_isnameattr=name=attr.attr_name.txtinlettry_prefixprefixf=ifList.exists(attr_startsprefix)attrsthenprefix^nameelsef()inletname=try_prefix("deriving."^deriver^".")(fun()->try_prefix(deriver^".")(fun()->name))intrySome(List.find(attr_isname)attrs)withNot_found->Noneletattr_nobuiltin~deriverattrs=attrs|>attr~deriver"nobuiltin"|>Arg.get_flag~deriverletrecremove_pervasive_lid=function|Lident_aslid->lid|Ldot(Lident"Pervasives",s)->Lidents|Ldot(Lident"Stdlib",s)->Lidents|Ldot(lid,s)->Ldot(remove_pervasive_lidlid,s)|Lapply(lid,lid2)->Lapply(remove_pervasive_lidlid,remove_pervasive_lidlid2)letremove_pervasives~derivertyp=ifattr_nobuiltin~derivertyp.ptyp_attributesthentypelseletmapper=objectinheritPpxlib.Ast_traverse.mapassupermethod!core_typetyp=matchsuper#core_typetypwith|{ptyp_desc=Ptyp_constr(lid,l)}->letlid={lidwithtxt=remove_pervasive_lidlid.txt}in{typwithptyp_desc=Ptyp_constr(lid,l)}|{ptyp_desc=Ptyp_class(lid,l)}->letlid={lidwithtxt=remove_pervasive_lidlid.txt}in{typwithptyp_desc=Ptyp_class(lid,l)}|typ->typendinmapper#core_typetypletmkloc=Ocaml_common.Location.mklocletfold_left_type_paramsfnaccumparams=List.fold_left(funaccum(param,_)->matchparamwith|{ptyp_desc=Ptyp_any}->accum|{ptyp_desc=Ptyp_varname}->letname=mklocnameparam.ptyp_locinfnaccumname|_->assertfalse)accumparamsletfold_left_type_declfnaccum{ptype_params}=fold_left_type_paramsfnaccumptype_paramsletfold_left_type_extfnaccum{ptyext_params}=fold_left_type_paramsfnaccumptyext_paramsletfold_right_type_paramsfnparamsaccum=List.fold_right(fun(param,_)accum->matchparamwith|{ptyp_desc=Ptyp_any}->accum|{ptyp_desc=Ptyp_varname}->letname=mklocnameparam.ptyp_locinfnnameaccum|_->assertfalse)paramsaccumletfold_right_type_declfn{ptype_params}accum=fold_right_type_paramsfnptype_paramsaccumletfold_right_type_extfn{ptyext_params}accum=fold_right_type_paramsfnptyext_paramsaccumletfree_vars_in_core_typetyp=letrecfree_intyp=matchtypwith|{ptyp_desc=Ptyp_any}->[]|{ptyp_desc=Ptyp_varname}->[mklocnametyp.ptyp_loc]|{ptyp_desc=Ptyp_arrow(_,x,y)}->free_inx@free_iny|{ptyp_desc=(Ptyp_tuplexs|Ptyp_constr(_,xs))}->List.mapfree_inxs|>List.concat|{ptyp_desc=Ptyp_alias(x,name)}->[mklocname.txttyp.ptyp_loc]@free_inx|{ptyp_desc=Ptyp_poly(bound,x)}->List.filter(funy->not(List.memybound))(free_inx)|{ptyp_desc=Ptyp_variant(rows,_,_)}->List.map(function{prf_desc=Rtag(_,_,ts)}->List.mapfree_ints|{prf_desc=Rinherit(t)}->[free_int])rows|>List.concat|>List.concat|_->assertfalseinletuniqlst=letmoduleStringSet=Set.Make(String)inletadd(rev_names,txts)name=lettxt=name.txtinifStringSet.memtxttxtsthen(rev_names,txts)else(name::rev_names,StringSet.addtxttxts)inList.rev(fst(List.fold_leftadd([],StringSet.empty)lst))infree_intyp|>uniqletvar_name_of_inti=letletter="abcdefghijklmnopqrstuvwxyz"inletrecloopi=ifi<26then[letter.[i]]elseletter.[imod26]::loop(i/26)inString.concat""(List.map(String.make1)(loopi))letfresh_varbound=letrecloopi=letvar_name=var_name_of_intiinifList.memvar_nameboundthenloop(i+1)elsevar_nameinloop0letpoly_fun_of_type_decltype_declexpr=fold_right_type_decl(funnameexpr->letname=name.txtinExp.fun_Label.nolabelNone(pvar("poly_"^name))expr)type_declexprletpoly_fun_of_type_exttype_extexpr=fold_right_type_ext(funnameexpr->letname=name.txtinExp.fun_Label.nolabelNone(pvar("poly_"^name))expr)type_extexprletpoly_apply_of_type_decltype_declexpr=fold_left_type_decl(funexprname->letname=name.txtinExp.applyexpr[Label.nolabel,evar("poly_"^name)])exprtype_declletpoly_apply_of_type_exttype_extexpr=fold_left_type_ext(funexprname->letname=name.txtinExp.applyexpr[Label.nolabel,evar("poly_"^name)])exprtype_extletpoly_arrow_of_type_declfntype_decltyp=fold_right_type_decl(funnametyp->letname=name.txtinTyp.arrowLabel.nolabel(fn(Typ.varname))typ)type_decltypletpoly_arrow_of_type_extfntype_exttyp=fold_right_type_ext(funnametyp->letvar=Typ.var~loc:name.locname.txtinTyp.arrowLabel.nolabel(fnvar)typ)type_exttypletcore_type_of_type_decl{ptype_name=name;ptype_params}=letname=mkloc(Lidentname.txt)name.locinTyp.constrname(List.mapfstptype_params)letcore_type_of_type_ext{ptyext_path;ptyext_params}=Typ.constrptyext_path(List.mapfstptyext_params)letinstantiateboundtype_decl=letvars,bound=List.fold_right(fun_(vars,bound)->letv=fresh_varboundin(v::vars,v::bound))(free_vars_in_core_type(core_type_of_type_decltype_decl))([],bound)inletvars=List.revvarsinletcore_type=core_type_of_type_decl{type_declwithptype_params=List.map2(funv(_,variance)->Typ.varv,variance)varstype_decl.ptype_params}incore_type,vars,boundletfold_exprs?unitfnexprs=matchexprswith|[a]->a|hd::tl->List.fold_leftfnhdtl|[]->matchunitwith|Somex->x|None->raise(Invalid_argument"Ppx_deriving.fold_exprs")letseq_reduce?sepab=letloc=!Ast_helper.default_locinmatchsepwith|Somex->[%expr[%ea];[%ex];[%eb]]|None->[%expr[%ea];[%eb]]letbinop_reducexab=letloc=!Ast_helper.default_locin[%expr[%ex][%ea][%eb]]letstrong_type_of_typety=letfree_vars=free_vars_in_core_typetyinmatchfree_varswith|[]->ty|_->Typ.force_poly@@Typ.polyfree_varstytypederiver_options=|Optionsof(string*expression)list|Unknown_syntaxletderivepathpstr_locitemattributesfnarg=letderiving=find_attr"deriving"attributesinletderiver_exprs,loc=matchderivingwith|Some(PStr[{pstr_desc=Pstr_eval({pexp_desc=Pexp_tupleexprs},[]);pstr_loc}])->exprs,pstr_loc|Some(PStr[{pstr_desc=Pstr_eval({pexp_desc=(Pexp_ident_|Pexp_apply_)}asexpr,[]);pstr_loc}])->[expr],pstr_loc|_->raise_errorf~loc:pstr_loc"Unrecognized [@@deriving] annotation syntax"inList.fold_left(funitemsderiver_expr->letname,options=matchderiver_exprwith|{pexp_desc=Pexp_identname}->name,Options[]|{pexp_desc=Pexp_apply({pexp_desc=Pexp_identname},[label,{pexp_desc=Pexp_record(options,None)}])}whenlabel=Label.nolabel->name,Options(options|>List.map(fun({txt},expr)->String.concat"."(Ocaml_common.Longident.flattentxt),expr))|{pexp_desc=Pexp_apply({pexp_desc=Pexp_identname},_)}->name,Unknown_syntax|{pexp_loc}->raise_errorf~loc:pexp_loc"Unrecognized [@@deriving] syntax"inletname,loc=String.concat"_"(Ocaml_common.Longident.flattenname.txt),name.locinletis_optional,options=matchoptionswith|Unknown_syntax->false,options|Optionsoptions'->matchList.assoc"optional"options'with|exceptionNot_found->false,options|expr->Arg.(get_expr~deriver:namebool)expr,Options(List.remove_assoc"optional"options')inmatchlookup_internal_or_externalname,optionswith|Some(Internalderiver),Optionsoptions->items@((fnderiver)~options~path:(!path)arg)|Some(Internal_),Unknown_syntax->raise_errorf~loc:deriver_expr.pexp_loc"Unrecognized [@@deriving] option syntax"|Some(External_),_->items|None,_->ifis_optionalthenitemselseraise_errorf~loc"Cannot locate deriver %s"name)[item]deriver_exprsletderive_type_declpathtyp_declspstr_locitemfn=letattributes=List.concat(List.map(fun{ptype_attributes=attrs}->attrs)typ_decls)inderivepathpstr_locitemattributesfntyp_declsletderive_type_extpathtyp_extpstr_locitemfn=letattributes=typ_ext.ptyext_attributesinderivepathpstr_locitemattributesfntyp_extletderive_module_type_declpathmodule_type_declpstr_locitemfn=letattributes=module_type_decl.pmtd_attributesinderivepathpstr_locitemattributesfnmodule_type_declletmodule_from_input_name()=match!Ocaml_common.Location.input_namewith|""|"//toplevel//"->[]|filename->letcapitalize=String.capitalize_asciiinmatchFilename.chop_suffixfilename".ml"with|exception_->(* see https://github.com/ocaml-ppx/ppx_deriving/pull/196 *)[]|path->[capitalize(Filename.basenamepath)]letpstr_desc_rec_flagpstr=matchpstrwith|Pstr_type(rec_flag,typ_decls)->rec_flag|_->assertfalseletmodule_nesting=ref[]letwith_modulenamef=letold_nesting=!module_nestinginbeginmatchnamewith|Somename->module_nesting:=!module_nesting@[name]|None->()end;letresult=f()inmodule_nesting:=old_nesting;resultclassmapper=object(self)inheritAst_traverse.mapassupermethod!expressionexpr=matchexprwith|{pexp_desc=Pexp_extension({txt=name;loc},payload)}whenString.(lengthname>=7&&subname07="derive.")->letname=String.subname7((String.lengthname)-7)inletderiver=matchlookup_internal_or_externalnamewith|Some(Internal{core_type=Somederiver})->deriver|Some_->raise_errorf~loc"Deriver %s does not support inline notation"name|None->raise_errorf~loc"Cannot locate deriver %s"nameinbeginmatchpayloadwith|PTyptyp->derivertyp|_->raise_errorf~loc"Unrecognized [%%derive.*] syntax"end|{pexp_desc=Pexp_extension({txt=name;loc},PTyptyp)}->beginmatchlookup_internal_or_externalnamewith|Some(Internal{core_type=Somederiver})->Ast_helper.with_default_loctyp.ptyp_loc(fun()->derivertyp)|_->super#expressionexprend|_->super#expressionexprmethod!structureitems=matchitemswith|{pstr_desc=Pstr_type(_,typ_decls)aspstr_desc;pstr_loc}::restwhenList.exists(funty->has_attr"deriving"ty.ptype_attributes)typ_decls&&pstr_desc_rec_flagpstr_desc=Nonrecursive->raise_errorf~loc:pstr_loc"The nonrec flag is not supported by ppx_deriving"|{pstr_desc=Pstr_type(_,typ_decls);pstr_loc}asitem::restwhenList.exists(funty->has_attr"deriving"ty.ptype_attributes)typ_decls->letderived=Ast_helper.with_default_locpstr_loc(fun()->derive_type_declmodule_nestingtyp_declspstr_locitem(funderiver->deriver.type_decl_str))inderived@self#structurerest|{pstr_desc=Pstr_typexttyp_ext;pstr_loc}asitem::restwhenhas_attr"deriving"typ_ext.ptyext_attributes->letderived=Ast_helper.with_default_locpstr_loc(fun()->derive_type_extmodule_nestingtyp_extpstr_locitem(funderiver->deriver.type_ext_str))inderived@self#structurerest|{pstr_desc=Pstr_modtypemodtype;pstr_loc}asitem::restwhenhas_attr"deriving"modtype.pmtd_attributes->letderived=Ast_helper.with_default_locpstr_loc(fun()->derive_module_type_declmodule_nestingmodtypepstr_locitem(funderiver->deriver.module_type_decl_str))inderived@self#structurerest|{pstr_desc=Pstr_module({pmb_name={txt=name}}asmb)}asitem::rest->letderived={itemwithpstr_desc=Pstr_module(with_modulename(fun()->self#module_bindingmb))}inderived::self#structurerest|{pstr_desc=Pstr_recmodulembs}asitem::rest->letderived={itemwithpstr_desc=Pstr_recmodule(mbs|>List.map(fun({pmb_name={txt=name}}asmb)->with_modulename(fun()->self#module_bindingmb)))}inderived::self#structurerest|{pstr_loc}asitem::rest->letderived=self#structure_itemiteminderived::self#structurerest|[]->[]method!signatureitems=matchitemswith|{psig_desc=Psig_type(_,typ_decls);psig_loc}asitem::restwhenList.exists(funty->has_attr"deriving"ty.ptype_attributes)typ_decls->letderived=Ast_helper.with_default_locpsig_loc(fun()->derive_type_declmodule_nestingtyp_declspsig_locitem(funderiver->deriver.type_decl_sig))inderived@self#signaturerest|{psig_desc=Psig_typexttyp_ext;psig_loc}asitem::restwhenhas_attr"deriving"typ_ext.ptyext_attributes->letderived=Ast_helper.with_default_locpsig_loc(fun()->derive_type_extmodule_nestingtyp_extpsig_locitem(funderiver->deriver.type_ext_sig))inderived@self#signaturerest|{psig_desc=Psig_modtypemodtype;psig_loc}asitem::restwhenhas_attr"deriving"modtype.pmtd_attributes->letderived=Ast_helper.with_default_locpsig_loc(fun()->derive_module_type_declmodule_nestingmodtypepsig_locitem(funderiver->deriver.module_type_decl_sig))inderived@self#signaturerest|{psig_desc=Psig_module({pmd_name={txt=name}}asmd)}asitem::rest->letderived={itemwithpsig_desc=Psig_module(with_modulename(fun()->self#module_declarationmd))}inderived::self#signaturerest|{psig_desc=Psig_recmodulemds}asitem::rest->letderived={itemwithpsig_desc=Psig_recmodule(mds|>List.map(fun({pmd_name={txt=name}}asmd)->with_modulename(fun()->self#module_declarationmd)))}inderived::self#signaturerest|{psig_loc}asitem::rest->letderived=self#signature_itemiteminderived::self#signaturerest|[]->[]endletmap_structures=module_nesting:=module_from_input_name();(newmapper)#structuresletmap_signatures=module_nesting:=module_from_input_name();(newmapper)#signatureslethash_variants=letaccu=ref0infori=0toString.lengths-1doaccu:=223*!accu+Char.codes.[i]done;(* reduce to 31 bits *)accu:=!acculand(1lsl31-1);(* make it signed for 64 bits architectures *)if!accu>0x3FFFFFFFthen!accu-(1lsl31)else!accu(* This is only used when ppx_deriving is linked as part of an ocaml-migrate-parsetre
driver. *)let()=Ppxlib.Driver.register_transformation"ppx_deriving"~impl:map_structure~intf:map_signature