Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file lib.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103openPpxlibletraise_errorf=Location.raise_errorfletmkloctxtloc={txt;loc}letmknoloctxt=mkloctxt!Ast_helper.default_locletstr_of_strings=mknolocsletpvarname=Ast_helper.Pat.var(str_of_stringname)letattr_ascontext=Attribute.declare"deriving.toString.as"contextAst_pattern.(single_expr_payload(estring__))(fune->e)letconstr_attr_as=attr_asAttribute.Context.constructor_declarationletrtag_attr_as=attr_asAttribute.Context.rtagletargn=Printf.sprintf"a%d"letpattntyps=List.mapi(funi_->pvar(argni))typsletlid_of_strings=mknoloc(Longident.parses)letconstrname=Ast_helper.Exp.construct(lid_of_stringname)Noneletpconstrname=Ast_helper.Pat.construct(lid_of_stringname)NonemodulePpx_deriving=structopenAst_helpertypecasing=|OCaml|Reason(* Some helpers imported from ppx_deriving, inlining them here allows to remove
the dependency on Ppx_deriving.Ast_convenience and the whole ppx_deriving package *)letcore_type_of_type_decl{ptype_name=name;ptype_params;_}=letname=mkloc(Lidentname.txt)name.locinTyp.constrname(List.mapfstptype_params)letmangle?(fixpoint="t")~casingaffixname=matchname=fixpoint,affix,casingwith|true,(`Prefixx|`Suffixx),_->x|false,`Prefixx,OCaml->x^"_"^name|false,`Suffixx,OCaml->name^"_"^x|false,`Prefixx,Reason->x^String.capitalize_asciiname|false,`Suffixx,Reason->name^String.capitalize_asciixletmangle_type_decl?fixpointaffix{ptype_name={txt=name;_};_}=mangle?fixpointaffixnamelettype_of_decltype_decl=letloc=type_decl.ptype_locinlettyp=core_type_of_type_decltype_declin[%type:[%ttyp]->string]letget_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"derivernameletattr~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"|>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_attributesthentypelse(letmapper=objectinheritAst_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_typetyp)end