Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file eval.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142(*
* Generic transformers: plugins.
* Copyright (C) 2016-2019
* Dmitrii Kosarev aka Kakadu
* St.Petersburg State University, JetBrains Research
*)(** {i Stateful} plugin: functors + inherited value
to make decisions about how to map values.
Essentially, is a {!Gmap} trait with polymorphic inherited attributes.
Is a simplified version of {!Stateful} trait: doesn't allow to pass modified
environment through transformation.
Inherited attributes' type (both default and for type parameters) is ['env].
Synthetized attributes' type (both default and for type parameters) is [ _ t].
For type declaration [type ('a,'b,...) typ = ...] it will create transformation
function with type
[('env -> 'a -> 'a2) ->
('env -> 'b -> 'b2) -> ... ->
'env -> ('a,'b,...) typ -> ('a2, 'b2, ...) typ ]
*)openBaseopenPpxlibopenPrintfopenGTCommonopenHelpersBaselettrait_name="eval"letparam_name_mangler=sprintf"%s_2"moduleMake(AstHelpers:GTHELPERS_sig.S)=structmoduleG=Gmap.Make(AstHelpers)moduleP=Plugin.Make(AstHelpers)lettrait_name=trait_nameopenAstHelpersclassginitial_argstdecls=object(self:'self)inheritG.ginitial_argstdeclsassuperinheritP.with_inherited_attrinitial_argstdeclsassuper2methodtrait_name=trait_namemethod!inh_of_main~loc_tdecl=Typ.var~loc"env"methodinh_of_param~loctdecl_name=Typ.var~loc"env"method!make_typ_of_class_argument:'a.loc:loc->type_declaration->(Typ.t->'a->'a)->string->(('a->'a)->'a->'a)->'a->'a=fun~loctdeclchainnamek->letsubj_t=Typ.var~locnameinletsyn_t=self#syn_of_param~locnameinletinh_t=self#inh_of_main~loctdeclink@@chain(Typ.arrow~locinh_t@@Typ.arrow~locsubj_tsyn_t)method!app_transformation_expr~loctrfinhsubj=Exp.app_list~loctrf[inh;subj]methodplugin_class_params~loc(typs:Ppxlib.core_typelist)~typname=super#plugin_class_params~loctyps~typname@[Typ.var~loc"env"]method!extra_class_sig_memberstdecl=letloc=loc_from_camltdecl.ptype_locinletwrap=ifis_polyvariant_tdecltdeclthenTyp.openize~locelse(fun?as_x->x)in[Ctf.constraint_~loc(Typ.var~loc@@Naming.make_extra_paramtdecl.ptype_name.txt)(wrap@@Typ.constr~loc(Lidenttdecl.ptype_name.txt)@@map_type_param_namestdecl.ptype_params~f:(funs->Typ.var~locs));letsyn=sprintf"syn_%s"tdecl.ptype_name.txtinCtf.constraint_~loc(Typ.var~loc@@syn)(self#hack~locparam_name_manglersyntdecl)]method!extra_class_str_memberstdecl=letloc=loc_from_camltdecl.ptype_locinletwrap=ifis_polyvariant_tdecltdeclthenTyp.openize~locelse(fun?as_x->x)in[Cf.constraint_~loc(Typ.var~loc@@Naming.make_extra_paramtdecl.ptype_name.txt)(wrap@@Typ.constr~loc(Lidenttdecl.ptype_name.txt)@@map_type_param_namestdecl.ptype_params~f:(funs->Typ.var~locs));letsyn=sprintf"syn_%s"tdecl.ptype_name.txtinCf.constraint_~loc(Typ.var~loc@@syn)(self#hack~locparam_name_manglersyntdecl)](* very similar as gmap but uses significant inherited attribute *)(* TODO: refactor somehow ??? *)method!on_record_declaration~loc~is_self_rec~mutual_declstdecllabs=letpat=Pat.record~loc@@List.maplabs~f:(funl->(Lidentl.pld_name.txt,Pat.var~locl.pld_name.txt))inletmethname=sprintf"do_%s"tdecl.ptype_name.txtin[Cf.method_concrete~locmethname@@Exp.fun_~loc(Pat.sprintf~loc"env")@@Exp.fun_~locpat@@Exp.record~loc@@List.maplabs~f:(fun{pld_name;pld_type}->lidentpld_name.txt,self#app_transformation_expr~loc(self#do_typ_gen~loc~is_self_rec~mutual_declstdeclpld_type)(Exp.ident~loc"env")(Exp.ident~locpld_name.txt))]endletcreate=(newg:>P.plugin_constructor)endletregister()=Expander.register_plugintrait_name(moduleMake:Plugin_intf.MAKE)let()=register()